fix(ai-character): 관리자 권한 확인 중복 요청 방지

This commit is contained in:
Yu Sung
2026-08-03 13:08:12 +09:00
parent 8265fe4947
commit 344674c756
4 changed files with 49 additions and 42 deletions

View File

@@ -3,7 +3,7 @@ import { http, HttpResponse } from "msw";
import { afterEach, beforeEach, expect, test, vi } from "vitest";
import { App } from "./App";
import { apiBaseUrl, installDesktopMediaQuery, requireElement, saveAdminSession, useAiCharactersResponse } from "./app-test-support";
import { apiBaseUrl, installDesktopMediaQuery, requireElement, saveAdminSession, useAiCharacterDetailResponse, useAiCharactersResponse } from "./app-test-support";
import { authSessionStorage } from "@/features/auth/model/auth-session-storage";
import { server } from "@/shared/test/server";
@@ -41,6 +41,26 @@ test("renders the protected admin shell for an existing ADMIN session", async ()
await waitFor(() => expect(requests).toHaveLength(2));
});
test("reuses successful ADMIN verification during protected intra-app navigation", async () => {
saveAdminSession();
const verificationRequests: Request[] = [];
useAiCharactersResponse(200, (request) => verificationRequests.push(request));
useAiCharacterDetailResponse("101");
window.history.pushState({}, "", "/ai-characters");
render(<App />);
await screen.findByRole("main", { name: "AI 캐릭터 관리" });
await waitFor(() => expect(verificationRequests).toHaveLength(2));
window.history.pushState({}, "", "/ai-characters/101/edit");
fireEvent.popState(window);
expect(screen.getByRole("main", { name: "AI 캐릭터 관리" })).toBeInTheDocument();
expect(screen.queryByRole("heading", { name: "관리자 권한 확인 중" })).not.toBeInTheDocument();
expect(await screen.findByRole("heading", { name: "AI 캐릭터 수정" })).toBeInTheDocument();
expect(verificationRequests).toHaveLength(2);
});
test("shows an accessible status while the initial protected route probe is pending", async () => {
saveAdminSession();
let resolveProbeReady: (finishProbe: () => void) => void = () => undefined;
@@ -59,7 +79,7 @@ test("shows an accessible status while the initial protected route probe is pend
render(<App />);
const finishProbe = await probeReady;
expect(screen.getByRole("status")).toHaveTextContent("보호 route 확인 중");
expect(screen.getByRole("status")).toHaveTextContent("관리자 권한 확인 중");
expect(screen.queryByRole("main", { name: "AI 캐릭터 관리" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "로그아웃" })).not.toBeInTheDocument();
finishProbe();
@@ -84,7 +104,7 @@ test("keeps malformed protected routes behind the ADMIN probe", async () => {
render(<App />);
const finishProbe = await probeReady;
expect(screen.getByRole("status")).toHaveTextContent("보호 route 확인 중");
expect(screen.getByRole("status")).toHaveTextContent("관리자 권한 확인 중");
expect(screen.queryByRole("main", { name: "AI 캐릭터 관리" })).not.toBeInTheDocument();
finishProbe();
expect(await screen.findByRole("heading", { name: "접근 권한이 없습니다" })).toBeInTheDocument();
@@ -122,7 +142,7 @@ test.each([
render(<App />);
const finishProbe = await probeReady;
expect(screen.getByRole("status")).toHaveTextContent("보호 route 확인 중");
expect(screen.getByRole("status")).toHaveTextContent("관리자 권한 확인 중");
expect(screen.queryByRole("main", { name: "AI 캐릭터 관리" })).not.toBeInTheDocument();
expect(screen.queryByRole("button", { name: "로그아웃" })).not.toBeInTheDocument();
finishProbe();