Compare commits
5 Commits
5671735e54
...
bab32023fb
Author | SHA1 | Date | |
---|---|---|---|
bab32023fb | |||
6efb268394 | |||
e5d6987b10 | |||
5a0ceadcc6 | |||
2cc1eac201 |
@ -1,5 +1,6 @@
|
||||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
module.exports = {
|
||||
testTimeout: 10000,
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
collectCoverage: true,
|
||||
|
41
Express/barAndCafe/package-lock.json
generated
41
Express/barAndCafe/package-lock.json
generated
@ -7,6 +7,7 @@
|
||||
"dependencies": {
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/node": "^20.12.7",
|
||||
"axios": "^1.6.8",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
"rimraf": "^5.0.5",
|
||||
@ -2105,8 +2106,7 @@
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
||||
"dev": true
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/atob": {
|
||||
"version": "2.1.2",
|
||||
@ -2121,6 +2121,16 @@
|
||||
"node": ">= 4.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.6.8",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
|
||||
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/babel-cli": {
|
||||
"version": "6.26.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-cli/-/babel-cli-6.26.0.tgz",
|
||||
@ -4319,7 +4329,6 @@
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
@ -4614,7 +4623,6 @@
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
@ -5138,6 +5146,25 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.6",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
|
||||
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/for-in": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||
@ -5180,7 +5207,6 @@
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
@ -8845,6 +8871,11 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
||||
},
|
||||
"node_modules/pseudomap": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||
|
@ -5,12 +5,15 @@
|
||||
"start": "node dist/src/server.js",
|
||||
"predev": "npm run build",
|
||||
"dev": "npx tsc -w & nodemon dist/src/server.js",
|
||||
"predocs": "npm run build",
|
||||
"docs": "jsdoc -c jsdoc.json",
|
||||
"pretest": "npm run build",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/node": "^20.12.7",
|
||||
"axios": "^1.6.8",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
"rimraf": "^5.0.5",
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { getCity } from "./openTripMaps"
|
||||
import express from "express"
|
||||
/**
|
||||
* Initialize Express application instance.
|
||||
@ -22,6 +23,7 @@ function getWelcome(req: express.Request, res: express.Response) {
|
||||
* @openapi
|
||||
* /welcome:
|
||||
* get:
|
||||
* summary: retun just hello
|
||||
* description: Welcome to swagger-jsdoc!
|
||||
* responses:
|
||||
* 200:
|
||||
@ -29,4 +31,27 @@ function getWelcome(req: express.Request, res: express.Response) {
|
||||
*/
|
||||
app.get("/welcome", getWelcome)
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /otm/city:
|
||||
* get:
|
||||
* summary: return the drinks in a city
|
||||
* description: return the drinks in a defined perimeter in a city
|
||||
* parameters:
|
||||
* - name: name
|
||||
* in: query
|
||||
* required: true
|
||||
* description: the name of the city
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Return a list of bars and coffee in city in geoJSON format
|
||||
* 400:
|
||||
* description: Missing Argument Error
|
||||
* 401:
|
||||
* description: Missing OTM tocken
|
||||
*/
|
||||
app.get("/otm/city", getCity)
|
||||
|
||||
export default app
|
71
Express/barAndCafe/src/openTripMaps.ts
Normal file
71
Express/barAndCafe/src/openTripMaps.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import axios from 'axios';
|
||||
import express from "express"
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config({path: '../../.env'})
|
||||
|
||||
const key = process.env.OPEN_TRIP_MAPS_KEY
|
||||
|
||||
const optionsDrink = {
|
||||
method: 'GET',
|
||||
url: 'https://api.opentripmap.com/0.1/en/places/radius',
|
||||
params: {
|
||||
radius: '1000',
|
||||
lon: '-1.43333',
|
||||
lat: '46.66667',
|
||||
apikey: key,
|
||||
kinds: 'bars,cafes,pubs,biergartens'
|
||||
},
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
};
|
||||
|
||||
|
||||
const optionsCity = {
|
||||
method: 'GET',
|
||||
url: 'https://api.opentripmap.com/0.1/en/places/geoname',
|
||||
params: {
|
||||
name: 'Paris',
|
||||
apikey: key
|
||||
},
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle GET request for city search route ('/otm/city').
|
||||
* @param {express.Request} req - HTTP Request object.
|
||||
* @param {express.Response} res - HTTP Response object.
|
||||
*/
|
||||
export async function getCity(req: express.Request, res: express.Response) {
|
||||
const cityName = req.query["name"]
|
||||
const radius = req.query["radius"]
|
||||
|
||||
if(!key){
|
||||
res.status(401).send("Missing OTM key")
|
||||
return
|
||||
}
|
||||
if(!cityName){
|
||||
res.status(400).send("Missing Argument name")
|
||||
return
|
||||
}
|
||||
if(radius){
|
||||
optionsDrink.params.radius = radius as string
|
||||
}
|
||||
|
||||
optionsCity.params.name = cityName as string
|
||||
|
||||
try {
|
||||
const { data } = await axios.request(optionsCity);
|
||||
optionsDrink.params.lat = data.lat
|
||||
optionsDrink.params.lon = data.lon
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await axios.request(optionsDrink);
|
||||
res.send(data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,7 @@ 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 => {
|
||||
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")
|
||||
|
66
Express/barAndCafe/test/openTripMaps.test.ts
Normal file
66
Express/barAndCafe/test/openTripMaps.test.ts
Normal file
@ -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<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();
|
||||
});
|
||||
});
|
||||
});
|
@ -1,3 +1,7 @@
|
||||
vars {
|
||||
TRIPMAP_URL: https://api.opentripmap.com/0.1
|
||||
}
|
||||
vars:secret [
|
||||
app_key
|
||||
app_key,
|
||||
OTM_KEY
|
||||
]
|
||||
|
@ -1,7 +1,7 @@
|
||||
meta {
|
||||
name: express test
|
||||
name: express Drink OTM
|
||||
type: http
|
||||
seq: 3
|
||||
seq: 4
|
||||
}
|
||||
|
||||
get {
|
19
bruno/OpenData datatourisme/otm_drink.bru
Normal file
19
bruno/OpenData datatourisme/otm_drink.bru
Normal file
@ -0,0 +1,19 @@
|
||||
meta {
|
||||
name: otm_drink
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{TRIPMAP_URL}}/en/places/radius?radius=1000&lon=-1.43333&lat=46.66667&apikey={{OTM_KEY}}&kinds=bars,cafes,pubs,biergartens
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
query {
|
||||
radius: 1000
|
||||
lon: -1.43333
|
||||
lat: 46.66667
|
||||
apikey: {{OTM_KEY}}
|
||||
kinds: bars,cafes,pubs,biergartens
|
||||
}
|
16
bruno/OpenData datatourisme/otm_ex_city.bru
Normal file
16
bruno/OpenData datatourisme/otm_ex_city.bru
Normal file
@ -0,0 +1,16 @@
|
||||
meta {
|
||||
name: otm_ex_city
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
get {
|
||||
url: http://localhost:3001/otm/city?name=La roche sur yon&radius=300
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
query {
|
||||
name: La roche sur yon
|
||||
radius: 300
|
||||
}
|
16
bruno/OpenData datatourisme/otm_location.bru
Normal file
16
bruno/OpenData datatourisme/otm_location.bru
Normal file
@ -0,0 +1,16 @@
|
||||
meta {
|
||||
name: otm_location
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{TRIPMAP_URL}}/en/places/geoname?name=Paris&apikey={{OTM_KEY}}
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
query {
|
||||
name: Paris
|
||||
apikey: {{OTM_KEY}}
|
||||
}
|
22
bruno/OpenData datatourisme/test graphQL.bru
Normal file
22
bruno/OpenData datatourisme/test graphQL.bru
Normal file
@ -0,0 +1,22 @@
|
||||
meta {
|
||||
name: test graphQL
|
||||
type: graphql
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: https://datatour-tweb.cb85.fr
|
||||
body: graphql
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:graphql {
|
||||
{
|
||||
poi {
|
||||
total
|
||||
results {
|
||||
_uri
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user