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
9 changes: 5 additions & 4 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const server = setupServer(
http.post(`${API_HOST}/api/admins`, () =>
HttpResponse.json({ status: 'success', message: 'ok', password: 'generated-pass' })
),
http.delete(`${API_HOST}/api/admins/:username`, () => HttpResponse.json({ success: true })),
http.delete(`${API_HOST}/api/admins`, () => HttpResponse.json({ success: true })),
http.post(`${API_HOST}/api/auth/otp/verify`, () => HttpResponse.json({ token: 'otp-token' })),
http.post(`${API_HOST}/api/auth/otp/validate`, () => HttpResponse.json({ token: 'otp-token' }))
);
Expand Down Expand Up @@ -299,8 +299,9 @@ describe('admins page', () => {
admins: [{ username: 'carol', createdAt: '2026-01-25T08:02:05.614Z' }],
})
),
http.delete(`${API_HOST}/api/admins/:username`, ({ params }) => {
deleted = params.username as string;
http.delete(`${API_HOST}/api/admins`, async ({ request }) => {
const body = (await request.json()) as { username: string };
deleted = body.username;
return HttpResponse.json({ success: true });
})
);
Expand All @@ -323,7 +324,7 @@ describe('admins page', () => {
admins: [{ username: 'carol', createdAt: '2026-01-25T08:02:05.614Z' }],
})
),
http.delete(`${API_HOST}/api/admins/:username`, () => {
http.delete(`${API_HOST}/api/admins`, () => {
deleteCalled = true;
return HttpResponse.json({ success: true });
})
Expand Down
11 changes: 7 additions & 4 deletions src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const handlers = [
});
}),

http.delete('https://frontend.myapp.local/api/admins/:username', () => {
http.delete('https://frontend.myapp.local/api/admins', () => {
return HttpResponse.json({ success: true });
}),
];
Expand Down Expand Up @@ -142,17 +142,20 @@ describe('apiService', () => {
expect(response.data.password).toBe('pw-for-newadmin');
});

it('removeAdmin should target the username in the URL', async () => {
it('removeAdmin should send the username in the request body', async () => {
let requestedUrl = '';
let requestedBody: { username?: string } = {};
server.use(
http.delete('https://frontend.myapp.local/api/admins/:username', ({ request }) => {
http.delete('https://frontend.myapp.local/api/admins', async ({ request }) => {
requestedUrl = request.url;
requestedBody = (await request.json()) as { username?: string };
return HttpResponse.json({ success: true });
})
);
const response = await apiService.removeAdmin('gone');
expect(response.data).toEqual({ success: true });
expect(requestedUrl).toContain('/api/admins/gone');
expect(requestedUrl).toBe('https://frontend.myapp.local/api/admins');
expect(requestedBody).toEqual({ username: 'gone' });
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const apiService = {
api.post<AddAdminResponse>('/api/admins', { username }),

removeAdmin: (username: string): Promise<AxiosResponse<{ success: boolean }>> =>
api.delete(`/api/admins/${username}`),
api.delete('/api/admins', { data: { username } }),
};

export const mockApiService = {
Expand Down
Loading