Added fake data for test and dev environment #17

Merged
Suguivy merged 77 commits from testing into develop 2024-01-06 12:34:44 +00:00
4 changed files with 27 additions and 12 deletions
Showing only changes of commit 7c68174ca4 - Show all commits

View File

@ -7,6 +7,7 @@ const authTokenSecret = process.env.JWTSECRET || "badsecret";
class AuthControler {
async login(req: Request, res: Response) {
// Read app and secret from request body
console.log(req.body)
const { app, secret } = req.body;
// Filter app from the apps by app and secret

View File

@ -1,3 +1,12 @@
import populateDatabase from "../tests/populateDatabase";
import { startApp } from "./app";
startApp();
await startApp();
try{
await populateDatabase();
}
catch {
}

View File

@ -1,8 +1,10 @@
import AuthModel, { Auth } from "../models/AuthModel";
class AuthService {
async find(app: string, secret: string): Promise<Auth | null> {
async find(app: String, secret: String): Promise<Auth | null> {
console.log(app, secret)
const auth = await AuthModel.findOne({ app: app, secret: secret });
console.log(auth)
return auth;
}
}

View File

@ -1,28 +1,31 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import request from "supertest";
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();
if (!process.env.DEDICATED_MONGODB_SERVER) await memoryServer.start();
await startApp();
await populateDatabase();
});
afterAll(async () => {
if (!process.env.DEDICATED_MONGODB_SERVER)
await memoryServer.stop();
if (!process.env.DEDICATED_MONGODB_SERVER) await memoryServer.stop();
});
describe("/login", async () => {
const correctRespose = await request(app)
let correctRespose: Response;
beforeAll(async () => {
correctRespose = await request(app)
.post("/login")
.send({ app: "tester", secret: "test" });
it("should return 200 for correct login", () => {
});
it("should return 200 for correct login", async () => {
expect(correctRespose.status).toBe(200);
});
it("should contain a token", () => {
expect(correctRespose.body).toHaveProperty("token");
});