From e8d76e5e9577d557c0bd1238bd88e3313b92cb23 Mon Sep 17 00:00:00 2001 From: chan Date: Fri, 29 May 2026 18:34:10 +0900 Subject: [PATCH] test(adminfront): fix csv parser vitest failure and optimize audit spec for CI --- .../src/features/users/utils/csvParser.ts | 2 +- adminfront/tests/audit.spec.ts | 75 +++++++------------ 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/adminfront/src/features/users/utils/csvParser.ts b/adminfront/src/features/users/utils/csvParser.ts index a6ab2f1c..16673a65 100644 --- a/adminfront/src/features/users/utils/csvParser.ts +++ b/adminfront/src/features/users/utils/csvParser.ts @@ -358,7 +358,7 @@ function applySecondaryEmailMetadata( ...metadataEmailList(item.metadata.secondary_emails), ...emails, ]); - item.metadata.sub_email = value; + item.metadata.sub_email = emails; item.metadata.secondary_emails = uniqueSecondaryEmails; addWorksmobileAliasEmails(item, emails); } diff --git a/adminfront/tests/audit.spec.ts b/adminfront/tests/audit.spec.ts index e4aa351f..e2c8ad21 100644 --- a/adminfront/tests/audit.spec.ts +++ b/adminfront/tests/audit.spec.ts @@ -44,11 +44,12 @@ test.describe("Audit Logs Management", () => { await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } }); }); - await page.route(/.*\/api\/v1\/audit.*/, async (route) => { + await page.route("**/v1/audit*", async (route) => { const url = route.request().url(); const urlObj = new URL(url); const cursor = urlObj.searchParams.get("cursor"); const offset = cursor ? 20 : 0; + console.log(`[mock] Audit logs request: ${url} (offset: ${offset})`); return route.fulfill({ json: { items: generateMockLogs(20, offset), @@ -59,7 +60,7 @@ test.describe("Audit Logs Management", () => { }); }); - await page.route(/.*\/api\/v1\/user\/me/, async (route) => { + await page.route("**/user/me", async (route) => { return route.fulfill({ json: { id: "admin-user", @@ -70,9 +71,9 @@ test.describe("Audit Logs Management", () => { headers: { "Access-Control-Allow-Origin": "*" }, }); }); - }); + }); - const generateMockLogs = (count: number, offset = 0) => { + const generateMockLogs = (count: number, offset = 0) => { return Array.from({ length: count }, (_, i) => { const id = offset + i; return { @@ -90,41 +91,30 @@ test.describe("Audit Logs Management", () => { }), }; }); - }; + }; - test("should load initial logs and display correctly", async ({ page }) => { - const responsePromise = page.waitForResponse(/.*\/api\/v1\/audit.*/); + test("should load initial logs and display correctly", async ({ page }) => { + console.log("[test] Navigating to /audit-logs"); await page.goto("/audit-logs"); - await responsePromise; // Check header await expect(page.getByText(/감사 로그|Audit Logs/i).first()).toBeVisible({ timeout: 20000, }); - // Wait for the table to have at least one row - const firstRow = page.locator("tbody tr").first(); - await expect(firstRow).toBeVisible({ timeout: 15000 }); - - // Check if table rows are rendered - await expect(page.locator("tbody tr")).toHaveCount(20); + // Wait for the table row to appear (retry mechanism in expect will handle the async load) + await expect(page.locator("tbody tr")).toHaveCount(20, { timeout: 15000 }); // Check specific data visible in the row await expect(page.locator("tbody")).toContainText("user-even"); await expect(page.locator("tbody")).toContainText("CREATE_TENANT"); - }); - - test("should load more logs on scroll (infinite scroll)", async ({ - page, - }) => { - const responsePromise = page.waitForResponse(/.*\/api\/v1\/audit.*/); - await page.goto("/audit-logs"); - await responsePromise; - - await expect(page.locator("tbody tr").first()).toBeVisible({ - timeout: 15000, }); - await expect(page.locator("tbody tr")).toHaveCount(20); + + test("should load more logs on scroll (infinite scroll)", async ({ + page, + }) => { + await page.goto("/audit-logs"); + await expect(page.locator("tbody tr")).toHaveCount(20, { timeout: 15000 }); const loadMoreBtn = page.getByRole("button", { name: /더 보기|Load more/i, @@ -132,24 +122,16 @@ test.describe("Audit Logs Management", () => { await expect(loadMoreBtn).toBeVisible({ timeout: 10000 }); await expect(loadMoreBtn).toBeEnabled(); - const nextResponsePromise = page.waitForResponse(/.*\/api\/v1\/audit.*/); await loadMoreBtn.click(); - await nextResponsePromise; // Wait for the next page to load (should reach 40) await expect(page.locator("tbody tr")).toHaveCount(40, { timeout: 15000 }); await expect(page.locator("tbody")).toContainText("user-even"); - }); - - test("should filter logs by Action and User ID locally", async ({ page }) => { - const responsePromise = page.waitForResponse(/.*\/api\/v1\/audit.*/); - await page.goto("/audit-logs"); - await responsePromise; - - await expect(page.locator("tbody tr").first()).toBeVisible({ - timeout: 15000, }); - await expect(page.locator("tbody tr")).toHaveCount(20); + + test("should filter logs by Action and User ID locally", async ({ page }) => { + await page.goto("/audit-logs"); + await expect(page.locator("tbody tr")).toHaveCount(20, { timeout: 15000 }); // Search by User ID const userIdInput = page.getByTestId("audit-search-user-id"); @@ -161,7 +143,6 @@ test.describe("Audit Logs Management", () => { // Clear User ID await userIdInput.clear(); - await userIdInput.press("Enter"); await expect(page.locator("tbody tr")).toHaveCount(20, { timeout: 15000 }); // Search by Action @@ -171,17 +152,11 @@ test.describe("Audit Logs Management", () => { // Check that we only see ROTATE_SECRET (20 - 7 = 13) await expect(page.locator("tbody tr")).toHaveCount(13, { timeout: 15000 }); await expect(page.locator("tbody")).not.toContainText("CREATE_TENANT"); - }); - - test("should filter logs by Status locally", async ({ page }) => { - const responsePromise = page.waitForResponse(/.*\/api\/v1\/audit.*/); - await page.goto("/audit-logs"); - await responsePromise; - - await expect(page.locator("tbody tr").first()).toBeVisible({ - timeout: 15000, }); - await expect(page.locator("tbody tr")).toHaveCount(20); + + test("should filter logs by Status locally", async ({ page }) => { + await page.goto("/audit-logs"); + await expect(page.locator("tbody tr")).toHaveCount(20, { timeout: 15000 }); // Select "Failure" status await page.getByTestId("audit-filter-status").selectOption("failure"); @@ -193,5 +168,5 @@ test.describe("Audit Logs Management", () => { await page.getByTestId("audit-filter-status").selectOption("success"); await expect(page.locator("tbody tr")).toHaveCount(16, { timeout: 15000 }); - }); + }); });