import { createPinia, setActivePinia } from 'pinia' import { beforeEach, describe, expect, it } from 'vitest' import { useAccessPreviewStore } from '@/core/access/accessPreview' import { useAuthStore } from '@/core/auth/auth' describe('server access store', () => { beforeEach(() => setActivePinia(createPinia())) it('uses only the authenticated permission snapshot', () => { const auth = useAuthStore() auth.token = 'token' auth.permissions = ['platform:warehouse:list'] const access = useAccessPreviewStore() access.initializeAfterLogin() expect(access.can('platform:warehouse:list')).toBe(true) expect(access.can('platform:user:list')).toBe(false) expect(access.firstAccessiblePath).toBe('/dashboard') }) it('keeps only the unprotected dashboard when the server snapshot is empty', () => { const access = useAccessPreviewStore() expect(access.permissionCodes.size).toBe(0) expect(access.filteredNavigation).toHaveLength(1) expect(access.firstAccessiblePath).toBe('/dashboard') }) })