This commit is contained in:
2026-08-25 09:52:45 +08:00
parent e9b6979a82
commit 5641545fd5
4 changed files with 208 additions and 6 deletions
@@ -5,8 +5,11 @@ import { createPinia, setActivePinia } from 'pinia'
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
createPlatformManagedUser,
getPlatformUserOptions,
listSharedReceivingOverseasWarehouseOptions,
listPlatformManagedUsers,
updatePlatformManagedUser,
type PlatformManagedUser,
} from '@/modules/iam/api/platformIam'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
@@ -18,6 +21,7 @@ const internalUsersSource = readFileSync(resolve(process.cwd(), 'src/modules/iam
vi.mock('@/modules/iam/api/platformIam', () => ({
listPlatformManagedUsers: vi.fn(),
getPlatformUserOptions: vi.fn(),
listSharedReceivingOverseasWarehouseOptions: vi.fn(),
createPlatformManagedUser: vi.fn(),
updatePlatformManagedUser: vi.fn(),
changePlatformManagedUserStatus: vi.fn(),
@@ -48,6 +52,7 @@ const user: PlatformManagedUser = {
memberType: 'INTERNAL', memberNo: 'PLATFORM-30', status: 'ACTIVE', roleIds: ['40'],
roleNames: ['运营管理员'], lastLoginAt: '2026-06-01T10:30:00',
protectedAccount: false,
overseasWarehouseId: null,
}
async function mountView() {
@@ -101,10 +106,15 @@ describe('InternalUsersView platform internal user management', () => {
{ id: '10001', name: '华远贸易', status: 'ACTIVE' },
],
roles: [
{ id: '40', tenantId: '0', name: '运营管理员', status: 'ACTIVE' },
{ id: '41', tenantId: '10001', name: '租户管理员', status: 'ACTIVE' },
{ id: '40', tenantId: '0', roleCode: 'PLATFORM_OPERATOR', name: '运营管理员', status: 'ACTIVE' },
{ id: '41', tenantId: '10001', roleCode: 'CUSTOMER_ADMIN', name: '客户管理员', status: 'ACTIVE' },
],
})
vi.mocked(listSharedReceivingOverseasWarehouseOptions).mockReset().mockResolvedValue([
{ id: '90071992547409931', warehouseCode: 'LAX-01', warehouseName: '洛杉矶收货仓', countryCode: 'US' },
])
vi.mocked(createPlatformManagedUser).mockReset().mockResolvedValue(user)
vi.mocked(updatePlatformManagedUser).mockReset().mockResolvedValue(user)
})
it('loads a server page and only renders internal-user fields', async () => {
@@ -143,6 +153,73 @@ describe('InternalUsersView platform internal user management', () => {
expect(document.body.textContent).toContain('确认添加')
})
it('requires a shared receiving warehouse for WAREHOUSE_PICKER', async () => {
vi.mocked(getPlatformUserOptions).mockResolvedValueOnce({
tenants: [{ id: '0', name: '平台', status: 'ACTIVE' }],
roles: [
{ id: '40', tenantId: '0', roleCode: 'PLATFORM_OPERATOR', name: '运营管理员', status: 'ACTIVE' },
{ id: '4000005', tenantId: '0', roleCode: 'WAREHOUSE_PICKER', name: '仓库拣货员', status: 'ACTIVE' },
],
})
const wrapper = await mountView()
await wrapper.findAll('button').find((button) => button.text().trim() === '新增用户')?.trigger('click')
await flushPromises()
expect(document.body.textContent).not.toContain('实际海外收货仓')
const roleSelect = wrapper.findAllComponents({ name: 'ElSelect' })
.find((component) => component.props('placeholder') === '选择角色')
expect(roleSelect).toBeDefined()
roleSelect?.vm.$emit('update:modelValue', ['4000005'])
await flushPromises()
expect(listSharedReceivingOverseasWarehouseOptions).toHaveBeenCalledOnce()
expect(document.body.textContent).toContain('实际海外收货仓')
const warehouseSelect = wrapper.findAllComponents({ name: 'ElSelect' })
.find((component) => component.props('placeholder') === '请选择平台共享海外收货仓')
expect(warehouseSelect).toBeDefined()
})
it('uses the stable role code instead of localized role names to activate the warehouse binding', () => {
expect(internalUsersSource).toContain("role.roleCode === 'WAREHOUSE_PICKER'")
expect(internalUsersSource).toContain('overseasWarehouseId: hasWarehousePickerRole.value ? form.overseasWarehouseId : null')
expect(internalUsersSource).not.toContain("role.name === '仓库拣货员'")
})
it('preserves the picker warehouse binding when editing a WAREHOUSE_PICKER user', async () => {
const pickerUser: PlatformManagedUser = {
...user,
roleIds: ['4000005'],
roleNames: ['仓库拣货员'],
overseasWarehouseId: '90071992547409931',
}
vi.mocked(listPlatformManagedUsers).mockResolvedValueOnce({
records: [pickerUser], page: 1, size: 10, total: 1, pages: 1,
})
vi.mocked(getPlatformUserOptions).mockResolvedValueOnce({
tenants: [{ id: '0', name: '平台', status: 'ACTIVE' }],
roles: [{ id: '4000005', tenantId: '0', roleCode: 'WAREHOUSE_PICKER', name: '仓库拣货员', status: 'ACTIVE' }],
})
vi.mocked(updatePlatformManagedUser).mockResolvedValueOnce(pickerUser)
const wrapper = await mountView()
const setupState = (wrapper.vm.$ as unknown as {
setupState: { openEdit: (row: PlatformManagedUser) => void }
}).setupState
setupState.openEdit(pickerUser)
await flushPromises()
await wrapper.findAll('button').find((button) => button.text().trim() === '保存修改')?.trigger('click')
await flushPromises()
expect(updatePlatformManagedUser).toHaveBeenCalledWith('30', {
displayName: '张伟',
phone: '13800138000',
email: 'zhangwei@example.com',
tenantId: '0',
roleIds: ['4000005'],
overseasWarehouseId: '90071992547409931',
})
})
it('requests server-side pages and filters instead of slicing locally', async () => {
const wrapper = await mountView()
await wrapper.find('button[aria-label="第 2 页"]').trigger('click')