diff --git a/README.md b/README.md index b108ad8..42903cf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,15 @@ $ npm start 5. To run the test suite, execute the following command: ```bash $ npm run test + +## Dependencies + "body-parser": "^1.19.0", + "express": "^4.17.1", + "assert": "^2.0.0", + "chai": "^4.2.0", + "chai-http": "^4.3.0", + "mocha": "^6.2.0", + "should": "^13.2.3" ``` ## Contributing diff --git a/routes/route.js b/routes/route.js index cb8a48c..c8c4897 100644 --- a/routes/route.js +++ b/routes/route.js @@ -1,15 +1,43 @@ -const express = require("express"); +var express = require("express"); +var router = express.Router(); -const router = express.Router(); +//check the running status of the app router.get("/check", (req, res) => { res.send("Congratulations! Your app works! :)"); }); +// addition 2 numbers router.post("add", (req, res) => { - // Add logic here + let param1 = req.body.param1; + let param2 = req.body.param2; + + res.json({ + result:param1+ param2, + meta: { + success: true, + message: `Calculated ${param1} + ${param2}`, + code: 200 + } + }); }); +//multiplication of 2 number +router.post("multi", (req, res) => { + let param1 = req.body.param1; + let param2 = req.body.param2; + + res.json({ + result: param1 + param2, + meta: { + success: true, + message: `Calculated ${param1} * ${param2}`, + code: 200 + } + }); +}); + +//power 2 number router.post("/power", (req, res) => { let param1 = req.body.param1; let param2 = req.body.param2; @@ -24,6 +52,8 @@ router.post("/power", (req, res) => { }); }); + +//factorial 2 number router.post("/factorial", (req, res) => { const { param1 } = req.body; @@ -61,6 +91,7 @@ router.post("/factorial", (req, res) => { } }); +//calcuate ceil value router.post("/ceil", (req, res) => { try { const { param1 } = req.body; diff --git a/test/tests.js b/test/tests.js index b22dc69..234a7d4 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,11 +1,14 @@ -const chai = require("chai"); -const chaiHttp = require("chai-http"); -const app = require("../app"); -const assert = require("assert"); -const should = chai.should(); +var chai = require("chai"); +var chaiHttp = require("chai-http"); +var app = require("../app"); +var assert = require("assert"); +var should = chai.should(); chai.use(chaiHttp); +// REST Used for calculation + + describe("----------START TEST FOR app.js----------", () => { it("Checks if the App is working", done => { chai @@ -44,6 +47,50 @@ describe("----------START TEST FOR app.js----------", () => { }); }); + it("Checks the POST /math/add", done => { + chai + .request(app) + .post("/math/add") + .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(5); + + done(); + } + }); + }); + + it("Checks the POST /math/multi", done => { + chai + .request(app) + .post("/math/multi") + .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(6); + + done(); + } + }); + }); + it("Checks the POST /math/power", done => { chai .request(app)