22 lines
668 B
TypeScript
22 lines
668 B
TypeScript
|
|
/**
|
||
|
|
* Helper to reset the database before each test.
|
||
|
|
* Calls the /api/test/reset endpoint on the worker's backend.
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { APIRequestContext } from "@playwright/test";
|
||
|
|
import { getBackendUrl } from "./backend-url";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reset the database for the current worker.
|
||
|
|
* Truncates all tables and re-seeds base data.
|
||
|
|
*/
|
||
|
|
export async function resetDatabase(request: APIRequestContext): Promise<void> {
|
||
|
|
const backendUrl = getBackendUrl();
|
||
|
|
const response = await request.post(`${backendUrl}/api/test/reset`);
|
||
|
|
|
||
|
|
if (!response.ok()) {
|
||
|
|
const text = await response.text();
|
||
|
|
throw new Error(`Failed to reset database: ${response.status()} - ${text}`);
|
||
|
|
}
|
||
|
|
}
|