mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 15:59:35 +01:00
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import type { APIRequestContext, APIResponse } from '@playwright/test';
|
|
|
|
/**
|
|
* Typisierter API-Wrapper für Playwright-Tests.
|
|
* Ergänzt den raw request-Context um Auth-Header und JSON-Defaults.
|
|
*/
|
|
export class ApiClient {
|
|
constructor(
|
|
private readonly request: APIRequestContext,
|
|
private readonly token: string,
|
|
) {}
|
|
|
|
private get authHeaders() {
|
|
return { Authorization: `Bearer ${this.token}` };
|
|
}
|
|
|
|
async get(path: string): Promise<APIResponse> {
|
|
return this.request.get(path, { headers: this.authHeaders });
|
|
}
|
|
|
|
async post(path: string, body: unknown): Promise<APIResponse> {
|
|
return this.request.post(path, {
|
|
data: body,
|
|
headers: this.authHeaders,
|
|
});
|
|
}
|
|
|
|
async put(path: string, body: unknown): Promise<APIResponse> {
|
|
return this.request.put(path, {
|
|
data: body,
|
|
headers: this.authHeaders,
|
|
});
|
|
}
|
|
|
|
async patch(path: string, body: unknown): Promise<APIResponse> {
|
|
return this.request.patch(path, {
|
|
data: body,
|
|
headers: this.authHeaders,
|
|
});
|
|
}
|
|
|
|
async delete(path: string): Promise<APIResponse> {
|
|
return this.request.delete(path, { headers: this.authHeaders });
|
|
}
|
|
}
|