fix: close admin channel test sms loop

This commit is contained in:
hectorzhao
2026-07-09 11:49:20 +08:00
parent a4a638208e
commit c58a010951
12 changed files with 582 additions and 17 deletions
@@ -554,6 +554,36 @@ describe('SendChainService', () => {
});
});
it('updates admin channel test message status without business retry routing', async () => {
const { service, prisma, billing } = createService();
prisma.smsBatchTask.findUnique.mockResolvedValue({ id: 'task-1', tenantId: 'tenant-1', sourceType: 'admin_channel_test' });
await service.handleSubmitResult({
messageId: 'MSG-1',
channelId: 'channel-1',
submitId: 'SUB-1',
sequenceId: 7,
gatewayMessageId: 'GW-1',
submitStatus: 'timeout',
errorCode: 'SUBMIT_TIMEOUT',
errorMessage: 'context deadline exceeded',
submittedAt: '2026-07-09T03:44:15.445Z',
});
expect(prisma.channelRouteRule.findFirst).not.toHaveBeenCalled();
expect(billing.release).not.toHaveBeenCalled();
expect(prisma.smsMessageRecord.update).toHaveBeenCalledWith({
where: { id: 'record-1' },
data: expect.objectContaining({
gatewayMessageId: 'GW-1',
submitStatus: 'timeout',
status: 'timeout',
errorCode: 'SUBMIT_TIMEOUT',
errorMessage: 'context deadline exceeded',
}),
});
});
it('releases reservation for rejected submit result and refunds failed receipts', async () => {
const { service, prisma, billing } = createService();
prisma.smsBillingRecord.findFirst
+6 -1
View File
@@ -619,13 +619,18 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
},
});
await this.recordSubmitSegments(message, data, submittedAt);
const batchTask = await this.prisma.smsBatchTask.findUnique({
where: { id: message.batchTaskId },
select: { sourceType: true },
});
const isAdminChannelTest = batchTask?.sourceType === 'admin_channel_test';
if (data.submitId && message.submitId && data.submitId !== message.submitId) {
return this.prisma.smsMessageRecord.findUnique({ where: { id: message.id } });
}
const status = data.submitStatus === 'accepted' ? 'submitted' : data.submitStatus === 'timeout' ? 'timeout' : 'submit_failed';
if (data.submitStatus === 'accepted') {
await this.chargeAcceptedMessage(message);
} else {
} else if (!isAdminChannelTest) {
const retried = await this.retryMessageIfAllowed(message, data.submitStatus === 'timeout' ? '提交超时补发' : '提交失败补发');
if (retried) {
await this.refreshTaskProgress(message.batchTaskId);