37 lines
988 B
JavaScript
37 lines
988 B
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { yedirRequest } from "../api-client.mjs";
|
|
|
|
test("yedirRequest sends a Bearer token and returns JSON", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = async (url, options) => {
|
|
assert.equal(url, "https://example.com/api/openapi/v1/me");
|
|
assert.equal(options.headers.Authorization, "Bearer secret-token");
|
|
return Response.json({ success: true });
|
|
};
|
|
|
|
try {
|
|
assert.deepEqual(
|
|
await yedirRequest(
|
|
"/api/openapi/v1/me",
|
|
{},
|
|
{ baseUrl: "https://example.com/", accessToken: "secret-token" }
|
|
),
|
|
{ success: true }
|
|
);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("yedirRequest rejects non-http base URLs", async () => {
|
|
await assert.rejects(
|
|
yedirRequest(
|
|
"/api/openapi/v1/me",
|
|
{},
|
|
{ baseUrl: "file:///tmp/site", accessToken: "secret-token" }
|
|
),
|
|
/http or https/
|
|
);
|
|
});
|