| 1 | import { app } from "../index"; |
| 2 | import request from "supertest"; |
| 3 | |
| 4 | describe("Express App", () => { |
| 5 | beforeAll(async () => { |
| 6 | // Mock initialize to avoid database connections during tests |
| 7 | jest.spyOn(console, "log").mockImplementation(() => {}); |
| 8 | jest.spyOn(console, "error").mockImplementation(() => {}); |
| 9 | }); |
| 10 | |
| 11 | afterAll(() => { |
| 12 | jest.restoreAllMocks(); |
| 13 | }); |
| 14 | |
| 15 | it("should return 404 for undefined routes", async () => { |
| 16 | const response = await request(app).get("/undefined-route"); |
| 17 | expect(response.status).toBe(404); |
| 18 | expect(response.body).toHaveProperty("status", "error"); |
| 19 | expect(response.body).toHaveProperty( |
| 20 | "message", |
| 21 | "Cannot find /undefined-route on this server!" |
| 22 | ); |
| 23 | }); |
| 24 | |
| 25 | it("should have a router stack", () => { |
| 26 | // Simply check that the app has a router stack |
| 27 | expect(app._router).toBeDefined(); |
| 28 | expect(Array.isArray(app._router.stack)).toBe(true); |
| 29 | expect(app._router.stack.length).toBeGreaterThan(0); |
| 30 | }); |
| 31 | }); |