diff --git a/routes/date.test.js b/routes/date.test.js index 8fd09bf..0c66022 100644 --- a/routes/date.test.js +++ b/routes/date.test.js @@ -21,10 +21,10 @@ describe("/date", () => { }); describe("GET /month", () => { - it("should return 5", async () => { + it("should return 6", async () => { const res = await request(server).get("/date/month"); expect(res.statusCode).toEqual(200); - expect(res.body).toEqual({ month: 5 }); + expect(res.body).toEqual({ month: 6 }); }); }); diff --git a/routes/math.js b/routes/math.js index c2eeff9..de803f4 100644 --- a/routes/math.js +++ b/routes/math.js @@ -18,11 +18,12 @@ router.post("/sum", (req, res, next) => { router.post("/product", (req, res, next) => { if (req.body.length == 0) { - res.sendStatus(400).send("Product requires at least two values"); + res.sendStatus(400).send(); + } else if (req.body.length == 1) { + res.json({ product: req.body[0] }); } else { const product = req.body.reduce( - (runningProduct, num) => num * runningProduct, - 0 + (runningProduct, num) => num * runningProduct ); res.json({ product }); } diff --git a/routes/parrot.test.js b/routes/parrot.test.js index b7c3001..20f1ed5 100644 --- a/routes/parrot.test.js +++ b/routes/parrot.test.js @@ -5,7 +5,7 @@ const server = require("../server"); describe("/parrot", () => { describe("GET /parrot", () => { it("should return GET and query parameters", async () => { - const res = await request(server).get("/parrot?key1=true&key2=other"); + const res = await request(server).get("/parrot/parrot?key1=true&key2=other"); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ body: {}, @@ -20,10 +20,10 @@ describe("/parrot", () => { describe("POST /parrot", () => { it("should return POST and body", async () => { const requestBody = { - key: true, + key: "true", key2: "other", }; - const res = await request(server).post("/parrot").send(requestBody); + const res = await request(server).post("/parrot/parrot").send(requestBody); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ body: requestBody, @@ -39,7 +39,7 @@ describe("/parrot", () => { key2: "other", }; const res = await request(server) - .put("/parrot?field=value") + .put("/parrot/parrot?field=value") .send(requestBody); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ diff --git a/routes/string.test.js b/routes/string.test.js index bf4a55b..0c72130 100644 --- a/routes/string.test.js +++ b/routes/string.test.js @@ -17,12 +17,12 @@ describe("/string", () => { }); describe("GET /uppercase", () => { it("should not change an already uppercase version of a string", async () => { - const res = await request(server).get("/string/TEST/lowercase"); + const res = await request(server).get("/string/TEST/uppercase"); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ uppercase: "TEST" }); }); it("should return an uppercase version of a string", async () => { - const res = await request(server).get("/string/otHEr/lowercase"); + const res = await request(server).get("/string/otHEr/uppercase"); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ uppercase: "OTHER" }); });