fix: align reporting fields queries and disk monitoring
This commit is contained in:
@@ -114,6 +114,7 @@ function createPrismaMock() {
|
||||
create: jest.fn().mockResolvedValue({ id: 'drainage-record-1' }),
|
||||
},
|
||||
smsTemplate: {
|
||||
count: jest.fn().mockResolvedValue(0),
|
||||
findMany: jest.fn().mockResolvedValue([{
|
||||
id: 'tpl-1',
|
||||
tenantId: 'tenant-1',
|
||||
@@ -1024,6 +1025,56 @@ describe('SmsConfigService', () => {
|
||||
expect(prisma.channelSignatureReportTask.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('never lets client status filters bypass deleted signature exclusion and keeps template history filtered', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.smsSignature.findMany.mockResolvedValue([]);
|
||||
prisma.smsSignature.groupBy.mockResolvedValue([] as never);
|
||||
prisma.smsTemplate.findMany.mockResolvedValue([]);
|
||||
const service = new SmsConfigService(prisma as never);
|
||||
for (const status of ['deleted', 'all', 'approved']) {
|
||||
await service.getClientSignatureWorkspace('tenant-1', { status });
|
||||
const filter = { notIn: ['deleted', 'disabled'], ...(status !== 'all' ? { equals: status } : {}) };
|
||||
expect(prisma.smsSignature.findMany).toHaveBeenLastCalledWith(expect.objectContaining({ where: expect.objectContaining({ tenantId: 'tenant-1', auditStatus: filter }) }));
|
||||
expect(prisma.smsSignature.count).toHaveBeenLastCalledWith(expect.objectContaining({ where: expect.objectContaining({ auditStatus: filter }) }));
|
||||
}
|
||||
await service.listClientTemplates('tenant-1', true);
|
||||
expect(prisma.smsTemplate.findMany).toHaveBeenLastCalledWith(expect.objectContaining({ where: expect.objectContaining({ tenantId: 'tenant-1', auditStatus: { not: 'deleted' } }) }));
|
||||
await service.listTemplatesPage({ tenantId: 'tenant-1', status: 'all', page: 1, pageSize: 10 });
|
||||
expect(prisma.smsTemplate.count).toHaveBeenLastCalledWith(expect.objectContaining({ where: expect.objectContaining({ auditStatus: { not: 'deleted' } }) }));
|
||||
prisma.smsSignature.findUnique.mockResolvedValue({ id: 'sig-deleted', tenantId: 'tenant-1', auditStatus: 'deleted' } as never);
|
||||
prisma.smsTemplate.findUnique.mockResolvedValue({ id: 'tpl-deleted', tenantId: 'tenant-1', auditStatus: 'deleted' } as never);
|
||||
await expect(service.submitSignature('sig-deleted', 'tenant-1')).rejects.toThrow('not found');
|
||||
await expect(service.submitTemplate('tpl-deleted', 'tenant-1')).rejects.toThrow('not found');
|
||||
});
|
||||
|
||||
it('uses exactly the same editable common fields in client and admin signature forms', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const field = { id: 'field-common', code: 'license', name: '主体证明', fieldType: 'file', description: '最新配置', status: 'active' };
|
||||
prisma.commonReportField.findMany.mockResolvedValue([{ id: 'common-1', reportType: 'signature', required: true, drainageField: field }]);
|
||||
const service = new SmsConfigService(prisma as never);
|
||||
for (const applicationId of [undefined, 'app-1']) {
|
||||
const admin = await service.getApplicationReportFields(applicationId, 'signature');
|
||||
const client = await service.getClientApplicationReportFields(applicationId, 'signature');
|
||||
expect(client).toEqual(admin.map((item) => Object.fromEntries(Object.entries(item).filter(([key]) => !['channels', 'commonReportTypes'].includes(key)))));
|
||||
expect(client[0]).toMatchObject({ code: 'license', name: '主体证明', fieldType: 'file', required: true, description: '最新配置' });
|
||||
}
|
||||
prisma.commonReportField.findMany.mockResolvedValue([{ id: 'common-1', reportType: 'signature', required: false, drainageField: field }]);
|
||||
expect((await service.getClientApplicationReportFields(undefined, 'signature'))[0].required).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps both common field purposes in material snapshots and ignores deleted channel requirements', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const field = { id: 'field-1', code: 'license', name: '主体证明', fieldType: 'file', status: 'active' };
|
||||
prisma.commonReportField.findMany.mockResolvedValue([
|
||||
{ reportType: 'signature', required: true, drainageField: field },
|
||||
{ reportType: 'drainage', required: false, drainageField: field },
|
||||
]);
|
||||
prisma.channelRouteRule.findMany.mockResolvedValue([{ group: { id: 'group-1', items: [{ channel: { id: 'deleted-channel', status: 'deleted', reportFields: [{ status: 'active', reportType: 'signature', required: true, drainageField: { ...field, id: 'old', code: 'old' } }] } }] } }] as never);
|
||||
const result = await new SmsConfigService(prisma as never).getApplicationReportFields('app-1');
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).toMatchObject({ required: true, reportTypes: ['signature', 'drainage'], commonReportTypes: ['signature', 'drainage'], channels: [] });
|
||||
});
|
||||
|
||||
it('accepts a scheme-less drainage URL and synchronizes the compatibility name', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.smsSignature.findUnique.mockResolvedValue({ id: 'sig-1', tenantId: 'tenant-1', applicationId: 'app-1', auditStatus: 'approved' });
|
||||
|
||||
Reference in New Issue
Block a user