import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import request, { Response } from "supertest"; import app, { startApp } from "../src/app"; import memoryServer from "./memoryServer"; import populateDatabase from "./populateDatabase"; beforeAll(async () => { if (!process.env.DEDICATED_MONGODB_SERVER) await memoryServer.start(); await startApp(); await populateDatabase(); }); afterAll(async () => { if (!process.env.DEDICATED_MONGODB_SERVER) await memoryServer.stop(); }); describe("/login", async () => { let correctRespose: Response; beforeAll(async () => { correctRespose = await request(app) .post("/login") .send({ app: "tester", secret: "test" }); }); it("should return 200 for correct login", async () => { expect(correctRespose.status).toBe(200); }); it("should contain a token", () => { expect(correctRespose.body).toHaveProperty("token"); }); it("should return 403 for invalid credentials", async () => { const res = await request(app).post("/login").send({}); expect(res.status).toBe(403); }); });