Skip to content

Commit

Permalink
Merge pull request #17 from yashvardhan-kukreja/yashvardhan-kukreja/#9
Browse files Browse the repository at this point in the history
Added route POST /math/power (#9)
  • Loading branch information
mayankshah1607 authored Oct 2, 2019
2 parents 6f81ff9 + b34da33 commit b9165f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions routes/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,18 @@ router.post('add', (req, res) => {
// Add logic here
})

router.post("/power", (req, res) => {
let param1 = req.body.param1;
let param2 = req.body.param2;

res.json({
result: Math.pow(param1, param2),
meta: {
success: true,
message: `Calculated ${param1} raised to the power ${param2}`,
code: 200
}
});
});

module.exports = router;
26 changes: 25 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const chai = require("chai");
const chaiHttp = require("chai-http");
const app = require("../app");
const assert = require('assert');
const should = require('should');
const should = chai.should()

chai.use(chaiHttp);

Expand All @@ -20,4 +20,28 @@ describe("----------START TEST FOR app.js----------", () => {
}
})
})

it("Checks the POST /math/power", (done) => {
chai.request(app)
.post("/math/power")
.send({"param1": 3, "param2": 2})
.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(9);


done()
}
})
})


})

0 comments on commit b9165f2

Please sign in to comment.