38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { serviceRoutes } from "../src/routes/services.js";
|
|
|
|
const originalFetch = globalThis.fetch;
|
|
const requests: Request[] = [];
|
|
|
|
globalThis.fetch = (async (input, init) => {
|
|
const request = new Request(input, init);
|
|
requests.push(request);
|
|
const path = new URL(request.url).pathname;
|
|
if (request.method === "DELETE" && path.endsWith("/api/v1/resumes/resume-1")) {
|
|
return new Response(null, { status: 204 });
|
|
}
|
|
return new Response("<html>preview</html>", {
|
|
status: 200,
|
|
headers: { "content-type": "text/html; charset=utf-8" },
|
|
});
|
|
}) as typeof fetch;
|
|
|
|
const app = serviceRoutes({ skipAuth: true });
|
|
try {
|
|
const preview = await app.request("http://backend.test/resume/export/resumes/resume-1/preview");
|
|
assert.equal(preview.status, 200);
|
|
assert.equal(await preview.text(), "<html>preview</html>");
|
|
assert.equal(new URL(requests[0]!.url).pathname, "/api/v1/export/resumes/resume-1/preview");
|
|
assert.equal(requests[0]!.headers.get("x-growqr-user"), "user_test");
|
|
assert.match(requests[0]!.headers.get("authorization") ?? "", /^Bearer /);
|
|
|
|
const deleted = await app.request("http://backend.test/resume/resumes/resume-1", { method: "DELETE" });
|
|
assert.equal(deleted.status, 204);
|
|
assert.equal(await deleted.text(), "");
|
|
assert.equal(new URL(requests[1]!.url).pathname, "/api/v1/resumes/resume-1");
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
|
|
console.log("resume gateway proxy tests passed");
|