-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2c30ddc
Showing
8 changed files
with
5,215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
|
||
const { add, subtract } = require('./calculator'); | ||
|
||
app.get('/add', (req, res) => { | ||
let { value1, value2 } = req.query; | ||
value1 = parseInt(value1); | ||
value2 = parseInt(value2); | ||
res.json({ | ||
result: add(value1, value2), | ||
}); | ||
}); | ||
|
||
app.get('/subtract', (req, res) => { | ||
let { value1, value2 } = req.query; | ||
value1 = parseInt(value1); | ||
value2 = parseInt(value2); | ||
res.json({ | ||
result: subtract(value1, value2), | ||
}); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const app = require('./app'); | ||
const supertest = require('supertest'); | ||
const request = supertest(app); //arrange | ||
|
||
test('gets the add endpoint', async done => { | ||
const response = await request.get('/add?value1=2&value2=2'); //Act | ||
expect(response.status).toBe(200); | ||
expect(response.type).toBe('application/json'); | ||
expect(response.body.result).toBe(4); | ||
done(); | ||
}); | ||
|
||
test('gets the subtract endpoint', async done => { | ||
const response = await request.get('/subtract?value1=2&value2=4'); //Act | ||
expect(response.status).toBe(200); | ||
expect(response.type).toBe('application/json'); | ||
expect(response.body.result).not.toBeNull(); | ||
expect(response.body.result).toBe(-2); | ||
done(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function add(a, b) { | ||
return a + b; | ||
} | ||
|
||
function subtract(a, b) { | ||
return a - b; | ||
} | ||
|
||
module.exports = { add, subtract }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { add, subtract } = require('./calculator'); //Arrange | ||
|
||
describe('add operation', () => { | ||
test('adds 1 + 2 to equal 3', () => { | ||
var value = add(1, 2); //Act | ||
expect(value).toBe(3); //Assert | ||
}); | ||
|
||
test('adds 5 + 5 to equal 10', () => { | ||
var value = add(5, 5); //Act | ||
expect(value).toBe(10); //Assert | ||
}); | ||
}); | ||
|
||
describe('subtract operation', () => { | ||
test('subtracts 5 - 5 to equal 0', () => { | ||
var value = subtract(5, 5); //Act | ||
expect(value).toBe(0); //Assert | ||
}); | ||
|
||
test('subtracts 3 - 2 to equal 1', () => { | ||
var value = subtract(3, 2); //Act | ||
expect(value).toBe(1); //Assert | ||
}); | ||
}); |
Oops, something went wrong.