diff --git a/src/__tests__/Navigation.test.tsx b/src/__tests__/Navigation.test.tsx
index 0569722..665235e 100644
--- a/src/__tests__/Navigation.test.tsx
+++ b/src/__tests__/Navigation.test.tsx
@@ -29,9 +29,15 @@ import { useSession } from '@/components/SessionProvider'
describe('Epic 1: Navigation Component', () => {
beforeEach(() => {
vi.clearAllMocks()
- vi.mocked(global.fetch).mockResolvedValue({
- json: () => Promise.resolve({ role: 'player' }),
- } as Response)
+ vi.mocked(global.fetch).mockImplementation(async (url) => {
+ if (url?.toString().includes('/api/users/')) {
+ return new Response(JSON.stringify({ role: 'player' }), {
+ status: 200,
+ headers: { 'Content-Type': 'application/json' },
+ })
+ }
+ return new Response(JSON.stringify({}), { status: 200 })
+ })
})
afterEach(() => {
@@ -116,15 +122,21 @@ describe('Epic 1: Navigation Component', () => {
})
// Mock fetch to return club_admin role
- vi.mocked(global.fetch).mockResolvedValue({
- json: () => Promise.resolve({ role: 'club_admin' }),
- } as Response)
+ vi.mocked(global.fetch).mockImplementation(async (url) => {
+ if (url?.toString().includes('/api/users/admin-123/role')) {
+ return new Response(JSON.stringify({ role: 'club_admin' }), {
+ status: 200,
+ headers: { 'Content-Type': 'application/json' },
+ })
+ }
+ return new Response(JSON.stringify({}), { status: 200 })
+ })
render()
await waitFor(() => {
expect(screen.getByText('Admin')).toBeInTheDocument()
- })
+ }, { timeout: 3000 })
expect(screen.getByText('Tournaments')).toBeInTheDocument()
})
@@ -143,10 +155,17 @@ describe('Epic 1: Navigation Component', () => {
refreshSession: vi.fn(),
})
- // Mock fetch to return player role
- vi.mocked(global.fetch).mockResolvedValue({
- json: () => Promise.resolve({ role: 'player' }),
- } as Response)
+ // Mock fetch to return player role (already set in beforeEach, but explicit here)
+ vi.mocked(global.fetch).mockImplementation(async (url) => {
+ if (url?.toString().includes('/api/users/')) {
+ return {
+ json: () => Promise.resolve({ role: 'player' }),
+ } as Response
+ }
+ return {
+ json: () => Promise.resolve({}),
+ } as Response
+ })
render()