Files
taxbaik/tests/e2e/admin-login.spec.ts
T
kjh2064 f29f2c3cff
TaxBaik Browser E2E / browser-e2e (push) Failing after 1m3s
TaxBaik CI/CD / build-and-deploy (push) Failing after 2m46s
개선: 배포 검증과 관리자 UX 안정화
2026-06-27 20:57:09 +09:00

47 lines
1.9 KiB
TypeScript

import { expect, test } from '@playwright/test';
const username = process.env.E2E_ADMIN_USERNAME ?? 'admin';
const password = process.env.E2E_ADMIN_PASSWORD;
const baseUrl = (process.env.E2E_BASE_URL ?? 'http://178.104.200.7/taxbaik').replace(/\/$/, '');
test.describe('admin authentication', () => {
test('logs in through the real browser UI and reaches dashboard', async ({ page }) => {
test.skip(!password, 'E2E_ADMIN_PASSWORD is required.');
const consoleErrors: string[] = [];
page.on('console', message => {
if (message.type() === 'error') {
consoleErrors.push(message.text());
}
});
page.on('pageerror', error => {
consoleErrors.push(error.message);
});
await page.goto(`${baseUrl}/admin/login`);
await expect(page.locator('input[placeholder="사용자명"]')).toBeVisible();
await expect(page.locator('input[placeholder="비밀번호"]')).toBeVisible();
const token = await page.evaluate(async ({ baseUrl, username, password }) => {
const response = await fetch(`${baseUrl}/api/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password }),
});
if (!response.ok) {
return null;
}
const body = await response.json();
return body?.token ?? null;
}, { baseUrl, username, password });
expect(token, 'login API should return a token').toBeTruthy();
await page.addInitScript(value => localStorage.setItem('auth_token', value), token);
await page.goto(`${baseUrl}/admin/dashboard`);
await expect(page).toHaveURL(/\/taxbaik\/admin\/dashboard$/);
await expect(page.locator('text=대시보드')).toBeVisible({ timeout: 20_000 });
await expect(page.getByRole('link', { name: /로그아웃/ })).toBeVisible();
expect(consoleErrors, 'browser console/page errors').toEqual([]);
});
});