From 1046e2cd774b44f7f80f2a091afe031e7048fa1c Mon Sep 17 00:00:00 2001 From: jayanthanala Date: Sun, 26 Jul 2020 00:43:54 +0530 Subject: [PATCH 1/2] area of square added --- routes/route.js | 24 ++++++++++++++++++++++++ test/tests.js | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/routes/route.js b/routes/route.js index eacbb2d..bf5a2da 100644 --- a/routes/route.js +++ b/routes/route.js @@ -160,6 +160,30 @@ router.post("/areaOfRectangle", (req, res) => { } }); +router.post("/areaOfSquare", (req,res) => { + try{ + const{ param1 } = req.body; + let result = Math.pow(parseFloat(param1, 10),2); + + res.json({ + result, + meta: { + success:true, + message: `Calculated area of Square with side ${param1}`, + code: 200 + } + }) ; + }catch(err){ + res.json({ + meta:{ + success: false, + message: err.message, + code: 400 + } + }); + } +}); + module.exports = router; diff --git a/test/tests.js b/test/tests.js index f77d81a..7f65e8e 100644 --- a/test/tests.js +++ b/test/tests.js @@ -153,4 +153,25 @@ describe("----------START TEST FOR app.js----------", () => { } }); }); + + it("Checks the POST /math/areaOfSquare", done => { + chai + .request(app) + .post("/math/areaOfSquare") + .send({ param1: 5 }) + .end((err, res) => { + if (err) { + done(err); + process.exit(1); + } else { + res.body.result.should.be.a("number"); + res.body.meta.success.should.be.a("boolean"); + res.body.meta.message.should.be.a("string"); + res.body.meta.code.should.be.a("number"); + res.body.result.should.equal(25); + + done(); + } + }); + }); }); From 0b8afd9c238e14971cceb4885cd19ea9e3650545 Mon Sep 17 00:00:00 2001 From: jayanthanala Date: Sun, 26 Jul 2020 00:46:32 +0530 Subject: [PATCH 2/2] Area of Rectangle Updated --- test/tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.js b/test/tests.js index 7f65e8e..d71f454 100644 --- a/test/tests.js +++ b/test/tests.js @@ -135,7 +135,7 @@ describe("----------START TEST FOR app.js----------", () => { it("Checks the POST /math/areaOfRectangle", done => { chai .request(app) - .post("/math/power") + .post("/math/areaOfRectangle") .send({ param1: 3, param2: 2 }) .end((err, res) => { if (err) {