Files
kochwas/tests/e2e/remote/fixtures/api-cleanup.ts
hsiegeln a7ad159c69
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m42s
test(e2e): Playwright Smoketests gegen kochwas-dev (remote)
Automatisierte End-to-End-Tests gegen ein deployed Environment. Loest
die manuellen MCP-Playwright-Runs ab. 42 Tests in 9 Files:

- homepage: H1, Sektionen, Sort-Tabs, Console-Errors
- search: lokaler Treffer, Web-Fallback, Empty-State, Deep-Link
- profile: Switcher, Auswahl-Persistenz, Favoriten-Section, Guard-Dialog
- recipe-detail: Header, Portionen-Scaling (4->6), Favorit-Toggle,
  Rating-Persistenz ueber Reload, Gekocht-Counter, Wunschliste-Toggle
- comments: eigenen erstellen+loeschen via UI, fremder hat kein Delete
- wishlist: Seite, Sort-Tabs, Badge-Sync, requireProfile-Custom-Message
- preview: Guard ohne ?url=, echte URL parst, unparsbare zeigt error-box
- admin: alle 4 Subrouten + /admin redirect
- api-errors: parsePositiveIntParam (4x Invalid id), validateBody (4x
  Invalid body + issues), 404, Sanity /health /profiles /domains

Architektur:
- Separate playwright.remote.config.ts (getrennt von local preview)
- workers: 1 + afterEach API-Cleanup (rating, favorite, wishlist, comments)
- Hardcoded Recipe-ID 66 + Profile 1/2/3 — stabile Dev-DB-Seeds
- E2E_REMOTE_URL ueberschreibt die Ziel-URL

Ausfuehrung: npm run test:e2e:remote

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 12:14:04 +02:00

68 lines
1.7 KiB
TypeScript

import type { APIRequestContext } from '@playwright/test';
// Cleanup-Helfer fuer afterEach-Hooks. Alle sind idempotent — wenn der
// Zustand schon weg ist (z. B. der Test ist zwischen Action und Check
// abgebrochen), fliegt nichts.
export async function clearRating(
api: APIRequestContext,
recipeId: number,
profileId: number
): Promise<void> {
await api.delete(`/api/recipes/${recipeId}/rating`, {
data: { profile_id: profileId }
});
}
export async function clearFavorite(
api: APIRequestContext,
recipeId: number,
profileId: number
): Promise<void> {
await api.delete(`/api/recipes/${recipeId}/favorite`, {
data: { profile_id: profileId }
});
}
export async function removeFromWishlist(
api: APIRequestContext,
recipeId: number,
profileId: number
): Promise<void> {
await api.delete(`/api/wishlist/${recipeId}?profile_id=${profileId}`);
}
export async function deleteComment(
api: APIRequestContext,
recipeId: number,
commentId: number
): Promise<void> {
await api.delete(`/api/recipes/${recipeId}/comments`, {
data: { comment_id: commentId }
});
}
/**
* Safety-Net: loescht alle E2E-Kommentare eines Profils. Gedacht fuer
* afterEach/afterAll, falls ein Test abbricht bevor der eigene Cleanup
* greift. Markiert E2E-Kommentare am Prefix "E2E ".
*/
export async function cleanupE2EComments(
api: APIRequestContext,
recipeId: number,
profileId: number
): Promise<void> {
const res = await api.get(`/api/recipes/${recipeId}/comments`);
if (!res.ok()) return;
const list = (await res.json()) as {
id: number;
profile_id: number;
text: string;
}[];
for (const c of list) {
if (c.profile_id === profileId && c.text.startsWith('E2E ')) {
await deleteComment(api, recipeId, c.id);
}
}
}