diff --git a/package.json b/package.json index f27046f..b01ab15 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test:interview-user-identity": "tsx scripts/interview-user-identity.test.ts", "test:ws-ticket": "tsx scripts/ws-ticket.test.ts", "test:roleplay-drafts": "tsx scripts/roleplay-drafts.test.ts", + "test:resume-gateway": "tsx scripts/resume-gateway.test.ts", "start": "node dist/index.js", "typecheck": "tsc -p tsconfig.json --noEmit", "workflows:smoke": "tsx src/workflows/smoke-test.ts", diff --git a/scripts/resume-gateway.test.ts b/scripts/resume-gateway.test.ts new file mode 100644 index 0000000..a05c887 --- /dev/null +++ b/scripts/resume-gateway.test.ts @@ -0,0 +1,37 @@ +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("preview", { + 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(), "preview"); + 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"); diff --git a/src/routes/services.ts b/src/routes/services.ts index 1c33031..e2fbd44 100644 --- a/src/routes/services.ts +++ b/src/routes/services.ts @@ -483,7 +483,7 @@ async function proxyResumeRequest(req: Request, rest: string, userId: string) { mission, }).catch((err) => log.warn({ err, path: normalizedRest }, "failed to record resume gateway event")); - return new Response(responseBuffer, { + return new Response(res.status === 204 || res.status === 205 || res.status === 304 ? null : responseBuffer, { status: res.status, statusText: res.statusText, headers: decodedProxyHeaders(res.headers),