38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
jest.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
$queryRaw: jest.fn(),
|
|
},
|
|
}))
|
|
|
|
jest.mock('@/lib/system-settings-columns', () => ({
|
|
ensureSystemSettingsOptionalColumns: jest.fn(),
|
|
}))
|
|
|
|
export {}
|
|
|
|
const { prisma } = require('@/lib/prisma')
|
|
const { ensureSystemSettingsOptionalColumns } = require('@/lib/system-settings-columns')
|
|
|
|
describe('public-share-settings', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
})
|
|
|
|
it('读取公开分享开关时不执行运行期 DDL', async () => {
|
|
prisma.$queryRaw.mockResolvedValue([{ enablePublicShare: true }])
|
|
const { isPublicShareEnabled } = require('../public-share-settings')
|
|
|
|
await expect(isPublicShareEnabled()).resolves.toBe(true)
|
|
expect(ensureSystemSettingsOptionalColumns).not.toHaveBeenCalled()
|
|
expect(prisma.$queryRaw).toHaveBeenCalled()
|
|
})
|
|
|
|
it('读取失败时按关闭处理', async () => {
|
|
prisma.$queryRaw.mockRejectedValue(new Error('missing column'))
|
|
const { isPublicShareEnabled } = require('../public-share-settings')
|
|
|
|
await expect(isPublicShareEnabled()).resolves.toBe(false)
|
|
expect(ensureSystemSettingsOptionalColumns).not.toHaveBeenCalled()
|
|
})
|
|
})
|