1
0
forked from baron/baron-sso
Files
baron-sso/adminfront/tests/users_bulk_secondary.spec.ts
chan 62b1938c42 refactor: 보조 이메일 키값을 sub_email로 통일 및 수동 폼 추가 (#917)
- `secondary_emails` 대신 `sub_email`을 키값으로 사용하도록 전면 수정
- 관리자 화면의 수동 사용자 생성(Create) 및 수정(Detail) 폼에 `sub_email` 입력 필드 추가
- CSV 템플릿의 컬럼명을 `sub_email`로 변경
- 백엔드의 Kratos Traits 조회 및 배열 추출 로직을 `sub_email` 기준으로 업데이트
- E2E 테스트(`users_bulk.spec.ts`, `users_bulk_secondary.spec.ts`)에서 `sub_email` 검증하도록 수정 및 통과 확인
2026-05-29 11:07:59 +09:00

95 lines
3.6 KiB
TypeScript

import { expect, test } from "@playwright/test";
test.describe("Users Bulk Upload Secondary Emails", () => {
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
window.localStorage.setItem("locale", "ko");
window.localStorage.setItem("admin_session", "fake-token");
(window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })._IS_TEST_MODE = true;
const authData = {
access_token: "fake-token",
token_type: "Bearer",
profile: { sub: "admin-user", name: "Admin", role: "super_admin" },
expires_at: Math.floor(Date.now() / 1000) + 36000,
};
window.localStorage.setItem("oidc.user:http://localhost:5000/oidc:adminfront", JSON.stringify(authData));
});
await page.route("**/api/v1/user/me", async (route) => {
return route.fulfill({
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
headers: { "Access-Control-Allow-Origin": "*" },
});
});
await page.route("**/api/v1/admin/tenants*", async (route) => {
return route.fulfill({
json: { items: [], total: 0, limit: 100, offset: 0 },
headers: { "Access-Control-Allow-Origin": "*" },
});
});
await page.route("**/api/v1/admin/users*", async (route) => {
if(route.request().url().includes("/bulk")) {
return route.continue();
}
return route.fulfill({
json: { items: [], total: 0, limit: 50, offset: 0 },
headers: { "Access-Control-Allow-Origin": "*" },
});
});
await page.route("**/oidc/**", async (route) => {
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
});
});
test("should parse secondary_emails and send to backend", async ({ page }) => {
let bulkPayload: any = null;
await page.route("**/api/v1/admin/users/bulk", async (route) => {
if (route.request().method() === "POST") {
bulkPayload = route.request().postDataJSON();
return route.fulfill({
json: { results: [{ email: "test@example.com", success: true, userId: "u-1" }] },
headers: { "Access-Control-Allow-Origin": "*" },
});
}
return route.continue();
});
await page.goto("/users");
await expect(page.getByTestId("page-title")).toContainText(/사용자|Users/i, { timeout: 20000 });
await page.getByTestId("user-data-mgmt-btn").click();
await page.getByRole("menuitem", { name: /일괄 임포트|일괄 등록|Bulk Import/i }).click();
// Create a mock CSV with secondary_emails
const csvContent = `email,sub_email,name,phone,role,tenant_slug\ntest@example.com,sub1@test.com;sub2@test.com,홍길동,010-1234-5678,user,tenant-slug`;
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByText(/파일 선택|Change file|Select file/i).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles({
name: 'users_with_secondary.csv',
mimeType: 'text/csv',
buffer: Buffer.from(csvContent),
});
await expect(page.getByText(/파싱 중/)).not.toBeVisible();
await expect(page.getByTestId("bulk-start-btn")).toBeEnabled();
await page.getByTestId("bulk-start-btn").click();
await expect(page.getByText(/성공|Success/i)).toBeVisible();
expect(bulkPayload).not.toBeNull();
expect(bulkPayload.users).toHaveLength(1);
// The most important check - does it parse to the metadata
expect(bulkPayload.users[0].metadata.sub_email).toContain("sub1@test.com");
expect(bulkPayload.users[0].metadata.sub_email).toContain("sub2@test.com");
});
});