|
1 | 1 | import Database from "better-sqlite3"; |
2 | 2 | import request from "supertest"; |
3 | 3 | import express from "express"; |
| 4 | +import { autoAuth, TEST_API_KEY } from "./helpers/api-key-helper.js"; |
4 | 5 | import type { Request, Response } from "express"; |
5 | 6 | import { resetByWalletRateLimitBuckets } from "../src/middleware/rateLimiter.js"; |
6 | 7 | import { |
@@ -317,9 +318,8 @@ describe("GET /api/jobs/by-wallet/:address – HTTP", () => { |
317 | 318 | // Dynamically import the router AFTER setDb() so it uses the in-memory DB |
318 | 319 | const { default: router } = await import("../src/routes/jobs.js"); |
319 | 320 | app = express(); |
320 | | - // Ensure no API_KEY gate is active for the baseline HTTP suite |
321 | | - delete process.env.API_KEY; |
322 | 321 | app.use(express.json()); |
| 322 | + app.use(autoAuth); |
323 | 323 | app.use("/api/jobs", router); |
324 | 324 | }); |
325 | 325 |
|
@@ -430,6 +430,7 @@ describe("GET /api/jobs/by-wallet/:address – Zod middleware", () => { |
430 | 430 | const { default: router } = await import("../src/routes/jobs.js"); |
431 | 431 | app = express(); |
432 | 432 | app.use(express.json()); |
| 433 | + app.use(autoAuth); |
433 | 434 | app.use("/api/jobs", router); |
434 | 435 | }); |
435 | 436 |
|
@@ -549,11 +550,11 @@ describe("GET /api/jobs/by-wallet/:address – status codes", () => { |
549 | 550 | const { default: router } = await import("../src/routes/jobs.js"); |
550 | 551 | app = express(); |
551 | 552 | app.use(express.json()); |
| 553 | + app.use(autoAuth); |
552 | 554 | app.use("/api/jobs", router); |
553 | 555 | }); |
554 | 556 |
|
555 | 557 | afterEach(() => { |
556 | | - delete process.env.API_KEY; |
557 | 558 | resetJobsByWalletCache(); |
558 | 559 | }); |
559 | 560 |
|
@@ -669,14 +670,14 @@ describe("GET /api/jobs/by-wallet/:address – status codes", () => { |
669 | 670 | expect(res.body.success).toBe(true); |
670 | 671 | }); |
671 | 672 |
|
672 | | - it("returns 200 (no gate) when API_KEY env var is not set", async () => { |
| 673 | + it("returns 401 (fails closed) when API_KEY env var is not set", async () => { |
673 | 674 | delete process.env.API_KEY; |
674 | 675 |
|
675 | 676 | const res = await request(app) |
676 | 677 | .get(`/api/jobs/by-wallet/${VALID_WALLET}`) |
677 | | - .expect(200); |
| 678 | + .expect(401); |
678 | 679 |
|
679 | | - expect(res.body.success).toBe(true); |
| 680 | + expect(res.body).toEqual({ success: false, error: "Unauthorized" }); |
680 | 681 | }); |
681 | 682 |
|
682 | 683 | // ------------------------------------------------------------------------- |
|
0 commit comments