export {} jest.mock('@/lib/prisma', () => ({ prisma: { $executeRawUnsafe: jest.fn(), materialLog: { create: jest.fn(), }, }, })) const { prisma } = require('@/lib/prisma') const { ensureMaterialLogsTable, createMaterialLog } = require('../material-log') describe('material log persistence safety', () => { beforeEach(() => { jest.resetAllMocks() }) it('运行期不再兜底建表或改表', async () => { await ensureMaterialLogsTable() expect(prisma.$executeRawUnsafe).not.toHaveBeenCalled() }) it('创建日志时会保存素材快照', async () => { await createMaterialLog({ materialId: 'material-1', userId: 'user-1', action: 'DELETE', materialSnapshot: { productModel: '测试素材', }, }) expect(prisma.materialLog.create).toHaveBeenCalledWith({ data: expect.objectContaining({ materialId: 'material-1', action: 'DELETE', materialSnapshot: { productModel: '测试素材', }, }), }) expect(prisma.$executeRawUnsafe).not.toHaveBeenCalled() }) })