Files
taxbaik/tests/e2e/helpers/admin-auth.ts
T
kjh2064 661ffbbf2c
TaxBaik CI/CD / build-and-deploy (push) Successful in 1m10s
TaxBaik Browser E2E / browser-e2e (push) Failing after 1m37s
test: blazor 내부 이동으로 관리자 e2e 안정화
2026-06-27 21:34:19 +09:00

73 lines
2.3 KiB
TypeScript

import { expect, type APIRequestContext, type Page } from '@playwright/test';
export type InquiryListItem = {
id: number;
name: string;
phone: string;
message: string;
};
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);
}
export async function loginThroughAdminUi(
page: Page,
baseUrl: string,
username: string,
password: string,
) {
await page.goto(`${baseUrl}/admin/login`);
await page.locator('input[placeholder="사용자명"]').fill(username);
await page.locator('input[placeholder="비밀번호"]').fill(password);
await page.getByRole('button', { name: '로그인' }).click();
await expect(page).toHaveURL(/\/taxbaik\/admin\/dashboard$/);
await expect(page.getByRole('heading', { name: '대시보드' })).toBeVisible({ timeout: 20_000 });
}
export async function navigateInBlazor(page: Page, targetUrl: string) {
await page.evaluate(url => {
const blazor = (window as typeof window & { Blazor?: { navigateTo: (target: string) => void } }).Blazor;
if (blazor) {
blazor.navigateTo(url);
return;
}
window.location.href = url;
}, targetUrl);
}
export async function findInquiryByName(
request: APIRequestContext,
baseUrl: string,
token: string,
name: string,
) {
const response = await request.get(`${baseUrl}/api/inquiry?page=1&pageSize=100`, {
headers: { Authorization: `Bearer ${token}` },
});
expect(response.status(), 'admin inquiry list API should be accessible with the token').toBe(200);
const body = await response.json();
const items = (body?.data ?? []) as InquiryListItem[];
const inquiry = items.find(item => item.name === name);
expect(inquiry, `created inquiry ${name} should appear in the admin inquiry API`).toBeTruthy();
return inquiry!;
}