From 3a9a059de029bcc0135ce2d951593cb139b55f84 Mon Sep 17 00:00:00 2001 From: Louis Liu Date: Wed, 29 Jul 2026 12:14:49 +0800 Subject: [PATCH] test: cover missing auth header rejection --- tests/integration/auth-jwt-validation.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/integration/auth-jwt-validation.test.ts diff --git a/tests/integration/auth-jwt-validation.test.ts b/tests/integration/auth-jwt-validation.test.ts new file mode 100644 index 0000000..be3f35a --- /dev/null +++ b/tests/integration/auth-jwt-validation.test.ts @@ -0,0 +1,47 @@ +import express from "express"; +import request from "supertest"; + +import { createErrorMiddleware } from "../../src/middleware/error.middleware"; +import { logger } from "../../src/observability/logger"; +import { createInvoiceRouter } from "../../src/routes/invoice.routes"; + +describe("JWT authentication validation", () => { + it("rejects invoice requests without an Authorization header", async () => { + const invoiceService = { + getInvoicesBySellerId: jest.fn(), + }; + + const app = express(); + app.use(express.json()); + app.use( + "/api/v1/invoices", + createInvoiceRouter({ + invoiceService: invoiceService as any, + config: { + ipfs: { + maxFileSizeMB: 10, + allowedMimeTypes: ["application/pdf"], + uploadRateLimit: { + windowMs: 60_000, + maxUploads: 5, + }, + }, + kyc: { + skipVerification: true, + }, + } as any, + }), + ); + app.use(createErrorMiddleware(logger)); + + const response = await request(app).get("/api/v1/invoices").expect(401); + + expect(response.body).toMatchObject({ + success: false, + error: { + message: "Authorization token is required.", + }, + }); + expect(invoiceService.getInvoicesBySellerId).not.toHaveBeenCalled(); + }); +});