Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Piterson25 committed Mar 25, 2024
1 parent 066d721 commit c8642bf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
7 changes: 4 additions & 3 deletions backend/test/userEndpoints.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from "vitest";
import User from "../src/models/User";

let userId: number;

Expand Down Expand Up @@ -110,10 +111,10 @@ test("Get user's friends", async () => {

const response = await fetch(`http://localhost:5000/users/${zuckId}/friends`);
const responseData = await response.json();
const { status, friends } = responseData;
const { status, users } = responseData;

expect(status).toBe("ok");
expect(friends).toHaveLength(2);
expect(users).toHaveLength(2);
});

async function searchUsers(lastPart: string) {
Expand Down Expand Up @@ -146,7 +147,7 @@ test("Search users", async () => {
expect(usersStatus).toBe("ok");

const zuck = usersResponseData.users.find(
([user, _score]: any) => user.mail == "[email protected]",
(user: User) => user.mail == "[email protected]",
);

expect(zuck).toBeDefined();
Expand Down
10 changes: 5 additions & 5 deletions backend/test/userFriends.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ test("Search user", async () => {

expect(status).toBe("ok");

userId = users[0][0].id;
userId = users[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 users = responseData.users;
const status = responseData.status;

expect(status).toBe("ok");
expect(friends.length).toBe(6);
expect(users.length).toBe(6);
});

test("Missing page", async () => {
Expand Down Expand Up @@ -58,7 +58,7 @@ test("First user", async () => {

const responseData = await response.json();
const status = responseData.status;
const users = responseData.friends;
const users = responseData.users;

expect(status).toBe("ok");
expect(users.length).toBe(1);
Expand All @@ -72,7 +72,7 @@ test("Not found users", async () => {
);
const responseData = await response.json();
const status = responseData.status;
const message = responseData.errors.friends;
const message = responseData.errors.users;

expect(status).toBe("error");
expect(message).toBe("No friends found with given queries");
Expand Down
10 changes: 7 additions & 3 deletions backend/test/userFriendsSuggestions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("Search user", async () => {

expect(status).toBe("ok");

userId = users[0][0].id;
userId = users[0].id;
});

test("Get friend suggestions", async () => {
Expand All @@ -22,11 +22,15 @@ test("Get friend suggestions", async () => {
);

const responseData = await response.json();
const size = responseData.size;
const status = responseData.status;
const allUsersSize = responseData.allUsersSize;
const totalPage = responseData.totalPage;
const usersLength = responseData.users.length;

expect(status).toBe("ok");
expect(size).toBe(15);
expect(allUsersSize).toBe(15);
expect(totalPage).toBe(3);
expect(usersLength).toBe(5);
});

test("Missing page", async () => {
Expand Down
26 changes: 24 additions & 2 deletions backend/test/userSearch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test("Search all users", async () => {
expect(status).toBe("ok");
expect(users.length).toBe(27);

userId = users[0][0].id;
userId = users[0].id;
});

test("Search all users from Poland", async () => {
Expand All @@ -30,6 +30,28 @@ test("Search all users from Poland", async () => {
expect(users.length).toBe(3);
});

test("Missing page", async () => {
const response = await fetch(
`http://localhost:5000/users/search?q=a&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/search?q=a&page=${page}`,
);

const responseData = await response.json();
const status = responseData.status;

expect(status).toBe("error");
});

test("First user from Lithuania", async () => {
const response = await fetch(
`http://localhost:5000/users/search?country=Lithuania&page=${page}&maxUsers=${maxUsers}`,
Expand All @@ -41,7 +63,7 @@ test("First user from Lithuania", async () => {

expect(status).toBe("ok");
expect(users.length).toBe(1);
expect(users[0][0].country).toBe("Lithuania");
expect(users[0].country).toBe("Lithuania");
});

test("Not found user", async () => {
Expand Down

0 comments on commit c8642bf

Please sign in to comment.