bot-api/tests/auth.test.ts

35 lines
1017 B
TypeScript

import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import request 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 () => {
const correctRespose = await request(app)
.post("/login")
.send({ app: "tester", secret: "test" });
it("should return 200 for correct login", () => {
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);
});
});