- Modul status (Migration 044): Störungen und Wartungen mit Zustand, Auswirkung, Bereich, Zeitraum und Meldungsverlauf. Öffentlich (/v1/public/status, Seite /status) nur, was das Personal veröffentlicht – nur dessen Texte, keine Kunden-/Ressourcen-/Anbieterdaten, nicht aus den internen Betriebsalarmen gespeist. Gesamtzustand aus aktiven Einträgen; angekündigte Wartungen zählen erst ab Beginn. - Verwaltung /admin/status (Support/Admin/Superadmin; Buchhaltung und Kunden nicht), Navigation. - Tests: API (Rechte, Veröffentlichung, Zustände, Abschluss, Felder) und Browser (Status- und Registrierungsseite barrierefrei, 12/12 grün). Passkeys und Berichte bleiben eigene offene Teilaufgaben. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
3 KiB
TypeScript
34 lines
3 KiB
TypeScript
import { beforeAll, describe, expect, it } from 'vitest';
|
|
import type { FastifyInstance } from 'fastify';
|
|
import { buildApp } from '../src/server.js';
|
|
import { call, code, login, makeUser } from './helpers.js';
|
|
|
|
let app: FastifyInstance;
|
|
beforeAll(async () => { app = await buildApp(); await app.ready(); });
|
|
const pub = async () => (await app.inject({ method: 'GET', url: '/v1/public/status' })).json();
|
|
async function staff(email: string, role: string) {
|
|
await makeUser({ email, kind: 'staff', staffRole: role }); const { client } = await login(app, email);
|
|
const s = (await call(app, client, 'POST', '/auth/mfa/setup')).json(); await call(app, client, 'POST', '/auth/mfa/confirm', { code: code(s.secret) }); return client;
|
|
}
|
|
|
|
describe('Öffentliche Statusseite (#23)', () => {
|
|
it('nur Veröffentlichtes ist öffentlich, ohne interne Felder; Gesamtzustand und Abschluss', async () => {
|
|
const sup = await staff('status-support@example.com', 'support'); const acc = await staff('status-buha@example.com', 'accounting');
|
|
await makeUser({ email: 'status-kunde@example.com' }); const cust = (await login(app, 'status-kunde@example.com')).client;
|
|
expect((await pub()).overall).toBe('ok');
|
|
expect((await call(app, cust, 'POST', '/admin/status-events', { kind: 'incident', title: 'X', body: 'xxx' })).statusCode).toBe(403);
|
|
expect((await call(app, acc, 'POST', '/admin/status-events', { kind: 'incident', title: 'X', body: 'xxx' })).statusCode).toBe(403);
|
|
const ev = (await call(app, sup, 'POST', '/admin/status-events', { kind: 'incident', title: 'E-Mail verzögert', component: 'E-Mail', impact: 'major', body: 'Wir untersuchen das.' })).json();
|
|
expect((await pub()).current).toHaveLength(0); // nicht veröffentlicht
|
|
await call(app, sup, 'POST', `/admin/status-events/${ev.id}/update`, { published: true, state: 'identified', body: 'Ursache gefunden.' });
|
|
let p = await pub(); expect(p.overall).toBe('major'); expect(p.current[0].title).toBe('E-Mail verzögert');
|
|
expect(p.current[0].updates.map((u: any) => u.state)).toEqual(['identified', 'investigating']);
|
|
const keys = Object.keys(p.current[0]); for (const k of ['published', 'created_by', 'createdBy']) expect(keys).not.toContain(k);
|
|
expect((await call(app, sup, 'POST', `/admin/status-events/${ev.id}/update`, { state: 'completed' })).statusCode).toBe(400); // passt nicht zu Störung
|
|
await call(app, sup, 'POST', `/admin/status-events/${ev.id}/update`, { state: 'resolved', body: 'Behoben.' });
|
|
p = await pub(); expect(p.overall).toBe('ok'); expect(p.recent[0].state).toBe('resolved'); expect(p.recent[0].endsAt).toBeTruthy();
|
|
// geplante Wartung in der Zukunft: angekündigt, beeinflusst den Gesamtzustand noch nicht
|
|
await call(app, sup, 'POST', '/admin/status-events', { kind: 'maintenance', title: 'Wartung Webserver', impact: 'minor', startsAt: new Date(Date.now() + 86400000).toISOString(), body: 'Kurze Unterbrechung möglich.', published: true });
|
|
p = await pub(); expect(p.overall).toBe('ok'); expect(p.current.map((e: any) => e.kind)).toContain('maintenance');
|
|
});
|
|
});
|