51 lines
1.9 KiB
TypeScript
51 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('contact submit', () => {
|
|
test('creates an inquiry and shows it in admin list', async ({ page, request }) => {
|
|
const stamp = Date.now();
|
|
const name = `E2E-${stamp}`;
|
|
const phone = '010-1234-5678';
|
|
const email = `e2e-${stamp}@example.com`;
|
|
const message = 'Playwright로 전송한 공개 문의 테스트입니다.';
|
|
|
|
const createResponse = await request.post(`${baseUrl}/api/inquiry`, {
|
|
data: {
|
|
name,
|
|
phone,
|
|
email,
|
|
serviceType: '기타',
|
|
message,
|
|
},
|
|
});
|
|
expect(createResponse.ok()).toBeTruthy();
|
|
const createBody = await createResponse.json();
|
|
expect(createBody.message).toContain('상담 신청이 접수되었습니다');
|
|
|
|
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);
|
|
await page.goto(`${baseUrl}/admin/inquiries`);
|
|
await expect(page.getByText(name)).toBeVisible({ timeout: 20_000 });
|
|
await expect(page.getByText(phone)).toBeVisible();
|
|
await expect(page.getByText(message.slice(0, 20))).toBeVisible();
|
|
});
|
|
});
|