41 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-05-03 17:09:34 +02:00
import request from "supertest";
import app from "../src/app";
import { Server, IncomingMessage, ServerResponse } from "http";
2024-05-06 19:44:15 +02:00
import * as dotenv from "dotenv";
2024-05-03 17:09:34 +02:00
2024-05-06 19:44:15 +02:00
dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000')
2024-05-03 17:09:34 +02:00
let serveur : Server<typeof IncomingMessage, typeof ServerResponse>
2024-05-06 19:44:15 +02:00
describe("Test the welcome path", () => {
2024-05-03 17:09:34 +02:00
beforeEach(() => {
serveur = app.listen(port, () =>{
console.log(`serveur running in ${port}`)
})
})
afterEach((done) => {
serveur.close(done)
})
test("It should response the GET method", done => {
request(app)
2024-05-06 19:44:15 +02:00
.get("/welcome")
2024-05-03 17:09:34 +02:00
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
test("It should response the GET method", done => {
2024-05-06 19:44:15 +02:00
const out = {hello:"world"};
2024-05-03 17:09:34 +02:00
request(app)
2024-05-06 19:44:15 +02:00
.get("/welcome")
2024-05-03 17:09:34 +02:00
.then(response => {
2024-05-06 19:44:15 +02:00
expect(response.text).toEqual(JSON.stringify(out))
2024-05-03 17:09:34 +02:00
done();
});
});
});