diff --git a/README.md b/README.md index 3a06711..e35a28a 100644 --- a/README.md +++ b/README.md @@ -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/)||||| \ No newline at end of file +|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/)|||||| \ No newline at end of file diff --git a/calculator.postman_collection.json b/calculator.postman_collection.json new file mode 100644 index 0000000..8e6b170 --- /dev/null +++ b/calculator.postman_collection.json @@ -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": {} +} \ No newline at end of file diff --git a/src/model/calculator.js b/src/model/calculator.js index 91715bc..52dc5bc 100644 --- a/src/model/calculator.js +++ b/src/model/calculator.js @@ -4,7 +4,7 @@ class Calculator { } sum(firstNumber, secondNumber) { - if (firstNumber && secondNumber) { + if (firstNumber != null && secondNumber != null) { return firstNumber + secondNumber; } return null; diff --git a/src/routes/index.js b/src/routes/index.js index b17de91..7892f30 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -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 }) @@ -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 }) diff --git a/test/model/calculator.test.js b/test/model/calculator.test.js index b56cfd6..2b37bcf 100644 --- a/test/model/calculator.test.js +++ b/test/model/calculator.test.js @@ -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; @@ -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;