Skip to content

Commit

Permalink
Merge pull request #31 from zinixyt/main
Browse files Browse the repository at this point in the history
ADDED THE JSON NORMALIZATION TESTS
  • Loading branch information
Unisergius authored Mar 13, 2024
2 parents 4dae393 + 2ef782a commit 7be2cd7
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 4 deletions.
19 changes: 18 additions & 1 deletion __test__/math.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { app } from '..';
/** @format */

import {
addTwoNumbers,
divideTwoNumbers,
Expand All @@ -8,6 +8,8 @@ import {
subtractTwoNumbers,
} from '../math.handler';

import request from 'supertest';

Check failure on line 11 in __test__/math.test.ts

View workflow job for this annotation

GitHub Actions / Deploy proxy

Could not find a declaration file for module 'supertest'. '/home/runner/work/simple-math-api-exercise/simple-math-api-exercise/node_modules/supertest/index.js' implicitly has an 'any' type.

/*
This file includes a battery of test for the math library we created. Using
Jest, we can describe a group of tests and run them.
Expand Down Expand Up @@ -47,6 +49,21 @@ describe('test math handler', (): void => {
test('sub two numbers', (): void => {
expect(subtractTwoNumbers(5, 3)).toBe(2);
});
test('test sum json response normalization', async(): Promise<void> => {
const expected = {"message":"Sum Operation","operation":"success","a":"1","b":"1","sum":2}
const resSum = await request(app).get("/sum/1/1")
expect(resSum.body).toEqual(expected)
});
test('test subtract json response normalization', async(): Promise<void> => {
const expected = {"message":"Subtract Operation","operation":"success","a":"5","b":"5","c":0}
const resDiv = await request(app).get("/subtract/5/5")
expect(resDiv.body).toEqual(expected)
});
test('test division json response normalization', async(): Promise<void> => {
const expected = {"message":"Div Operation","operation":"success","a":"5","b":"5","c":1}
const resDiv = await request(app).get("/div/5/5")
expect(resDiv.body).toEqual(expected)
});
test('power two numbers', (): void => {
expect(powerTwoNumbers(10, 25)).toBe(10000000000000000000000000);
});
Expand Down
174 changes: 171 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"homepage": "https://github.com/Unisergius/simple-math-api-exercise#readme",
"dependencies": {
"dotenv": "^16.0.3",
"supertest": "^6.3.4",
"express": "^4.18.3"
},
"devDependencies": {
Expand Down

0 comments on commit 7be2cd7

Please sign in to comment.