Skip to content

Commit

Permalink
Final test fix, now the response compared with expected value
Browse files Browse the repository at this point in the history
  • Loading branch information
elizachi committed Nov 19, 2023
1 parent c7ebcb7 commit 130b1ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
39 changes: 31 additions & 8 deletions src/presentation/http/router/userList.test.ts
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
Expand All @@ -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({
Expand All @@ -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([
Expand Down
9 changes: 6 additions & 3 deletions src/tests/test-data/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]

0 comments on commit 130b1ac

Please sign in to comment.