|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 5 | + |
| 6 | +const { mockGetSession, mockPrefetch } = vi.hoisted(() => ({ |
| 7 | + mockGetSession: vi.fn(), |
| 8 | + mockPrefetch: vi.fn(), |
| 9 | +})) |
| 10 | + |
| 11 | +vi.mock('next/navigation', () => ({ |
| 12 | + notFound: () => { |
| 13 | + throw new Error('NEXT_NOT_FOUND') |
| 14 | + }, |
| 15 | + redirect: (href: string) => { |
| 16 | + throw new Error(`NEXT_REDIRECT:${href}`) |
| 17 | + }, |
| 18 | +})) |
| 19 | +vi.mock('@/lib/auth', () => ({ getSession: mockGetSession })) |
| 20 | +vi.mock('@/lib/core/config/env-flags', () => ({ isBillingEnabled: true })) |
| 21 | +vi.mock('@/lib/permissions/super-user', () => ({ isPlatformAdmin: vi.fn() })) |
| 22 | +vi.mock('@/app/_shell/providers/get-query-client', () => ({ getQueryClient: vi.fn() })) |
| 23 | +vi.mock('@/components/settings/prefetch-standalone-general', () => ({ |
| 24 | + prefetchStandaloneGeneral: mockPrefetch, |
| 25 | +})) |
| 26 | +vi.mock('@/components/settings/account-settings-renderer', () => ({ |
| 27 | + AccountSettingsRenderer: () => null, |
| 28 | +})) |
| 29 | + |
| 30 | +import AccountSettingsSectionPage from '@/app/account/settings/[section]/page' |
| 31 | + |
| 32 | +const pageProps = (section: string) => ({ params: Promise.resolve({ section }) }) |
| 33 | + |
| 34 | +describe('account settings legacy links', () => { |
| 35 | + beforeEach(() => { |
| 36 | + vi.clearAllMocks() |
| 37 | + mockGetSession.mockResolvedValue({ user: { id: 'viewer-a' } }) |
| 38 | + }) |
| 39 | + |
| 40 | + it('redirects Authorized apps bookmarks to the General subview', async () => { |
| 41 | + await expect(AccountSettingsSectionPage(pageProps('authorized-apps'))).rejects.toThrow( |
| 42 | + 'NEXT_REDIRECT:/account/settings/general?view=authorized-apps' |
| 43 | + ) |
| 44 | + expect(mockPrefetch).not.toHaveBeenCalled() |
| 45 | + }) |
| 46 | + |
| 47 | + it('authenticates before following the legacy bookmark', async () => { |
| 48 | + mockGetSession.mockResolvedValue(null) |
| 49 | + |
| 50 | + await expect(AccountSettingsSectionPage(pageProps('authorized-apps'))).rejects.toThrow( |
| 51 | + 'NEXT_REDIRECT:/login' |
| 52 | + ) |
| 53 | + }) |
| 54 | + |
| 55 | + it('still rejects unknown sections', async () => { |
| 56 | + await expect(AccountSettingsSectionPage(pageProps('unknown'))).rejects.toThrow('NEXT_NOT_FOUND') |
| 57 | + }) |
| 58 | +}) |
0 commit comments