38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/** @jest-environment node */
|
||
|
||
import { GET } from '@/app/api/materials/upload/cleanup/route'
|
||
import { getServerSession } from 'next-auth'
|
||
|
||
jest.mock('next-auth', () => ({ getServerSession: jest.fn() }))
|
||
jest.mock('@/lib/auth', () => ({ authOptions: {} }))
|
||
jest.mock('@/lib/department-permission', () => ({
|
||
hasSystemAdminPermission: jest.fn(() => true),
|
||
}))
|
||
jest.mock('@/lib/upload-sessions', () => ({
|
||
deleteOwnedUploadSession: jest.fn(),
|
||
getOwnedUploadSession: jest.fn(),
|
||
getUploadSessionPresence: jest.fn(),
|
||
isSafeUploadId: jest.fn(() => true),
|
||
resolveOwnedMergedUpload: jest.fn(),
|
||
}))
|
||
|
||
describe('/api/materials/upload/cleanup GET safety gate', () => {
|
||
beforeEach(() => {
|
||
jest.clearAllMocks()
|
||
;(getServerSession as jest.Mock).mockResolvedValue({
|
||
user: { id: 'admin-1', role: 'admin', isSuperAdmin: true },
|
||
})
|
||
})
|
||
|
||
test.each(['1', '7'])('拒绝小于 8 小时的 maxAge=%s,避免删除仍可恢复的上传', async (maxAge) => {
|
||
const response = await GET({
|
||
url: `http://localhost/api/materials/upload/cleanup?maxAge=${maxAge}`,
|
||
} as any)
|
||
|
||
expect(response.status).toBe(400)
|
||
await expect(response.json()).resolves.toEqual({
|
||
error: 'maxAge 必须是 8 到 168 之间的整数',
|
||
})
|
||
})
|
||
})
|