-
Notifications
You must be signed in to change notification settings - Fork 0
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
Task 4 testing #4
Open
kandalova
wants to merge
8
commits into
task_4_source_code
Choose a base branch
from
task_4_testing
base: task_4_source_code
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1934bb4
Add unit tests
924388c
Update README.md
kandalova 3c2af44
fix gitignore
43d5bd6
fix unit tests
554c2b3
Add integration tests and separate test configs
325229f
Update README.md
kandalova 609cd74
Add e2e tests
b655989
Update README.md
kandalova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/node_modules | ||
.vscode |
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 |
---|---|---|
@@ -1,2 +1,38 @@ | ||
# node-mentoring-introduction | ||
Task 1 | ||
Task 4 | ||
|
||
https://d17btkcdsmqrmh.cloudfront.net/node-gmp/docs/testing/Homework | ||
|
||
[Task API](https://date.nager.at/swagger/index.html) | ||
|
||
## Subtask 1 | ||
Write unit tests for public-holidays.service.ts and helpers.ts files. | ||
Keep in mind that any external calls are mocked in unit tests. | ||
|
||
Tests Result | ||
|
||
![2023-09-22_23h36_37](https://github.com/kandalova/node-mentoring-introduction/assets/26093763/81bd7f24-1837-42af-a42a-397972766bb4) | ||
|
||
## Subtask 2 | ||
Write integration tests for public-holidays.service.ts. Do not forget that in this case you make real calls to the API. | ||
|
||
Tests Result | ||
|
||
![2023-09-22_23h37_02](https://github.com/kandalova/node-mentoring-introduction/assets/26093763/04812cbb-187a-4b4c-81b3-e27a29ed3387) | ||
|
||
|
||
## Subtask 3 | ||
Get code coverage with tests for your application. | ||
Strive to have no less than 90% of code coverage. | ||
|
||
Tests results | ||
|
||
![2023-09-22_23h36_01](https://github.com/kandalova/node-mentoring-introduction/assets/26093763/a9cae208-6d77-44bc-ac5a-ae25717c148f) | ||
|
||
## Subtask 4 | ||
Select any 2 endpoints from <code>Nager.Date API</code> and write e2e tests for them. | ||
|
||
Tests Result | ||
|
||
![image](https://github.com/kandalova/node-mentoring-introduction/assets/26093763/dd65bdaa-98a5-460f-a0a5-370711232df9) | ||
|
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,14 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
roots: ['./src'], | ||
preset: 'ts-jest', | ||
collectCoverageFrom: ['src/**'], | ||
coverageReporters: ['text'], | ||
coverageThreshold: { | ||
global: { | ||
lines: 98 | ||
} | ||
}, | ||
silent: false, | ||
verbose: true, | ||
}; |
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,8 @@ | ||
var config = require('./jest.config') | ||
config.testMatch= [ | ||
"**/tests/**/e2e/**/*.[jt]s?(x)", | ||
"**.e2e.[jt]s?(x)", | ||
], | ||
config.displayName= "e2e", | ||
console.log('RUNNING E2E TESTS'); | ||
module.exports = config |
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,8 @@ | ||
var config = require('./jest.config') | ||
config.testMatch= [ | ||
"**/tests/**/integration/**/*.[jt]s?(x)", | ||
"**.integration.[jt]s?(x)", | ||
], | ||
config.displayName= "integration", | ||
console.log('RUNNING INTEGRATION TESTS'); | ||
module.exports = config |
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,8 @@ | ||
var config = require('./jest.config') | ||
config.testMatch= [ | ||
"**/tests/**/unit/**/*.[jt]s?(x)", | ||
"**.unit.[jt]s?(x)", | ||
], | ||
config.displayName= "unit", | ||
console.log('RUNNING UNIT TESTS'); | ||
module.exports = config |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,60 @@ | ||
import request from 'supertest'; | ||
import 'expect-more-jest'; | ||
|
||
const PUBLIC_HOLIDAYS_API_URL = 'https://date.nager.at/api/v3'; | ||
|
||
describe("Date Nager API", ()=>{ | ||
describe("/PublicHolidays", ()=>{ | ||
test("Should return 200 and array of holidays", async ()=>{ | ||
const url = `/PublicHolidays/${2023}/${"GB"}`; | ||
const {status, body} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect(status).toEqual(200); | ||
body.forEach((holiday:any)=>{ | ||
expect(holiday).toEqual({ | ||
date: expect.any(String), | ||
localName: expect.toBeNullableOf(expect.any(String)), | ||
name: expect.toBeNullableOf(expect.any(String)), | ||
countryCode: expect.toBeNullableOf(expect.any(String)), | ||
fixed: expect.any(Boolean), | ||
global: expect.any(Boolean), | ||
counties: expect.toBeNullableOf(expect.toBeArrayOfStrings()), | ||
launchYear: expect.toBeNullableOf(expect.any(Number)), | ||
types: expect.toBeNullableOf(expect.toBeArrayOfStrings()), | ||
}) | ||
}); | ||
}); | ||
test("Should return 404 code",async () => { | ||
const url = `/PublicHolidays/${2023}/${"wrong"}`; | ||
const {status} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect(status).toEqual(404); | ||
}); | ||
test("Should return 400 code",async () => { | ||
const url = `/PublicHolidays/${202}/${"GB"}`; | ||
const {status} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect(status).toEqual(400); | ||
}) | ||
}); | ||
|
||
describe("/IsTodayPublicHoliday", ()=>{ | ||
test("Should return 200 or 204", async ()=>{ | ||
const url = `/IsTodayPublicHoliday/GB`; | ||
const {status} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect([200, 204]).toContain(status); | ||
}); | ||
test("Should return 200 or 204 with offset query", async ()=>{ | ||
const url = `/IsTodayPublicHoliday/GB/?offset=4`; | ||
const {status} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect([200, 204]).toContain(status); | ||
}); | ||
test("Should return 404 code",async () => { | ||
const url = `/PublicHolidays/wrong`; | ||
const {status} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect(status).toEqual(404); | ||
}); | ||
test("Should return 400 code",async () => { | ||
const url = `/PublicHolidays/202/GB`; | ||
const {status} = await request(PUBLIC_HOLIDAYS_API_URL).get(url); | ||
expect(status).toEqual(400); | ||
}) | ||
}) | ||
}) |
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,73 @@ | ||
import { checkIfTodayIsPublicHoliday, getListOfPublicHolidays, getNextPublicHolidays } from "../../services/public-holidays.service"; | ||
|
||
|
||
const YEAR = 2023; | ||
const COUNTRY = 'GB'; | ||
const SHORT_HOLIDAY = { | ||
"date": "2023-09-21", | ||
"localName": "string", | ||
"name": "string", | ||
} | ||
|
||
describe("Public holidays service", () => { | ||
|
||
it("should get all holidays", async () => { | ||
const holidaysResponseBefore = await getListOfPublicHolidays(YEAR, COUNTRY); | ||
|
||
expect(holidaysResponseBefore).toBeInstanceOf(Array); | ||
|
||
const holidaysResponseAfter = await getListOfPublicHolidays(YEAR, COUNTRY); | ||
const responseKeys = Object.keys(holidaysResponseAfter[0]); | ||
const expectedKeysKeys = Object.keys(SHORT_HOLIDAY); | ||
|
||
expect(holidaysResponseAfter.length).toBe(holidaysResponseBefore.length); | ||
|
||
expect(responseKeys).toEqual(expect.arrayContaining(expectedKeysKeys)); | ||
expect(holidaysResponseAfter[0]).toEqual(expect.objectContaining({ | ||
date: expect.any(String), | ||
localName: expect.any(String), | ||
name: expect.any(String) | ||
})); | ||
}); | ||
|
||
|
||
it('all holidays should throw error for wrong county', async () => { | ||
await expect(getListOfPublicHolidays(YEAR, "wrong")).rejects.toThrow(`Country provided is not supported, received: wrong`); | ||
}); | ||
|
||
it('all holidays should throw error for wrong year', async () => { | ||
await expect(getListOfPublicHolidays(1000, COUNTRY)).rejects.toThrow(`Year provided not the current, received: 1000`); | ||
}); | ||
|
||
it('check today should throw error for wrong county', async () => { | ||
await expect(checkIfTodayIsPublicHoliday("wrong")).rejects.toThrow(`Country provided is not supported, received: wrong`); | ||
}); | ||
|
||
it("check today should return boolean", async () => { | ||
const todayResponce = await checkIfTodayIsPublicHoliday(COUNTRY); | ||
expect(typeof todayResponce === 'boolean').toBeTruthy(); | ||
}); | ||
|
||
it('next holidays should throw error for wrong county', async () => { | ||
await expect(getNextPublicHolidays("wrong")).rejects.toThrow(`Country provided is not supported, received: wrong`); | ||
}); | ||
|
||
it("should get next holidays", async () => { | ||
const holidaysResponseBefore = await getNextPublicHolidays(COUNTRY); | ||
|
||
expect(holidaysResponseBefore).toBeInstanceOf(Array); | ||
|
||
const holidaysResponseAfter = await getNextPublicHolidays(COUNTRY); | ||
const responseKeys = Object.keys(holidaysResponseAfter[0]); | ||
const expectedKeysKeys = Object.keys(SHORT_HOLIDAY); | ||
|
||
expect(holidaysResponseAfter.length).toBe(holidaysResponseBefore.length); | ||
|
||
expect(responseKeys).toEqual(expect.arrayContaining(expectedKeysKeys)); | ||
expect(holidaysResponseAfter[0]).toEqual(expect.objectContaining({ | ||
date: expect.any(String), | ||
localName: expect.any(String), | ||
name: expect.any(String) | ||
})); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
все пункты выполнены! молодец )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо!