feat: init-express-backend (#6)
Reviewed-on: #6 Co-authored-by: Clement <c.boesmier@aptatio.com> Co-committed-by: Clement <c.boesmier@aptatio.com>
This commit is contained in:
41
Express/barAndCafe/test/app.test.ts
Normal file
41
Express/barAndCafe/test/app.test.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import request from "supertest";
|
||||
import app from "../src/app";
|
||||
import { Server, IncomingMessage, ServerResponse } from "http";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config({path: '../../.env'})
|
||||
const port = parseInt(process.env.BAR_PORT || '3000')
|
||||
|
||||
let serveur : Server<typeof IncomingMessage, typeof ServerResponse>
|
||||
|
||||
describe("Test the welcome path", () => {
|
||||
|
||||
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)
|
||||
.get("/welcome")
|
||||
.then(response => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test("It should response the GET method", done => {
|
||||
const out = {hello:"world"};
|
||||
request(app)
|
||||
.get("/welcome")
|
||||
.then(response => {
|
||||
expect(response.text).toEqual(JSON.stringify(out))
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user