mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 07:40:59 +00:00
013aa3954d
The first time an admin opens the settings on an installation that can share, a dialog asks for the whole installation, with every field switched on and a plain list of what never goes along. Nothing is sent before Agree; Not now asks again in 14 days, No keeps the question away until the terms change, and closing it decides nothing. Inside the TREK Places API card, Share place details then holds the switch for the installation and one per field, the figures of the last 30 days, the transmission log and the way to withdraw everything sent. The place form reports for each field whether the user typed it or a provider filled it.
190 lines
5.9 KiB
TypeScript
190 lines
5.9 KiB
TypeScript
import { http, HttpResponse } from 'msw';
|
|
import { buildUser, buildAdmin } from '../../factories';
|
|
|
|
export const adminHandlers = [
|
|
http.get('/api/admin/users', () => {
|
|
const user1 = buildUser({ username: 'alice', email: 'alice@example.com' });
|
|
const admin1 = buildAdmin({ username: 'admin', email: 'admin@example.com' });
|
|
return HttpResponse.json({ users: [admin1, user1] });
|
|
}),
|
|
|
|
http.post('/api/admin/users', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
const user = buildUser({ ...body });
|
|
return HttpResponse.json({ user });
|
|
}),
|
|
|
|
http.put('/api/admin/users/:id', async ({ params, request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
const user = buildUser({ id: Number(params.id), ...body });
|
|
return HttpResponse.json({ user });
|
|
}),
|
|
|
|
http.delete('/api/admin/users/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/admin/stats', () => {
|
|
return HttpResponse.json({
|
|
totalUsers: 2,
|
|
totalTrips: 5,
|
|
totalPlaces: 42,
|
|
totalFiles: 8,
|
|
});
|
|
}),
|
|
|
|
http.get('/api/admin/invites', () => {
|
|
return HttpResponse.json({ invites: [] });
|
|
}),
|
|
|
|
http.post('/api/admin/invites', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ invite: { id: 1, token: 'test-invite-token', ...body } });
|
|
}),
|
|
|
|
http.delete('/api/admin/invites/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/admin/oidc', () => {
|
|
return HttpResponse.json({
|
|
issuer: '',
|
|
client_id: '',
|
|
client_secret: '',
|
|
client_secret_set: false,
|
|
display_name: '',
|
|
oidc_only: false,
|
|
discovery_url: '',
|
|
});
|
|
}),
|
|
|
|
http.put('/api/admin/oidc', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ ...body });
|
|
}),
|
|
|
|
http.get('/api/admin/version-check', () => {
|
|
return HttpResponse.json({ update_available: false, latest: '1.0.0', current: '1.0.0' });
|
|
}),
|
|
|
|
http.get('/api/admin/bag-tracking', () => {
|
|
return HttpResponse.json({ enabled: false });
|
|
}),
|
|
|
|
http.put('/api/admin/bag-tracking', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/tours-wanderer', () => {
|
|
return HttpResponse.json({ enabled: false });
|
|
}),
|
|
|
|
http.put('/api/admin/tours-wanderer', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/tours-hiking-map', () => {
|
|
return HttpResponse.json({ enabled: true });
|
|
}),
|
|
|
|
http.put('/api/admin/tours-hiking-map', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/tours-ski-routing', () => {
|
|
return HttpResponse.json({ enabled: true });
|
|
}),
|
|
|
|
http.put('/api/admin/tours-ski-routing', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ enabled: body.enabled });
|
|
}),
|
|
|
|
http.get('/api/admin/addons', () => {
|
|
return HttpResponse.json({ addons: [] });
|
|
}),
|
|
|
|
http.get('/api/admin/packing-templates', () => {
|
|
return HttpResponse.json({ templates: [] });
|
|
}),
|
|
|
|
http.get('/api/admin/audit-log', () => {
|
|
return HttpResponse.json({ logs: [], total: 0 });
|
|
}),
|
|
|
|
http.get('/api/admin/mcp-tokens', () => {
|
|
return HttpResponse.json({ tokens: [] });
|
|
}),
|
|
|
|
http.get('/api/admin/oauth-sessions', () => {
|
|
return HttpResponse.json({ sessions: [] });
|
|
}),
|
|
|
|
http.delete('/api/admin/oauth-sessions/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.delete('/api/admin/mcp-tokens/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/admin/permissions', () => {
|
|
return HttpResponse.json({ permissions: {} });
|
|
}),
|
|
|
|
http.get('/api/admin/notification-preferences', () => {
|
|
return HttpResponse.json({
|
|
event_types: [],
|
|
available_channels: {},
|
|
implemented_combos: {},
|
|
preferences: {},
|
|
});
|
|
}),
|
|
|
|
// Auth settings endpoints used by AdminPage
|
|
http.get('/api/auth/app-settings', () => {
|
|
return HttpResponse.json({});
|
|
}),
|
|
|
|
http.put('/api/auth/app-settings', async ({ request }) => {
|
|
const body = await request.json() as Record<string, unknown>;
|
|
return HttpResponse.json({ ...body });
|
|
}),
|
|
|
|
http.get('/api/auth/me/settings', () => {
|
|
return HttpResponse.json({ settings: { maps_api_key: '', openweather_api_key: '' } });
|
|
}),
|
|
|
|
http.get('/api/auth/validate-keys', () => {
|
|
return HttpResponse.json({ maps: true, weather: true });
|
|
}),
|
|
|
|
// The TREK API card's allowance panel, read whenever the settings tab renders it.
|
|
http.get('/api/admin/service-identity', () => {
|
|
return HttpResponse.json({ state: 'legacy', tier: 'legacy', keySource: null, services: [], lastSeenAt: null });
|
|
}),
|
|
|
|
// Sharing place details, inside the same card: not eligible, so no prompt opens in other tests.
|
|
http.get('/api/admin/places-contribute', () => {
|
|
const fields = { website: true, phone: true, email: true, opening_hours: true, description: true, image: true };
|
|
return HttpResponse.json({
|
|
termsVersion: 1,
|
|
ceiling: 'admin',
|
|
eligible: false,
|
|
ineligibleReason: 'not_production',
|
|
consent: { enabled: false, fields, termsVersion: null, decision: null, decidedBy: null, decidedAt: null },
|
|
showPrompt: false,
|
|
snoozedUntil: null,
|
|
active: false,
|
|
counts: { accepted: 0, duplicate: 0, rejected: 0, withheld: 0, retracted: 0 },
|
|
lastSuccessDay: null,
|
|
queue: { size: 0, cap: 5000, full: false },
|
|
pauseReason: null,
|
|
registrationOpen: false,
|
|
});
|
|
}),
|
|
];
|