From e5d6987b104058ab3bf693aa9a2eacfb707835dd Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 13 May 2024 23:10:24 +0200 Subject: [PATCH] add some test --- Express/barAndCafe/test/app.test.ts | 14 +---- Express/barAndCafe/test/openTripMaps.test.ts | 66 ++++++++++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 Express/barAndCafe/test/openTripMaps.test.ts diff --git a/Express/barAndCafe/test/app.test.ts b/Express/barAndCafe/test/app.test.ts index f02dde7..e7ccc0a 100644 --- a/Express/barAndCafe/test/app.test.ts +++ b/Express/barAndCafe/test/app.test.ts @@ -10,17 +10,7 @@ let serveur : Server 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 => { + test("It should response the 200 code for GET method", done => { request(app) .get("/welcome") .then(response => { @@ -29,7 +19,7 @@ describe("Test the welcome path", () => { }); }); - test("It should response the GET method", done => { + test("It should response the GET method with content", done => { const out = {hello:"world"}; request(app) .get("/welcome") diff --git a/Express/barAndCafe/test/openTripMaps.test.ts b/Express/barAndCafe/test/openTripMaps.test.ts new file mode 100644 index 0000000..1e2ce39 --- /dev/null +++ b/Express/barAndCafe/test/openTripMaps.test.ts @@ -0,0 +1,66 @@ +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 + +describe("Test the otm city path", () => { + + test("It should response the 200 code for GET method", done => { + request(app) + .get("/otm/city") + .query({'name':'La roche sur yon'}) + .then(response => { + expect(response.statusCode).toBe(200); + done(); + }); + }); + + test("It should response the GET method with content", done => { + const out = { + "type": "FeatureCollection", + "features": [{ + "type": "Feature", + "id": "562635", + "geometry": { + "type": "Point", + "coordinates": [ + -1.4344594, + 46.6686478 + ] + }, + "properties": { + "xid": "N4032296324", + "name": "Le 27 point carré", + "dist": 236.40360026, + "rate": 1, + "osm": "node/4032296324", + "kinds": "foods,bars,tourist_facilities" + } + }] + } + + request(app) + .get("/otm/city") + .query({'name':'La roche sur yon', "radius": 240}) + .then(response => { + console.log(response.text) + expect(response.text).toEqual(JSON.stringify(out)) + done(); + }); + }); + + test("It should response the 400 code for GET method", done => { + request(app) + .get("/otm/city") + .then(response => { + console.log(response.text) + expect(response.statusCode).toBe(400); + done(); + }); + }); +}); \ No newline at end of file