From e8c23d179f3eb7b62ed772fcc30aa36a33e5e34c Mon Sep 17 00:00:00 2001 From: Mara Martini Date: Wed, 29 Nov 2023 16:24:53 +0100 Subject: [PATCH] tests ok --- packages/backend/src/server.js | 2 +- packages/backend/test/hello.test.js | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/backend/src/server.js b/packages/backend/src/server.js index 4758ae2..2b21f94 100644 --- a/packages/backend/src/server.js +++ b/packages/backend/src/server.js @@ -38,7 +38,7 @@ app.get('/products/:id', (request, response) => { if (product) { response.json(product); } else { - response.status(404); + response.sendStatus(404); } }); diff --git a/packages/backend/test/hello.test.js b/packages/backend/test/hello.test.js index a12700e..e614093 100644 --- a/packages/backend/test/hello.test.js +++ b/packages/backend/test/hello.test.js @@ -9,18 +9,18 @@ test('First test', async () => { server.close(); }); -// test('Test /products endpoint', async () => { -// const server = createServer(4400); -// await request(SERVER_URL) -// .get('/products') -// .expect(200) -// .expect(function (response) { -// expect(response.body.length).toEqual(6); -// const cards = response.body; -// expect(cards[0].id).toEqual(0); -// }); -// server.close(); -// }); +test('Test /products endpoint', async () => { + const server = createServer(4400); + await request(SERVER_URL) + .get('/products') + .expect(200) + .expect(function (response) { + expect(response.body.length).toEqual(6); + const cards = response.body; + expect(cards[0].id).toEqual(0); + }); + server.close(); +}); test('Test getProductById', async () => { const server = createServer(4400); @@ -36,9 +36,5 @@ test('Test nonexistent product id', async () => { const productId = 10; const response = await request(SERVER_URL).get(`/products/${productId}`); expect(response.status).toEqual(404); - expect(response.body).toEqual({ - error: 'Produit non trouvé', - }); - server.close(); });