test: add tests for steps controller
continuous-integration/drone/push Build is failing Details

WORK-RRE
Rémi REGNAULT 1 year ago
parent c183b18074
commit 74c60cc156

@ -8,16 +8,17 @@ const steps_gw = new StepsGateway()
StepsController.get('/:id', async (req, res) => {
const id = String(req.params.id);
const id = Number(req.params.id);
if (!Number.isInteger(id)) {
throw new Exceptions.BadRequestException('id invalid !');
res.status(400).send('invalid parameter or no parameter')
return
}
try {
const steps = await steps_gw.getForRecipes(Number(id))
if (steps == null) {
if (steps.length == 0) {
res.status(404).send('not found')
}
else {

@ -28,7 +28,6 @@ export const startServer = (port_to_use: number) => {
return app.listen(port_to_use, () => console.log(`App listening on PORT ${port}`));
};
// Exécutez le serveur uniquement si le module est le point d'entrée principal
if (require.main === module) {
startServer(port);
}

@ -25,12 +25,4 @@ export class Recipe implements IRecipe {
this.ingredients = ingredients
this.steps = steps
}
addStep(newStep: string) {
this.steps.push(newStep)
}
addIngredient(newIngredient: IIngredient) {
this.ingredients.push(newIngredient)
}
}

@ -0,0 +1,33 @@
import request from 'supertest';
import app, { startServer } from '../src/server';
import { Server, IncomingMessage, ServerResponse } from 'http';
describe('GET /steps', () => {
let server: Server<typeof IncomingMessage, typeof ServerResponse>;
const port = 3003
beforeAll(() => {
server = startServer(port);
});
afterAll((done) => {
server.close(done);
});
// /steps/:id
it('should return a 200 status code', async () => {
const response = await request(app).get('/steps/4444');
expect(response.status).toBe(200);
});
it('should return a 400 status code', async () => {
const response = await request(app).get('/steps/hey');
expect(response.status).toBe(400);
});
it('should return a 404 status code', async () => {
const response = await request(app).get('/steps/1');
expect(response.status).toBe(404);
});
});
Loading…
Cancel
Save