Browser-Abnahme: Ticket- und Rechnungsablauf (#119)
Some checks failed
CI / test (push) Has been cancelled
CI / e2e (push) Has been cancelled

- Setup legt feste Ausgangsdaten an (Firmendaten, Testkunde, Rechnungs-
  entwurf) in der Wegwerf-DB kundencenter_e2e.
- Ticket: Kunde eröffnet über die Oberfläche, Personal antwortet, Kunde
  sieht die Antwort (Desktop + 360 px, axe).
- Rechnung: Entwurf für Kunden unsichtbar (404), Personal stellt aus,
  Kunde sieht Nummer und lädt das PDF (axe auf beiden Seiten).
Ergebnis: 15 passed, 1 bewusst übersprungen (Ausstellen nur einmal).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude (KI) 2026-10-06 16:06:41 +02:00
parent bcf188df34
commit f475e8bd36
2 changed files with 51 additions and 0 deletions

View file

@ -28,7 +28,17 @@ async function setup() {
const id = randomUUID();
await c.query("INSERT INTO users (id, email, name, password_hash, kind, staff_role, status, email_verified_at) VALUES (?,?,?,?, 'staff', 'superadmin', 'active', UTC_TIMESTAMP(3))", [id, 'admin@e2e.example', 'E2E Admin', await hash('e2e-passwort-admin-123')]);
await c.query('INSERT INTO mfa_totp (user_id, secret_enc, confirmed_at) VALUES (?,?,UTC_TIMESTAMP(3))', [id, encrypt(secret)]);
// Feste Ausgangsdaten für Ticket- und Rechnungsablauf (#119): vollständige Firmendaten, Testkunde mit Inhaber, Rechnungsentwurf
await c.query("UPDATE company_settings SET name='E2E Firma GmbH', street='Teststr. 1', zip='12345', city='Teststadt', tax_number='12/345/67890' WHERE id=1");
const org = randomUUID(); const owner = randomUUID(); const draft = randomUUID();
await c.query("INSERT INTO organizations (id, customer_number, name, customer_type) VALUES (?, 'K-E2E1', 'E2E Ablauf GmbH', 'business')", [org]);
await c.query("INSERT INTO billing_profiles (org_id, company, country, billing_email) VALUES (?, 'E2E Ablauf GmbH', 'DE', 'ablauf@e2e.example')", [org]);
await c.query("INSERT INTO users (id, email, name, password_hash, kind, status) VALUES (?, 'ablauf@e2e.example', 'Ablauf Kunde', ?, 'customer', 'active')", [owner, await hash('e2e-passwort-kunde-1')]);
await c.query("INSERT INTO memberships (org_id, user_id, role) VALUES (?,?,'owner')", [org, owner]);
await c.query("INSERT INTO invoices (id, org_id, status, total_net_cents, total_tax_cents, total_gross_cents, created_by) VALUES (?, ?, 'draft', 1000, 190, 1190, ?)", [draft, org, id]);
await c.query("INSERT INTO invoice_items (id, invoice_id, description, quantity, unit_price_net_cents, tax_bp, net_cents, tax_cents, gross_cents, sort_order) VALUES (?, ?, 'E2E Webhosting', 1, 1000, 1900, 1000, 190, 1190, 0)", [randomUUID(), draft]);
await c.end();
writeFileSync('/tmp/kc-e2e-data.json', JSON.stringify({ draftInvoiceId: draft, customerEmail: 'ablauf@e2e.example', customerPassword: 'e2e-passwort-kunde-1' }));
rmSync('/tmp/kc-e2e-totp-step', { force: true });
writeFileSync('/tmp/kc-e2e-admin.json', JSON.stringify({ email: 'admin@e2e.example', password: 'e2e-passwort-admin-123', secret }));
}

View file

@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test';
import { readFileSync } from 'node:fs';
import { admin, expectAccessible, loginStaff, logout, totp } from './helpers';
test.describe.configure({ mode: 'serial' });
@ -101,3 +102,43 @@ test('Registrierungsseite: bei ausgeschalteter Registrierung nur Hinweis, barrie
await expectAccessible(page, 'Registrierung');
});
const data = () => JSON.parse(readFileSync('/tmp/kc-e2e-data.json', 'utf8')) as { draftInvoiceId: string; customerEmail: string; customerPassword: string };
async function loginCustomer(page: import('@playwright/test').Page) {
const d = data(); await page.goto('/login');
await page.getByLabel('E-Mail').fill(d.customerEmail); await page.getByLabel('Passwort').fill(d.customerPassword);
await page.getByRole('button', { name: 'Anmelden' }).click(); await expect(page).toHaveURL(/\/dashboard/);
}
test('Ticket: Kunde eröffnet, Personal antwortet, Kunde sieht die Antwort (#119)', async ({ page, browser }, info) => {
const subject = `Frage zum Hosting ${info.project.name}`;
const ctx = await browser.newContext({ colorScheme: info.project.use.colorScheme, viewport: info.project.use.viewport }); const cp = await ctx.newPage();
await loginCustomer(cp);
await cp.goto('/tickets'); await cp.getByRole('button', { name: 'Neues Ticket' }).click();
await cp.getByLabel('Betreff').fill(subject); await cp.getByLabel('Anliegen').fill('Wie richte ich mein Postfach ein?');
await cp.getByRole('button', { name: 'Absenden' }).click();
await expect(cp).toHaveURL(/\/tickets\/[0-9a-f-]{36}/); const ticketUrl = new URL(cp.url()).pathname;
await expectAccessible(cp, 'Ticket (Kunde)');
await loginStaff(page); await page.goto(ticketUrl);
await expect(page.getByText('Wie richte ich mein Postfach ein?')).toBeVisible();
await page.getByLabel('Antwort').fill('So geht es: Einstellungen öffnen …'); await page.getByRole('button', { name: 'Absenden' }).click();
await expect(page.getByText('So geht es: Einstellungen öffnen …')).toBeVisible();
await cp.reload(); await expect(cp.getByText('So geht es: Einstellungen öffnen …')).toBeVisible();
await ctx.close();
});
test('Rechnung: Personal stellt aus, Kunde sieht sie mit PDF; Entwurf war für den Kunden unsichtbar (#119)', async ({ page, browser }, info) => {
test.skip(info.project.name !== 'desktop-hell', 'Ausstellen ist einmalig – Ablauf läuft nur im Desktop-Projekt');
const d = data();
const ctx = await browser.newContext(); const cp = await ctx.newPage(); await loginCustomer(cp);
expect((await cp.request.get(`/api/invoices/${d.draftInvoiceId}`)).status()).toBe(404); // Entwurf unsichtbar
await loginStaff(page); await page.goto(`/rechnungen/${d.draftInvoiceId}`);
await page.getByRole('button', { name: 'Ausstellen' }).click();
await expect(page.getByText('Ausgestellt.')).toBeVisible();
await expectAccessible(page, 'Rechnung (Personal)');
await cp.goto('/rechnungen'); await expect(cp.getByText(/RE-\d+/).first()).toBeVisible();
await cp.goto(`/rechnungen/${d.draftInvoiceId}`); await expect(cp.getByRole('link', { name: 'PDF ansehen' })).toBeVisible();
const pdf = await cp.request.get(`/api/invoices/${d.draftInvoiceId}/pdf`); expect(pdf.status()).toBe(200); expect((await pdf.body()).subarray(0, 4).toString()).toBe('%PDF');
await expectAccessible(cp, 'Rechnung (Kunde)');
await ctx.close();
});