From 3c134a8126562a679f63f13993eb65eff9eba6ca Mon Sep 17 00:00:00 2001 From: Ryan Fields Date: Sun, 12 Jul 2020 14:42:20 -0700 Subject: [PATCH 1/3] fixing route --- routes/date.test.js | 4 ++-- routes/math.js | 7 ++++--- routes/parrot.test.js | 8 ++++---- routes/string.test.js | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) 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" }); }); From 4bafc720203a52083f37ca800d8da5a1bb7a23b5 Mon Sep 17 00:00:00 2001 From: Ryan Fields Date: Sun, 12 Jul 2020 14:53:57 -0700 Subject: [PATCH 2/3] when mocking date check for +1 as month starts at 0 --- routes/date.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/date.test.js b/routes/date.test.js index 0c66022..cb2f08c 100644 --- a/routes/date.test.js +++ b/routes/date.test.js @@ -21,7 +21,7 @@ describe("/date", () => { }); describe("GET /month", () => { - it("should return 6", async () => { + it("should return 7", async () => { const res = await request(server).get("/date/month"); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ month: 6 }); From fb17b1536402e24234f79eee52595aed2c4e6ab9 Mon Sep 17 00:00:00 2001 From: Ryan Fields Date: Sun, 12 Jul 2020 14:54:44 -0700 Subject: [PATCH 3/3] fix text in test --- routes/date.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/date.test.js b/routes/date.test.js index cb2f08c..0c66022 100644 --- a/routes/date.test.js +++ b/routes/date.test.js @@ -21,7 +21,7 @@ describe("/date", () => { }); describe("GET /month", () => { - it("should return 7", async () => { + it("should return 6", async () => { const res = await request(server).get("/date/month"); expect(res.statusCode).toEqual(200); expect(res.body).toEqual({ month: 6 });