Skip to content
Snippets Groups Projects
Commit 4754f9b0 authored by Leguy Emmanuel's avatar Leguy Emmanuel
Browse files

Rest service

parent 1abb2441
No related branches found
No related tags found
No related merge requests found
[
{
"name": "tgv",
"cfp": 0.002
},
{
"name": "metro",
"cfp": 0.003
},
{
"name": "rer",
"cfp": 0.07
},
{
"name": "vae",
"cfp": 0.1
},
{
"name": "bus-electric",
"cfp": 0.2
},
{
"name": "autocar",
"cfp": 0.3
},
{
"name": "ter",
"cfp": 0.3
},
{
"name": "electrical-car-covoit",
"cfp": 0.5
},
{
"name": "bus-thermique",
"cfp": 0.5
},
{
"name": "thermal-car",
"cfp": 2.1
},
{
"name": "scooter",
"cfp": 0.7
},
{
"name": "moto",
"cfp": 1.9
},
{
"name": "avion",
"cfp": 1.5
},
{
"name": "electrical-car",
"cfp": 1
},
{
"name": "thermal-car-covoit",
"cfp": 1.1
},
{
"name": "bus-thermique",
"cfp": 1.1
},
{
"name": "repas-vegetalien",
"cfp": 0.4
},
{
"name": "repas-vegetarien",
"cfp": 0.5
},
{
"name": "repas-poisson",
"cfp": 1.1
},
{
"name": "repas-poulet",
"cfp": 1.6
},
{
"name": "repas-boeuf",
"cfp": 7
},
{
"name": "chaffage-electric",
"cfp": 600
},
{
"name": "chaffage-gaz",
"cfp": 3800
},
{
"name": "chaffage-fioul",
"cfp": 5300
}
]
\ No newline at end of file
This diff is collapsed.
...@@ -13,13 +13,19 @@ ...@@ -13,13 +13,19 @@
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@types/eslint": "^8.44.7", "@types/eslint": "^8.44.7",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.10", "@types/jest": "^29.5.10",
"@types/supertest": "^2.0.16",
"@typescript-eslint/eslint-plugin": "^6.12.0", "@typescript-eslint/eslint-plugin": "^6.12.0",
"eslint": "^8.54.0", "eslint": "^8.54.0",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^15.0.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1", "ts-jest": "^29.1.1",
"ts-node-dev": "^2.0.0", "ts-node-dev": "^2.0.0",
"typescript": "^5.2.2" "typescript": "^5.2.2"
},
"dependencies": {
"express": "^4.18.2"
} }
} }
function display(message: string) { import express from 'express';
console.log(message); import { ProductsRepository, Product } from './products';
} import fs from 'fs';
display('Hello world!');
export const service = express();
service.get('/products', (request, response) => {
const products: Product[] = JSON.parse(fs.readFileSync('./data/products.json', 'utf-8'));
const productsRepository = new ProductsRepository(products);
response.status(200).json(productsRepository.all);
});
service.listen(8888);
\ No newline at end of file
import request from 'supertest';
import {service} from '../../src/index';
import { ProductsRepository } from '../../src/products';
describe('GET /products', () => {
it('should send a response with all the products in its body', async () => {
const spy = jest.spyOn(ProductsRepository.prototype, 'all', 'get');
await request(service).get('/products')
.expect(200)
.expect('content-type', /json/);
expect(spy).toHaveBeenCalled();
});
});
{ {
"compilerOptions": { "compilerOptions": {
"strict": true, "strict": true,
"outDir": "dist" "outDir": "dist",
"esModuleInterop": true
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment