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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ This project is used as an example of a project using different tools used in a

## Tools and technologies used

|CI/CD|Code Quality and security|Infrastructure monitoring and APM|PaaS Cloud hosting|Infrastructure as Code|Secrets management|
|-----|-------------------------|---------------------------------|------------------|----------------------|------------------|
|[Github Actions](https://github.com/features/actions)|[Newman](https://learning.postman.com/docs/running-collections/using-newman-cli/command-line-integration-with-newman/)|[DataDog](https://www.datadoghq.com/)|[AWS Lambda](https://aws.amazon.com/lambda/?did=ft_card&trk=ft_card)|[Terraform](https://www.terraform.io/)|[Hashicorp Vault](https://www.hashicorp.com/products/vault)|
||[Split.io](https://split.io/)|[xMatters](https://www.xmatters.com/)|[DigitalOcean App Platform](https://www.digitalocean.com/products/app-platform/)|||
||[Codacy](https://www.codacy.com/)|||||
||[Snyk](https://snyk.io/)|||||
||[Coveralls](https://coveralls.io/)|||||
|CI/CD|Code Quality and security|Infrastructure monitoring and APM|PaaS Cloud hosting|Infrastructure as Code|Secrets management|Package manager|
|-----|-------------------------|---------------------------------|------------------|----------------------|------------------|---------------|
|[Github Actions](https://github.com/features/actions)|[Newman](https://learning.postman.com/docs/running-collections/using-newman-cli/command-line-integration-with-newman/)|[DataDog](https://www.datadoghq.com/)|[AWS Lambda](https://aws.amazon.com/lambda/?did=ft_card&trk=ft_card)|[Terraform](https://www.terraform.io/)|[Hashicorp Vault](https://www.hashicorp.com/products/vault)|[GitHub Packages](https://github.com/features/packages)|
||[Split.io](https://split.io/)|[xMatters](https://www.xmatters.com/)|[DigitalOcean App Platform](https://www.digitalocean.com/products/app-platform/)||||
||[Codacy](https://www.codacy.com/)||||||
||[Snyk](https://snyk.io/)||||||
||[Coveralls](https://coveralls.io/)||||||
117 changes: 117 additions & 0 deletions calculator.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"info": {
"_postman_id": "b70dd849-82d9-4509-8a1b-c1c54ed44903",
"name": "Devops tool stack",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Sum",
"event": [
{
"listen": "test",
"script": {
"id": "bcfd0b9f-0c14-4a9f-848a-437af7f617bd",
"exec": [
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"pm.test(\"Result is correct\", function () {\r",
" var result = pm.response.json().result;\r",
" var expected = 4\r",
" pm.expect(result).to.eql(expected);\r",
"});\r",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"firstNumber\":2,\r\n \"secondNumber\":2\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/sum",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"sum"
]
}
},
"response": []
},
{
"name": "Diff",
"event": [
{
"listen": "test",
"script": {
"id": "7120666b-c4bd-4aa3-b621-9e976702c80e",
"exec": [
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"pm.test(\"Result is correct\", function () {\r",
" var result = pm.response.json().result;\r",
" var expected = 0\r",
" pm.expect(result).to.eql(expected);\r",
"});\r",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"firstNumber\":2,\r\n \"secondNumber\":2\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3000/diff",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"diff"
]
}
},
"response": []
},
{
"name": "Root query",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": ""
}
},
"response": []
}
],
"protocolProfileBehavior": {}
}
2 changes: 1 addition & 1 deletion src/model/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Calculator {
}

sum(firstNumber, secondNumber) {
if (firstNumber && secondNumber) {
if (firstNumber != null && secondNumber != null) {
return firstNumber + secondNumber;
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ router.post('/sum', function (req, res, next) {
let secondNumber = req.body.secondNumber;
let result = calculator.sum(firstNumber, secondNumber)

if (result) {
if (result != null) {
res.status(200).send({
result
})
Expand All @@ -27,7 +27,7 @@ router.post('/diff', function (req, res, next) {
let firstNumber = req.body.firstNumber;
let secondNumber = req.body.secondNumber;
let result = calculator.diff(firstNumber, secondNumber)
if (result) {
if (result != null) {
res.status(200).send({
result
})
Expand Down
17 changes: 17 additions & 0 deletions test/model/calculator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ describe("Calculator", () => {
const result = calculator.sum(firstNumber, secondNumber)
expect(result).toEqual(expected)
})

test("the sum of two numbers is 0", () => {
const firstNumber = 0;
const secondNumber = 0;
const expected = 0;
const result = calculator.sum(firstNumber, secondNumber)
expect(result).toEqual(expected)
})

test("the result is invalid because of missing firstNumber", () => {
const firstNumber = null;
const secondNumber = 3;
Expand All @@ -32,6 +41,14 @@ describe("Calculator", () => {
expect(result).toEqual(expected)
})

test("the diff of two numbers is 0", () => {
const firstNumber = 4;
const secondNumber = 4;
const expected = 0;
const result = calculator.diff(firstNumber, secondNumber)
expect(result).toEqual(expected)
})

test("the diff of two numbers is -2", () => {
const firstNumber = 4;
const secondNumber = 6;
Expand Down