PUT /availability/status vervangt POST /availability/admin/status; de poort sluit alleen het lezen van de status vrij

De status is één resource: de publieke GET en de PUT van de beheerder delen het pad; de PUT geeft de bijgewerkte resource terug. De vrijstelling van de poort geldt nu alleen voor GET en HEAD, zodat de PUT als beheerroute gewoon achter de poort blijft. De oude route verdwijnt zonder alias, dus API en admin-app moeten als één release uit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-10 13:39:40 +01:00
co-authored by Claude Sonnet 5.5
parent a3b67b6a36
commit 728fc08db8
16 changed files with 344 additions and 45 deletions
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
@@ -60,6 +60,37 @@ describe('SettingsPage', () => {
expect(maintenanceBtn.className).toContain('bg-primary');
});
it('changes the status with PUT on the status resource (no admin route), sending the chosen status', async () => {
let sent: { method: string; url: string; body: { newStatus: string } } | undefined;
server.use(
http.put(`${API_BASE}/api/v1/Availability/status`, async ({ request }) => {
sent = {
method: request.method,
url: new URL(request.url).pathname,
body: (await request.json()) as { newStatus: string },
};
return HttpResponse.json({
status: 'Maintenance',
checkedAt: new Date().toISOString(),
message: '',
isMasterControlled: false,
});
}),
);
mockAuthenticated();
renderApp('/settings');
await screen.findByTestId('availability-mode-selector', {}, { timeout: 10000 });
await userEvent.click(screen.getByTestId('mode-option-Maintenance'));
await userEvent.click(screen.getByTestId('availability-save-button'));
await vi.waitFor(() => expect(sent).toBeDefined());
expect(sent!.method).toBe('PUT');
expect(sent!.url).toBe('/api/v1/Availability/status');
expect(sent!.url).not.toContain('admin');
expect(sent!.body.newStatus).toBe('Maintenance');
});
it('saves availability and shows success toast', async () => {
mockAuthenticated();
renderApp('/settings');
@@ -72,7 +103,7 @@ describe('SettingsPage', () => {
it('shows error toast when save fails', async () => {
server.use(
http.post(`${API_BASE}/api/v1/Availability/admin/status`, () =>
http.put(`${API_BASE}/api/v1/Availability/status`, () =>
HttpResponse.json({ title: 'Error' }, { status: 500 }),
),
);
@@ -118,7 +149,7 @@ describe('SettingsPage', () => {
it('shows a master-controlled error toast on a 409 conflict from the server', async () => {
server.use(
http.post(`${API_BASE}/api/v1/Availability/admin/status`, () =>
http.put(`${API_BASE}/api/v1/Availability/status`, () =>
HttpResponse.json({ title: 'Conflict' }, { status: 409 }),
),
);