Skip to content

Commit

Permalink
Fix first user may be random
Browse files Browse the repository at this point in the history
  • Loading branch information
Piterson25 committed May 14, 2024
1 parent 32346ef commit 2aada44
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
9 changes: 7 additions & 2 deletions backend/test/chat.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { expect, test } from "vitest";
import { fetchData } from "../src/misc/fetchData.js";
import User from "../src/models/User.js";

let userId1: string = "";
let userId2: string = "";

const getUsers = async () => {
const response = await fetchData(`http://localhost:5000/users`, "GET", {});
userId1 = response.users[0].id;
userId2 = response.users[1].id;
userId1 = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
userId2 = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
};

await getUsers();
Expand Down
8 changes: 6 additions & 2 deletions backend/test/userFriendRequests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ let userId2: string = "";

const getUsers = async () => {
const response = await fetchData(`http://localhost:5000/users`, "GET", {});
userId = response.users[0].id;
userId2 = response.users[1].id;
userId = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
userId2 = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
};

await getUsers();
Expand Down
11 changes: 7 additions & 4 deletions backend/test/userFriendSuggestions.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { expect, test } from "vitest";
import { fetchData } from "../src/misc/fetchData.js";
import User from "../src/models/User.js";

let userId: number;
let page: number = 3;
let maxUsers: number = 5;

const getFirstUser = async () => {
const response = await fetchData(`http://localhost:5000/users`, "GET", {});
userId = response.users[0].id;
userId = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
};

await getFirstUser();
Expand All @@ -22,9 +25,9 @@ test("Get friend suggestions", async () => {
const { status, pageCount, friendSuggestions } = response;

expect(status).toBe("ok");
expect(pageCount).toBe(4);
expect(pageCount).toBe(3);
expect(friendSuggestions).toBeDefined();
expect(friendSuggestions.length).toBe(5);
expect(friendSuggestions.length).toBe(3);
});

test("Get friend suggestions with incorrect ID", async () => {
Expand Down Expand Up @@ -108,7 +111,7 @@ test("First user", async () => {
const { status, pageCount, friendSuggestions } = response;

expect(status).toBe("ok");
expect(pageCount).toBe(17);
expect(pageCount).toBe(13);
expect(friendSuggestions).toBeDefined();
expect(friendSuggestions.length).toBe(1);
});
Expand Down
17 changes: 10 additions & 7 deletions backend/test/userFriends.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { expect, test } from "vitest";
import { fetchData } from "../src/misc/fetchData.js";
import User from "../src/models/User.js";

let page: number = 1;
let maxUsers: number = 10;
let userId: string = "";

const getFirstUser = async () => {
const response = await fetchData(`http://localhost:5000/users`, "GET", {});
userId = response.users[0].id;
userId = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
};

await getFirstUser();
Expand All @@ -23,7 +26,7 @@ test("Get friends", async () => {

expect(status).toBe("ok");
expect(pageCount).toBe(1);
expect(friends.length).toBe(6);
expect(friends.length).toBe(9);
});

test("Get friends with incorrect ID", async () => {
Expand Down Expand Up @@ -118,12 +121,12 @@ test("First user", async () => {
const { status, pageCount, friends } = response;

expect(status).toBe("ok");
expect(pageCount).toBe(6);
expect(pageCount).toBe(9);
expect(friends.length).toBe(1);
expect(friends[0].country).toBe("PL");
expect(friends[0].mail).toBe("[email protected]");
expect(friends[0].first_name).toBe("Abby");
expect(friends[0].last_name).toBe("Godney");
expect(friends[0].country).toBe("CN");
expect(friends[0].mail).toBe("[email protected]");
expect(friends[0].first_name).toBe("Trever");
expect(friends[0].last_name).toBe("Shillito");
});

test("maxUsers equals 0", async () => {
Expand Down
5 changes: 4 additions & 1 deletion backend/test/userMeetings.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { expect, test } from "vitest";
import { fetchData } from "../src/misc/fetchData.js";
import User from "../src/models/User.js";

let userId: string = "";

const getFirstUser = async () => {
const response = await fetchData(`http://localhost:5000/users`, "GET", {});
userId = response.users[0].id;
userId = response.users.find(
(user: User) => user.mail === "[email protected]",
).id;
};

await getFirstUser();
Expand Down

0 comments on commit 2aada44

Please sign in to comment.