수정: 관리자 e2e 인증 흐름 안정화
This commit is contained in:
@@ -22,22 +22,10 @@ test.describe('admin authentication', () => {
|
||||
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.locator('input[placeholder="사용자명"]').fill(username);
|
||||
await page.locator('input[placeholder="비밀번호"]').fill(password);
|
||||
await page.getByRole('button', { name: '로그인' }).click();
|
||||
|
||||
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();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { getAdminToken, installAdminToken } from './helpers/admin-auth';
|
||||
|
||||
const username = process.env.E2E_ADMIN_USERNAME ?? 'admin';
|
||||
const currentPassword = process.env.E2E_ADMIN_CURRENT_PASSWORD;
|
||||
@@ -6,24 +7,11 @@ const newPassword = process.env.E2E_ADMIN_NEW_PASSWORD;
|
||||
const baseUrl = (process.env.E2E_BASE_URL ?? 'http://178.104.200.7/taxbaik').replace(/\/$/, '');
|
||||
|
||||
test.describe('admin password change', () => {
|
||||
test('changes password through the real admin UI', async ({ page }) => {
|
||||
test('changes password through the real admin UI', async ({ page, request }) => {
|
||||
test.skip(!currentPassword || !newPassword, 'E2E_ADMIN_CURRENT_PASSWORD and E2E_ADMIN_NEW_PASSWORD are required.');
|
||||
|
||||
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: currentPassword });
|
||||
expect(token, 'login API should return a token').toBeTruthy();
|
||||
|
||||
await page.addInitScript(value => localStorage.setItem('auth_token', value), token);
|
||||
const token = await getAdminToken(request, baseUrl, username, currentPassword);
|
||||
await installAdminToken(page, token);
|
||||
await page.goto(`${baseUrl}/admin/settings`);
|
||||
await expect(page.getByRole('heading', { name: /사이트 설정|설정/ })).toBeVisible();
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { getAdminToken, installAdminToken } from './helpers/admin-auth';
|
||||
|
||||
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 smoke', () => {
|
||||
test('navigates the main admin menus without circuit errors', async ({ page }) => {
|
||||
test('navigates the main admin menus without circuit errors', async ({ page, request }) => {
|
||||
test.skip(!password, 'E2E_ADMIN_PASSWORD is required.');
|
||||
|
||||
const consoleErrors: string[] = [];
|
||||
@@ -18,21 +19,8 @@ test.describe('admin smoke', () => {
|
||||
consoleErrors.push(error.message);
|
||||
});
|
||||
|
||||
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);
|
||||
const token = await getAdminToken(request, baseUrl, username, password);
|
||||
await installAdminToken(page, token);
|
||||
|
||||
const menuChecks = [
|
||||
{ path: '/admin/dashboard', heading: /대시보드/ },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { getAdminToken, installAdminToken } from './helpers/admin-auth';
|
||||
|
||||
const username = process.env.E2E_ADMIN_USERNAME ?? 'admin';
|
||||
const password = process.env.E2E_ADMIN_PASSWORD;
|
||||
@@ -27,21 +28,8 @@ test.describe('contact submit', () => {
|
||||
|
||||
test.skip(!password, 'E2E_ADMIN_PASSWORD is required to verify the admin list.');
|
||||
|
||||
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);
|
||||
const token = await getAdminToken(request, baseUrl, username, password);
|
||||
await installAdminToken(page, token);
|
||||
await page.goto(`${baseUrl}/admin/inquiries`);
|
||||
await expect(page.getByText(name)).toBeVisible({ timeout: 20_000 });
|
||||
await expect(page.getByText(phone)).toBeVisible();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { getAdminToken, installAdminToken } from './helpers/admin-auth';
|
||||
|
||||
const username = process.env.E2E_ADMIN_USERNAME ?? 'admin';
|
||||
const password = process.env.E2E_ADMIN_PASSWORD;
|
||||
@@ -27,21 +28,8 @@ test.describe('inquiry detail', () => {
|
||||
|
||||
test.skip(!password, 'E2E_ADMIN_PASSWORD is required to verify inquiry detail.');
|
||||
|
||||
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);
|
||||
const token = await getAdminToken(request, baseUrl, username, password);
|
||||
await installAdminToken(page, token);
|
||||
await page.goto(`${baseUrl}/admin/inquiries`);
|
||||
const row = page.getByRole('row').filter({ hasText: name }).first();
|
||||
await expect(row).toBeVisible({ timeout: 20_000 });
|
||||
|
||||
Reference in New Issue
Block a user