接入前端登录权限底座

This commit is contained in:
andy committed 2026-07-09 20:42:16 +08:00
1 parent c190d5e3a8
commit e49b2ccc1d
27 files changed
+1745 -68

No files matched your search

@@ -1,10 +1,12 @@
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createI18n } from 'vue-i18n'
import { createMemoryHistory, createRouter } from 'vue-router'
import zhCN from '@/i18n/locales/zh-CN'
import ReservationTaskDetailPanel from '@/components/reservation/ReservationTaskDetailPanel.vue'
import { useAuthStore } from '@/stores/authStore'
import type {
ReservationManualReviewConversionResult,
ReservationOrderListItem,
@@ -163,7 +165,40 @@ function createRequiredField(overrides: Partial<ReservationTaskFieldResult> = {}
}
}
async function mountPanel() {
function createAuthPayload(permissions: string[]) {
return {
access_token: 'session-token',
token_type: 'Bearer',
expires_at: '2026-07-09T12:00:00Z',
user: {
id: '1900000000000000001',
username: 'admin',
display_name: '系统管理员',
super_admin: true,
},
default_hotel_id: 'HOTEL-TEST',
hotels: [
{
hotel_id: 'HOTEL-TEST',
hotel_name: '测试酒店',
time_zone: 'Asia/Bangkok',
default_hotel: true,
},
],
permissions,
menus: [],
}
}
const defaultTaskPermissions = [
'RESERVATION_TASK_READ',
'RESERVATION_TASK_EDIT',
'RESERVATION_TASK_CONFIRM',
'RESERVATION_OPERA_SIM_EXECUTE',
'RESERVATION_AUDIT_READ',
]
async function mountPanel(permissions = defaultTaskPermissions) {
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
@@ -179,6 +214,9 @@ async function mountPanel() {
{ path: '/reservation/source-messages/:sourceMessageId/conversation', component: { template: '<div />' } },
],
})
const pinia = createPinia()
setActivePinia(pinia)
useAuthStore().applyLoginResult(createAuthPayload(permissions))
await router.push('/reservation/tasks/10001')
await router.isReady()
@@ -187,7 +225,7 @@ async function mountPanel() {
taskId: '10001',
},
global: {
plugins: [i18n, router],
plugins: [i18n, router, pinia],
stubs: {
RouterLink: {
template: '<a><slot /></a>',
@@ -222,6 +260,7 @@ describe('ReservationTaskDetailPanel', () => {
})
vi.mocked(service.fetchReservationOrders).mockResolvedValue(createOrderCandidateResult([]))
vi.mocked(service.convertReservationManualReviewTask).mockResolvedValue(createManualReviewConversionResult())
sessionStorage.clear()
})
it('shows draft save errors instead of leaving an unhandled rejection', async () => {
@@ -500,4 +539,45 @@ describe('ReservationTaskDetailPanel', () => {
target_order_id: '20002',
})
})
it('hides task processing buttons and audit timeline without permissions', async () => {
vi.mocked(service.fetchReservationTaskAudits).mockResolvedValue({
task_id: '10001',
items: [createAudit('audit-1', 'TASK_LOADED')],
})
vi.mocked(service.fetchReservationTaskDetail).mockResolvedValue(
createTaskDetail({
availability: {
blocked: false,
read_only: false,
editable: true,
confirmable: true,
executable: true,
blocked_by_task_id: null,
blocked_reason: null,
},
opera_operations: [
{
operation_id: 'op-1',
task_id: '10001',
operation_sequence: 1,
operation_code: 'CREATE_RESERVATION',
operation_name: 'Create reservation',
operation_status: 'PENDING',
attempt_count: 0,
last_error_message: null,
attempts: [],
},
],
}),
)
const wrapper = await mountPanel(['RESERVATION_TASK_READ'])
expect(wrapper.text()).not.toContain('保存草稿')
expect(wrapper.text()).not.toContain('确认任务')
expect(wrapper.text()).not.toContain('审计时间线')
expect(wrapper.find('button[title="执行"]').exists()).toBe(false)
expect(wrapper.find('button[title="重试"]').exists()).toBe(false)
})
})