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'
|
2026-08-03 18:49:18 +08:00
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
import { useAuthStore } from '@/core/auth/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
|
|
|
})
|
|
|
|
|
})
|