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..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) { @@ -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(); + } + }); + }); });