-
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.
Merge branch 'main' into feat/child-parent-relationship
- Loading branch information
Showing
2 changed files
with
48 additions
and
3 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 |
---|---|---|
@@ -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'); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -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": "" | ||
} | ||
] |