diff --git a/src/index.test.ts b/src/index.test.ts index 2d73329..f4406b6 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -38,4 +38,13 @@ describe("GET /:number", () => { const {square_root } = response.body; assert.deepStrictEqual(square_root, expectedResponse); }); + + it("should return a custom response if the number is 10", async () => { + const number = 10; + const expectedResponse = { squareRoot: "Banana" }; + + const response = await request(app).get(`/${number}`).expect(200); + + assert.deepStrictEqual(response.body, expectedResponse); + }); }); diff --git a/src/server.ts b/src/server.ts index cf9518a..eeb8e58 100644 --- a/src/server.ts +++ b/src/server.ts @@ -10,6 +10,10 @@ app.get("/:number", (req, res) => { return res.status(400).send({ error: "Please provide a valid number" }); } + if (number === 10) { + return res.json({squareRoot: 'Banana' }); + } + const squareRoot = Math.sqrt(number); res.json({ square_root: squareRoot }); });