Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions frontend/react-app/src/api/authInfoApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ export const login = async (accountId, password) => {
export const isAdmin = async (teamMemberId) => {
try {
const response = await fetch(`${BASE_URL}/${teamMemberId}/is-admin`, {
method: 'POST',
method: 'GET',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({teamMemberId})
});

if (!response.ok) {
console.error(`Failed to check member role: ${response.status} ${response.statusText}`);
return false;
}

const data = await response.json();
return data.isAdmin === true;
const role = await response.json();
return role;
}
catch (error) {
console.error("Error checking member role: ", error);
Expand Down
18 changes: 8 additions & 10 deletions frontend/react-app/src/tests/api-tests/authInfoApiTest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,29 @@ describe('AuthInfo API', () => {

//test: check if user is an admin
test('isAdmin should return true when user is an admin', async () => {
fetch.mockResponseOnce(JSON.stringify({ isAdmin: true }), { status: 200 });
fetch.mockResponseOnce(JSON.stringify("ADMIN"), { status: 200 });

const response = await isAdmin(1);

expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/1/is-admin`, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ teamMemberId: 1 })
method: 'GET',
headers: { "Content-Type": "application/json" }
});

expect(response).toBe(true);
expect(response).toBe("ADMIN");
});

//test: check if user is not an admin
test('isAdmin should return false when user is not an admin', async () => {
fetch.mockResponseOnce(JSON.stringify({ isAdmin: false }), { status: 200 });
fetch.mockResponseOnce(JSON.stringify("TEAM_MEMBER"), { status: 200 });

const response = await isAdmin(1);

expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/1/is-admin`, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ teamMemberId: 1 })
method: 'GET',
headers: { "Content-Type": "application/json" }
});

expect(response).toBe(false);
expect(response).toBe("TEAM_MEMBER");
});
});