88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
/** @jest-environment node */
|
|
|
|
import { getServerSession } from 'next-auth'
|
|
import { isSuperAdmin } from '@/lib/department-permission'
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
jest.mock('next-auth', () => ({
|
|
getServerSession: jest.fn(),
|
|
}))
|
|
|
|
jest.mock('@/lib/auth', () => ({
|
|
authOptions: {},
|
|
}))
|
|
|
|
jest.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
organizationUnit: {
|
|
findMany: jest.fn(),
|
|
},
|
|
departmentMaterialPermission: {
|
|
findMany: jest.fn(),
|
|
},
|
|
userEmployeeBinding: {
|
|
findMany: jest.fn(),
|
|
},
|
|
},
|
|
}))
|
|
|
|
jest.mock('@/lib/department-permission', () => ({
|
|
getAllMaterialTypes: jest.fn(async () => ['任务-详情']),
|
|
isSuperAdmin: jest.fn(),
|
|
}))
|
|
|
|
jest.mock('@/lib/material-type-options', () => ({
|
|
filterSelectableMaterialTypes: jest.fn((types: string[]) => types),
|
|
}))
|
|
|
|
const { GET } = require('@/app/api/organization/material-permissions/route') as typeof import('@/app/api/organization/material-permissions/route')
|
|
|
|
describe('/api/organization/material-permissions GET', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
;(getServerSession as jest.Mock).mockResolvedValue({ user: { id: 'super-admin' } })
|
|
;(isSuperAdmin as jest.Mock).mockResolvedValue(true)
|
|
;(prisma.organizationUnit.findMany as jest.Mock).mockResolvedValue([
|
|
{
|
|
id: 'brand-center',
|
|
name: '品牌中心',
|
|
path: '江苏简尚品牌管理有限公司/品牌中心',
|
|
level: 2,
|
|
parentId: null,
|
|
},
|
|
])
|
|
;(prisma.departmentMaterialPermission.findMany as jest.Mock).mockResolvedValue([
|
|
{
|
|
department: '江苏简尚品牌管理有限公司/品牌中心',
|
|
materialType: '任务-详情',
|
|
canView: true,
|
|
canDownload: true,
|
|
canDownloadSource: true,
|
|
canShare: true,
|
|
},
|
|
])
|
|
;(prisma.userEmployeeBinding.findMany as jest.Mock).mockResolvedValue([
|
|
{
|
|
employeeProfile: {
|
|
departmentPath: '江苏简尚品牌管理有限公司/品牌中心',
|
|
},
|
|
},
|
|
])
|
|
})
|
|
|
|
test('旧部门权限 GET 默认返回 canAccessPrivate false', async () => {
|
|
const response = await GET()
|
|
const body = await response.json()
|
|
|
|
expect(response.status).toBe(200)
|
|
expect(body.permissions['江苏简尚品牌管理有限公司/品牌中心']['任务-详情']).toMatchObject({
|
|
canView: true,
|
|
canDownload: true,
|
|
canDownloadSource: true,
|
|
canShare: true,
|
|
canEditAssets: false,
|
|
canAccessPrivate: false,
|
|
})
|
|
})
|
|
})
|