-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pagination and tests to friends endpoint
- Loading branch information
1 parent
0cd5393
commit d21f343
Showing
3 changed files
with
117 additions
and
32 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
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,79 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
let userId: number; | ||
let page: number = 3; | ||
let maxUsers: number = 5; | ||
|
||
test("Search user", async () => { | ||
const response = await fetch("http://localhost:5000/users/search?q=a"); | ||
|
||
const responseData = await response.json(); | ||
const users = responseData.users; | ||
const status = responseData.status; | ||
|
||
expect(status).toBe("ok"); | ||
|
||
userId = users[0][0].id; | ||
}); | ||
|
||
test("Get friends", async () => { | ||
const response = await fetch(`http://localhost:5000/users/${userId}/friends`); | ||
|
||
const responseData = await response.json(); | ||
const friends = responseData.friends; | ||
const status = responseData.status; | ||
|
||
expect(status).toBe("ok"); | ||
expect(friends.length).toBe(6); | ||
}); | ||
|
||
test("Missing page", async () => { | ||
const response = await fetch( | ||
`http://localhost:5000/users/${userId}/friends?maxUsers=${maxUsers}`, | ||
); | ||
|
||
const responseData = await response.json(); | ||
const status = responseData.status; | ||
|
||
expect(status).toBe("error"); | ||
}); | ||
|
||
test("Missing maxUsers", async () => { | ||
const response = await fetch( | ||
`http://localhost:5000/users/${userId}/friends?page=${page}`, | ||
); | ||
|
||
const responseData = await response.json(); | ||
const status = responseData.status; | ||
|
||
expect(status).toBe("error"); | ||
}); | ||
|
||
test("First user", async () => { | ||
page = 1; | ||
maxUsers = 1; | ||
const response = await fetch( | ||
`http://localhost:5000/users/${userId}/friends?page=${page}&maxUsers=${maxUsers}`, | ||
); | ||
|
||
const responseData = await response.json(); | ||
const status = responseData.status; | ||
const users = responseData.friends; | ||
|
||
expect(status).toBe("ok"); | ||
expect(users.length).toBe(1); | ||
}); | ||
|
||
test("Not found users", async () => { | ||
page = 3; | ||
maxUsers = 3; | ||
const response = await fetch( | ||
`http://localhost:5000/users/${userId}/friends?page=${page}&maxUsers=${maxUsers}`, | ||
); | ||
const responseData = await response.json(); | ||
const status = responseData.status; | ||
const message = responseData.errors.friends; | ||
|
||
expect(status).toBe("error"); | ||
expect(message).toBe("No friends found with given queries"); | ||
}); |