fix: validate signatures and restore report metrics

This commit is contained in:
hectorzhao
2026-07-27 20:51:14 +08:00
parent 04a497c791
commit 94aeacd3a2
19 changed files with 438 additions and 42 deletions
+65
View File
@@ -51,6 +51,7 @@ function createPrismaMock() {
reportFields: [{ code: 'license', name: '营业执照', fieldType: 'file', required: true, description: null, sortOrder: 1, status: 'active' }],
};
return {
$queryRaw: jest.fn().mockResolvedValue([]),
$transaction: jest.fn((callback) => callback({
smsChannel: {
create: jest.fn().mockImplementation(({ data }) => Promise.resolve({ id: 'channel-copy', ...data })),
@@ -218,6 +219,70 @@ describe('ChannelsService', () => {
});
});
it('adds real today delivery statistics and the latest successful send time to report tasks', async () => {
const prisma = createPrismaMock();
const task = { id: 'report-task-1', tenantId: 'tenant-1', signatureId: 'sig-1', channelId: 'channel-1', status: 'approved' };
const taskChannel = { id: 'channel-1', code: 'CMPP-A', name: '主通道' };
prisma.channelSignatureReportTask.findMany.mockResolvedValue([
{ ...task, reportType: 'signature', drainageItemId: null, channel: taskChannel },
{ ...task, id: 'report-task-2', reportType: 'drainage', drainageItemId: 'drain-1', channel: taskChannel },
]);
prisma.$queryRaw.mockResolvedValue([
{
channelId: 'channel-1',
signatureId: 'sig-1',
drainageInfoId: null,
total: 5,
acceptedCount: 4,
submitFailureCount: 1,
successCount: 2,
unknownCount: 1,
failureCount: 1,
lastSuccessfulSentAt: new Date('2026-07-27T01:00:00.000Z'),
},
{
channelId: 'channel-1',
signatureId: 'sig-1',
drainageInfoId: 'drain-1',
total: 3,
acceptedCount: 3,
submitFailureCount: 0,
successCount: 3,
unknownCount: 0,
failureCount: 0,
lastSuccessfulSentAt: new Date('2026-07-27T02:00:00.000Z'),
},
]);
const service = new ChannelsService(prisma as never);
const result = await service.listReportTasks(undefined, undefined, 'channel-1');
expect(result[0]).toEqual(expect.objectContaining({
deliveryStats: {
total: 8,
acceptedCount: 7,
submitFailureCount: 1,
submitFailureRate: 12.5,
successCount: 5,
successRate: 71.4,
unknownCount: 1,
unknownRate: 14.3,
failureCount: 1,
failureRate: 14.3,
},
lastSuccessfulSentAt: new Date('2026-07-27T02:00:00.000Z'),
}));
expect(result[1]).toEqual(expect.objectContaining({
deliveryStats: expect.objectContaining({
total: 3,
submitFailureCount: 0,
successCount: 3,
successRate: 100,
}),
lastSuccessfulSentAt: new Date('2026-07-27T02:00:00.000Z'),
}));
});
it('changes channel report status and recomputes the signature summary atomically', async () => {
const prisma = createPrismaMock();
const tx = {