1
0
forked from baron/baron-sso
Files
baron-sso/adminfront/tests/data_integrity.spec.ts

152 lines
4.5 KiB
TypeScript

import { expect, test } from "@playwright/test";
test.describe("Data integrity management", () => {
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 authority = "http://localhost:5000/oidc";
const clientId = "adminfront";
const key = `oidc.user:${authority}:${clientId}`;
window.localStorage.setItem(
key,
JSON.stringify({
access_token: "fake-token",
token_type: "Bearer",
profile: {
sub: "admin-user",
name: "Admin",
email: "admin@test.com",
role: "super_admin",
},
expires_at: Math.floor(Date.now() / 1000) + 36000,
}),
);
});
await page.route("**/api/v1/user/me", async (route) => {
await route.fulfill({
json: {
id: "admin-user",
name: "Admin",
email: "admin@test.com",
role: "super_admin",
manageableTenants: [],
},
});
});
await page.route("**/api/v1/admin/integrity", async (route) => {
await route.fulfill({
json: {
status: "fail",
checkedAt: "2026-05-14T00:00:00Z",
summary: {
totalChecks: 2,
passed: 1,
warnings: 0,
failures: 1,
},
sections: [
{
key: "tenant_integrity",
label: "테넌트 정합성",
status: "fail",
checks: [
{
key: "duplicate_tenant_slugs",
label: "중복 테넌트 slug",
description:
"삭제되지 않은 tenant의 slug를 대소문자 무시 기준으로 검사합니다.",
status: "fail",
severity: "error",
count: 1,
},
],
},
],
},
});
});
await page.route(/.*\/api\/v1\/.*/, async (route) => {
const url = route.request().url();
if (url.includes("/api/v1/user/me")) {
await route.fulfill({
json: {
id: "admin-user",
name: "Admin",
email: "admin@test.com",
role: "super_admin",
manageableTenants: [],
},
});
return;
}
if (url.includes("/api/v1/admin/integrity")) {
await route.fulfill({
json: {
status: "fail",
checkedAt: "2026-05-14T00:00:00Z",
summary: {
totalChecks: 2,
passed: 1,
warnings: 0,
failures: 1,
},
sections: [
{
key: "tenant_integrity",
label: "테넌트 정합성",
status: "fail",
checks: [
{
key: "duplicate_tenant_slugs",
label: "중복 테넌트 slug",
description:
"삭제되지 않은 tenant의 slug를 대소문자 무시 기준으로 검사합니다.",
status: "fail",
severity: "error",
count: 1,
},
],
},
],
},
});
return;
}
if (route.request().method() === "GET") {
await route.fulfill({ json: { items: [], total: 0 } });
} else {
await route.fulfill({ status: 200, json: {} });
}
});
});
test("shows the super-admin integrity report", async ({ page }) => {
await page.goto("/system/data-integrity");
await expect(
page.getByRole("heading", { name: "데이터 정합성 검증" }),
).toBeVisible();
await expect(page.getByText("테넌트 정합성")).toBeVisible();
await expect(page.getByText("중복 테넌트 slug")).toBeVisible();
await expect(page.getByRole("button", { name: "다시 검사" })).toBeVisible();
});
test("shows the latest integrity summary on the overview page", async ({
page,
}) => {
await page.goto("/");
await expect(page.getByText("정합성 최종 검증")).toBeVisible();
await expect(page.getByText("실패 1건")).toBeVisible();
await expect(page.getByText("테넌트 정합성")).toBeVisible();
});
});