Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions routes/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
23 changes: 22 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
});
});
});