68 lines
1.7 KiB
TypeScript
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|