Skip to content

Commit

Permalink
Merge branch 'main' into feat/child-parent-relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
elizachi committed Dec 11, 2023
2 parents 41b55de + 2a18d0d commit 24a898a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
43 changes: 43 additions & 0 deletions src/presentation/http/router/user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { describe, test, expect } from 'vitest';


describe('User API', () => {
describe('GET /user/myself', () => {
test('Returns user with status code 200 if user exists', async () => {
const userId = 1;
const accessToken = global.auth(userId);

const response = await global.api?.fakeRequest({
method: 'GET',
headers: {
authorization: `Bearer ${accessToken}`,
},
url: '/user/myself',
});

expect(response?.statusCode).toBe(200);

const body = response?.json();

expect(body).toStrictEqual({
'id': '1',
'email': '[email protected]',
'name': 'Test user 1',
'photo': '',
});
});

test('Returns response with status 401 when user is not authorized', async () => {
const response = await global.api?.fakeRequest({
method: 'GET',
url: '/user/myself',
});

expect(response?.statusCode).toBe(401);

const body = response?.json();

expect(body.message).toBe('You must be authenticated to access this resource');
});
});
});
8 changes: 5 additions & 3 deletions src/tests/test-data/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
"id": 1,
"email": "[email protected]",
"name": "Test user 1",
"created_at": "2023-10-16T13:49:19.000Z"
"created_at": "2023-10-16T13:49:19.000Z",
"photo": ""
},
{
"id": 2,
"email": "[email protected]",
"name": "Елизавета",
"created_at": "2023-10-22 19:19:40.892+03"
"created_at": "2023-10-22 19:19:40.892+03",
"photo": ""
},
{
"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": ""
}
]

0 comments on commit 24a898a

Please sign in to comment.