84 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** @jest-environment node */
import { getServerSession } from 'next-auth'
import { isSuperAdmin } from '@/lib/department-permission'
import { savePermissionPackItems } from '@/lib/user-permission-inherit'
jest.mock('next-auth', () => ({
getServerSession: jest.fn(),
}))
jest.mock('@/lib/auth', () => ({
authOptions: {},
}))
jest.mock('@/lib/prisma', () => ({
prisma: {
user: {
findUnique: jest.fn(),
},
},
}))
jest.mock('@/lib/department-permission', () => ({
getAllMaterialTypes: jest.fn(),
isSuperAdmin: jest.fn(),
}))
jest.mock('@/lib/user-permission-inherit', () => ({
ensureDefaultPermissionPacks: jest.fn(),
packItemsToMap: jest.fn(),
savePermissionPackItems: jest.fn(),
}))
const { PUT } = require('@/app/api/organization/user-permission-inherits/route') as typeof import('@/app/api/organization/user-permission-inherits/route')
describe('/api/organization/user-permission-inherits 保存权限包', () => {
beforeEach(() => {
jest.clearAllMocks()
;(getServerSession as jest.Mock).mockResolvedValue({ user: { id: 'super-admin' } })
;(isSuperAdmin as jest.Mock).mockResolvedValue(true)
})
test('私密任务详情权限仅任务详情可保存 true,其他类型强制回落为 false', async () => {
const response = await PUT({
json: async () => ({
action: 'save-pack',
slug: 'visual',
permissions: [
{
materialType: '任务-详情',
canView: true,
canDownload: true,
canDownloadSource: true,
canEditAssets: true,
canAccessPrivate: true,
},
{
materialType: '3D场景',
canView: true,
canDownload: true,
canDownloadSource: false,
canEditAssets: true,
canAccessPrivate: true,
},
],
}),
} as never)
expect(response.status).toBe(200)
expect(savePermissionPackItems).toHaveBeenCalledWith('visual', [
expect.objectContaining({
materialType: '任务-详情',
canEditAssets: true,
canAccessPrivate: true,
}),
expect.objectContaining({
materialType: '3D场景',
canEditAssets: false,
canAccessPrivate: false,
}),
])
})
})