Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added addition function in test.js #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 34 additions & 3 deletions routes/route.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,6 +52,8 @@ router.post("/power", (req, res) => {
});
});


//factorial 2 number
router.post("/factorial", (req, res) => {
const { param1 } = req.body;

Expand Down Expand Up @@ -61,6 +91,7 @@ router.post("/factorial", (req, res) => {
}
});

//calcuate ceil value
router.post("/ceil", (req, res) => {
try {
const { param1 } = req.body;
Expand Down
57 changes: 52 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down