22 lines
719 B
TypeScript
22 lines
719 B
TypeScript
import { expect, type APIRequestContext, type Page } from '@playwright/test';
|
|
|
|
export async function getAdminToken(
|
|
request: APIRequestContext,
|
|
baseUrl: string,
|
|
username: string,
|
|
password: string,
|
|
) {
|
|
const response = await request.post(`${baseUrl}/api/auth/login`, {
|
|
data: { username, password },
|
|
});
|
|
|
|
expect(response.status(), 'login API should accept the configured admin credentials').toBe(200);
|
|
const body = await response.json();
|
|
expect(body?.token, 'login API should return a token').toBeTruthy();
|
|
return body.token as string;
|
|
}
|
|
|
|
export async function installAdminToken(page: Page, token: string) {
|
|
await page.addInitScript(value => localStorage.setItem('auth_token', value), token);
|
|
}
|