forked from baron/baron-sso
- `adminfront` CSV 템플릿 헤더에 `secondary_emails` 추가 및 예시 반영 - `adminfront` CSV 파서(`csvParser.ts`)에서 `secondary_emails` 추출 로직 보강 - `backend` 에서 `BulkCreateUsers`, `UpdateUser` 실행 시 보조 이메일을 포함한 모든 이메일에 대해 식별자 유효성(ValidateLoginID) 검사 수행 - `domain.ValidateLoginID`의 파라미터를 복수 이메일 처리를 위해 `[]string`으로 변경 - Playwright E2E 테스트 `users_bulk_secondary.spec.ts` 신규 작성 및 테스트 패스 확인
95 lines
3.6 KiB
TypeScript
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,secondary_emails,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.secondary_emails).toContain("sub1@test.com");
|
|
expect(bulkPayload.users[0].metadata.secondary_emails).toContain("sub2@test.com");
|
|
});
|
|
}); |