Files
admin-web/src/stores/accessPreview.test.ts
T

28 lines
1019 B
TypeScript
Raw Normal View History

2026-07-30 17:59:43 +08:00
import { createPinia, setActivePinia } from 'pinia'
2026-07-31 15:34:35 +08:00
import { beforeEach, describe, expect, it } from 'vitest'
import { useAccessPreviewStore } from '@/stores/accessPreview'
import { useAuthStore } from '@/stores/auth'
2026-07-30 17:59:43 +08:00
2026-07-31 15:34:35 +08:00
describe('server access store', () => {
beforeEach(() => setActivePinia(createPinia()))
2026-07-30 17:59:43 +08:00
2026-07-31 15:34:35 +08:00
it('uses only the authenticated permission snapshot', () => {
const auth = useAuthStore()
auth.token = 'token'
auth.permissions = ['platform:warehouse:list']
const access = useAccessPreviewStore()
access.initializeAfterLogin()
2026-07-30 17:59:43 +08:00
2026-07-31 15:34:35 +08:00
expect(access.can('platform:warehouse:list')).toBe(true)
expect(access.can('platform:user:list')).toBe(false)
expect(access.firstAccessiblePath).toBe('/warehouses')
2026-07-30 17:59:43 +08:00
})
2026-07-31 15:34:35 +08:00
it('exposes no permissions when the server snapshot is empty', () => {
const access = useAccessPreviewStore()
expect(access.permissionCodes.size).toBe(0)
expect(access.filteredNavigation).toHaveLength(0)
expect(access.firstAccessiblePath).toBeNull()
2026-07-30 17:59:43 +08:00
})
})