@@ -52,6 +52,13 @@ function mockCallRecord(mock: ReturnType<typeof vi.fn>, index: number): unknown[
|
52 | 52 | return call; |
53 | 53 | } |
54 | 54 | |
| 55 | +function expectUnauthorizedPayload(res: ServerResponse, end: ReturnType<typeof vi.fn>): void { |
| 56 | +expect(res.statusCode).toBe(401); |
| 57 | +expect(end).toHaveBeenCalledWith( |
| 58 | +JSON.stringify({ error: { message: "Unauthorized", type: "unauthorized" } }), |
| 59 | +); |
| 60 | +} |
| 61 | + |
55 | 62 | describe("setDefaultSecurityHeaders", () => { |
56 | 63 | it("sets X-Content-Type-Options", () => { |
57 | 64 | const { res, setHeader } = makeMockHttpResponse(); |
@@ -144,10 +151,7 @@ describe("sendUnauthorized", () => {
|
144 | 151 | it("responds with 401 and a structured unauthorized payload", () => { |
145 | 152 | const { res, end } = makeMockHttpResponse(); |
146 | 153 | sendUnauthorized(res); |
147 | | -expect(res.statusCode).toBe(401); |
148 | | -expect(end).toHaveBeenCalledWith( |
149 | | -JSON.stringify({ error: { message: "Unauthorized", type: "unauthorized" } }), |
150 | | -); |
| 154 | +expectUnauthorizedPayload(res, end); |
151 | 155 | }); |
152 | 156 | }); |
153 | 157 | |
@@ -203,10 +207,7 @@ describe("sendGatewayAuthFailure", () => {
|
203 | 207 | const { res, end } = makeMockHttpResponse(); |
204 | 208 | const authResult = { ok: false, rateLimited: false } as GatewayAuthResult; |
205 | 209 | sendGatewayAuthFailure(res, authResult); |
206 | | -expect(res.statusCode).toBe(401); |
207 | | -expect(end).toHaveBeenCalledWith( |
208 | | -JSON.stringify({ error: { message: "Unauthorized", type: "unauthorized" } }), |
209 | | -); |
| 210 | +expectUnauthorizedPayload(res, end); |
210 | 211 | }); |
211 | 212 | }); |
212 | 213 | |
|