feat: open-trip-api-drink #11

Merged
Clement merged 34 commits from feat/open-trip-api into master 2024-05-19 09:38:39 +00:00
Showing only changes of commit c8266560eb - Show all commits

View File

@ -2,6 +2,7 @@ import request from "supertest";
import app from "../src/app"; import app from "../src/app";
import { Server, IncomingMessage, ServerResponse } from "http"; import { Server, IncomingMessage, ServerResponse } from "http";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
import rewire from 'rewire';
dotenv.config({path: '../../.env'}) dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000') const port = parseInt(process.env.BAR_PORT || '3000')
@ -9,6 +10,48 @@ const port = parseInt(process.env.BAR_PORT || '3000')
let serveur : Server<typeof IncomingMessage, typeof ServerResponse> let serveur : Server<typeof IncomingMessage, typeof ServerResponse>
describe("Test the otm city path", () => { describe("Test the otm city path", () => {
const opentripmapModule = rewire("../src/openTripMaps")
const callCity = opentripmapModule.__get__("callCity")
const callRadius = opentripmapModule.__get__("callRadius")
test("Get city from OTM", async () => {
const res = {
"name": "Paris",
"country": "FR",
"lat": 48.85341,
"lon": 2.3488,
"population": 2138551,
"timezone": "Europe/Paris",
"status": "OK"
}
expect(await callCity("Paris")).toEqual(res)
})
test("Get bar in radius from OTM", async () => {
const res = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"id": "562635",
"geometry": {
"type": "Point",
"coordinates": [
-1.4344594,
46.6686478
]
},
"properties": {
"xid": "N4032296324",
"name": "Le 27 point carré",
"dist": 0.17652159,
"rate": 1,
"osm": "node/4032296324",
"kinds": "foods,bars,tourist_facilities"
}
}]
}
expect(await callRadius("-1.4344594", "46.6686478", "10")).toEqual(res)
})
test("It should response the 200 code for GET method", done => { test("It should response the 200 code for GET method", done => {
request(app) request(app)
@ -63,4 +106,49 @@ describe("Test the otm city path", () => {
done(); done();
}); });
}); });
test("It should response the 200 code for GET method", done => {
request(app)
.get("/otm/radius")
.query({'lon':'-1.4344594', 'lat' : '46.6686478', 'radius': '10'})
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
//TODO faire les test pour les cas d'erreur
test("Get bar in radius from API", done => {
const res = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"id": "562635",
"geometry": {
"type": "Point",
"coordinates": [
-1.4344594,
46.6686478
]
},
"properties": {
"xid": "N4032296324",
"name": "Le 27 point carré",
"dist": 0.17652159,
"rate": 1,
"osm": "node/4032296324",
"kinds": "foods,bars,tourist_facilities"
}
}]
}
request(app)
.get("/otm/radius")
.query({'lon':'-1.4344594', 'lat' : '46.6686478', 'radius': '10'})
.then(response => {
expect(response.text).toEqual(JSON.stringify(res));
done();
});
})
}); });