fix: harden admin and CMPP delivery workflows

This commit is contained in:
hectorzhao
2026-07-15 11:21:02 +08:00
parent 00b6d95752
commit e47432bc9d
34 changed files with 878 additions and 226 deletions
+44 -2
View File
@@ -252,6 +252,7 @@ describe('OperationsService', () => {
.mockResolvedValueOnce(2)
.mockResolvedValueOnce(8)
.mockResolvedValueOnce(1)
.mockResolvedValueOnce(1)
.mockResolvedValueOnce(2);
const service = new OperationsService(prisma as never);
@@ -274,11 +275,25 @@ describe('OperationsService', () => {
failed: 2,
delivered: 8,
stalledPending: 1,
stalledAck: 1,
recentFailed: 2,
alertCount: 3,
alertCount: 4,
}),
}),
);
expect(prisma.cmppDownstreamDelivery.count).toHaveBeenNthCalledWith(4, {
where: { tenantId: 'tenant-1', status: 'pending', createdAt: { lte: expect.any(Date) } },
});
expect(prisma.cmppDownstreamDelivery.count).toHaveBeenNthCalledWith(5, {
where: { tenantId: 'tenant-1', status: 'awaiting_ack', ackDeadlineAt: { lte: expect.any(Date) } },
});
expect(prisma.cmppDownstreamDelivery.count).toHaveBeenNthCalledWith(6, {
where: {
tenantId: 'tenant-1',
status: { in: ['failed', 'unconfirmed', 'rejected'] },
updatedAt: { gte: expect.any(Date) },
},
});
await service.statistics({ tenantId: 'tenant-1', groupBy: 'application' });
expect(prisma.smsMessageRecord.groupBy).toHaveBeenCalledWith({
@@ -399,6 +414,8 @@ describe('OperationsService', () => {
deliveryType: 'receipt',
status: 'failed',
keyword: '1380',
createdAtFrom: '2026-07-01',
createdAtTo: '2026-07-15',
page: 1,
pageSize: 10,
})).resolves.toEqual({
@@ -413,6 +430,10 @@ describe('OperationsService', () => {
tenantId: 'tenant-1',
deliveryType: 'receipt',
status: 'failed',
createdAt: {
gte: new Date('2026-07-01T00:00:00.000+08:00'),
lte: new Date('2026-07-15T23:59:59.999+08:00'),
},
}),
include: { tenant: true, application: true, messageRecord: true },
orderBy: { createdAt: 'desc' },
@@ -451,6 +472,10 @@ describe('OperationsService', () => {
{ applicationId: 'app-1', status: 'delivered', _count: { _all: 5 } },
{ applicationId: 'app-2', status: 'pending', _count: { _all: 1 } },
{ applicationId: 'app-2', status: 'delivered', _count: { _all: 3 } },
])
.mockResolvedValueOnce([
{ applicationId: 'app-1', _count: { _all: 1 } },
{ applicationId: 'app-2', _count: { _all: 1 } },
]);
const service = new OperationsService(prisma as never);
@@ -482,10 +507,27 @@ describe('OperationsService', () => {
{ label: '4次及以上', count: 0 },
],
topApplications: [
{ applicationId: 'app-1', name: '应用A', pending: 2, awaitingAck: 0, failed: 1, unconfirmed: 0, rejected: 0, delivered: 5, alertCount: 3 },
{ applicationId: 'app-1', name: '应用A', pending: 2, awaitingAck: 0, failed: 1, unconfirmed: 0, rejected: 0, delivered: 5, alertCount: 1 },
{ applicationId: 'app-2', name: '应用B', pending: 1, awaitingAck: 0, failed: 0, unconfirmed: 0, rejected: 0, delivered: 3, alertCount: 1 },
],
});
expect(prisma.cmppDownstreamDelivery.groupBy).toHaveBeenNthCalledWith(3, {
by: ['applicationId'],
where: {
AND: [
{ tenantId: 'tenant-1', applicationId: 'app-1', deliveryType: undefined },
{
OR: [
{ status: 'pending', createdAt: { lte: expect.any(Date) } },
{ status: 'awaiting_ack', ackDeadlineAt: { lte: expect.any(Date) } },
{ status: { in: ['failed', 'unconfirmed', 'rejected'] }, updatedAt: { gte: expect.any(Date) } },
],
},
],
},
_count: { _all: true },
});
});
it('returns paginated downstream recovery statuses', async () => {