ratrapage_T-WEB/Express/barAndCafe/test/openTripMaps.test.ts

169 lines
4.9 KiB
TypeScript
Raw Normal View History

2024-05-13 23:10:24 +02:00
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 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();
});
});
2024-05-15 00:12:36 +02:00
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 => {
2024-05-16 10:14:54 +02:00
const out = {
2024-05-15 00:12:36 +02:00
"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 => {
2024-05-16 10:14:54 +02:00
expect(response.text).toEqual(JSON.stringify(out));
2024-05-15 00:12:36 +02:00
done();
});
})
2024-05-18 13:04:12 +02:00
test("It should response the 200 code for GET method", done => {
request(app)
.get("/otm/poidetaill")
.query({'id':'562635'})
.then(response => {
expect(response.statusCode).toBe(200);
done();
});
});
test("Get bar in radius from API", done => {
const out = {
"xid": "N4032296324",
"name": "Le 27 point carré",
"address": {
"road": "Rue Raymond Poincaré",
"town": "La Roche-sur-Yon",
"state": "Pays de la Loire",
"county": "La Roche-sur-Yon",
"suburb": "Zola",
"country": "France",
"postcode": "85000",
"country_code": "fr",
"house_number": "27",
"neighbourhood": "Cité des Forges"
},
"rate": "1",
"osm": "node/4032296324",
"kinds": "foods,bars,tourist_facilities",
"sources": {
"geometry": "osm",
"attributes": [
"osm"
]
},
"otm": "https://opentripmap.com/en/card/N4032296324",
"point": {
"lon": -1.4344594478607178,
"lat": 46.66864776611328
}
}
request(app)
.get("/otm/poidetaill")
.query({'id':'562635'})
.then(response => {
expect(response.text).toEqual(JSON.stringify(out));
done();
});
})
test("It should response the 200 code for GET method", done => {
request(app)
.get("/otm/poidetaill")
.then(response => {
expect(response.statusCode).toBe(400);
done();
});
});
2024-05-13 23:10:24 +02:00
});