-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final test fix, now the response compared with expected value
- Loading branch information
Showing
2 changed files
with
37 additions
and
11 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import userSessions from '@tests/test-data/user-sessions.json'; | ||
import { describe, test, expect, beforeAll } from 'vitest'; | ||
import type User from '@domain/entities/user.js'; | ||
import { assertType } from 'vitest'; | ||
|
||
/** | ||
* Access token that will be used for Auhorization header | ||
|
@@ -21,12 +19,37 @@ describe('UserList API', () => { | |
describe('GET /users?page', () => { | ||
test.each([ | ||
{ portionSize : 3, | ||
pageNumber: 1 }, | ||
pageNumber: 1, | ||
expectedUserList: [ { | ||
'id': 1, | ||
'email': '[email protected]', | ||
'name': 'Test user 1', | ||
'createdAt': '2023-10-16T13:49:19.000Z', | ||
'photo': '', | ||
'editorTools': null, | ||
}, | ||
{ | ||
'id': 4, | ||
'email': '[email protected]', | ||
'name': 'Егор Амурин', | ||
'createdAt': '2023-10-22T16:19:40.892Z', | ||
'photo': 'https://lh3.googleusercontent.com/a/ACg8ocL9_uBaC7XMFhosJZfIkDLC8tTm1GhtbvDfSbjf9eI2=s96-c', | ||
'editorTools': null, | ||
}, | ||
{ | ||
'id': 5, | ||
'email': '[email protected]', | ||
'name': 'Алиса Марикова', | ||
'createdAt': '2023-11-11T20:23:40.892Z', | ||
'photo': '', | ||
'editorTools': null, | ||
} ] }, | ||
|
||
{ portionSize: 0, | ||
pageNumber : 2 }, | ||
pageNumber : 2, | ||
expectedUserList: [] }, | ||
]) | ||
('Returns a userList with specified lengths with status 200', async ({ portionSize, pageNumber }) => { | ||
('Returns a userList with specified lengths with status 200', async ({ portionSize, pageNumber, expectedUserList }) => { | ||
const expectedStatus = 200; | ||
|
||
const response = await global.api?.fakeRequest({ | ||
|
@@ -39,11 +62,11 @@ describe('UserList API', () => { | |
|
||
expect(response?.statusCode).toBe(expectedStatus); | ||
|
||
const users = response?.json().items; | ||
const usersList = response?.json().items; | ||
|
||
expect(users).toHaveLength(portionSize); | ||
expect(usersList).toHaveLength(portionSize); | ||
|
||
assertType<User>(users); | ||
expect(usersList).toStrictEqual(expectedUserList); | ||
}); | ||
|
||
test.each([ | ||
|
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 |
---|---|---|
|
@@ -4,20 +4,23 @@ | |
"email": "[email protected]", | ||
"name": "Test user 1", | ||
"created_at": "2023-10-16T13:49:19.000Z", | ||
"photo": "" | ||
"photo": "", | ||
"editor_tools": null | ||
}, | ||
{ | ||
"id": 4, | ||
"email": "[email protected]", | ||
"name": "Егор Амурин", | ||
"created_at": "2023-10-22 19:19:40.892+03", | ||
"photo": "https://lh3.googleusercontent.com/a/ACg8ocL9_uBaC7XMFhosJZfIkDLC8tTm1GhtbvDfSbjf9eI2=s96-c" | ||
"photo": "https://lh3.googleusercontent.com/a/ACg8ocL9_uBaC7XMFhosJZfIkDLC8tTm1GhtbvDfSbjf9eI2=s96-c", | ||
"editor_tools": null | ||
}, | ||
{ | ||
"id": 5, | ||
"email": "[email protected]", | ||
"name": "Алиса Марикова", | ||
"created_at": "2023-11-11 23:23:40.892+03", | ||
"photo": "" | ||
"photo": "", | ||
"editor_tools": null | ||
} | ||
] |