fix: reject CMPP daily limit synchronously

This commit is contained in:
hectorzhao
2026-07-22 17:09:44 +08:00
parent 66bc230d7e
commit 55019443c0
7 changed files with 112 additions and 20 deletions
@@ -850,7 +850,7 @@ describe('SendChainService', () => {
expect(prisma.cmppDownstreamDelivery.create).toHaveBeenCalledTimes(2);
});
it('rejects every destination in one CMPP Submit with auditable receipts when the daily limit is exceeded', async () => {
it('rejects the whole CMPP Submit synchronously while keeping per-destination audit records when the daily limit is exceeded', async () => {
const { service, prisma, billing } = createService();
prisma.$queryRaw.mockResolvedValueOnce([{ dailyLimit: 1, usedCount: null }]);
let taskIndex = 0;
@@ -866,12 +866,13 @@ describe('SendChainService', () => {
remoteIp: '127.0.0.1',
});
expect(result).toEqual(expect.objectContaining({ accepted: true, phoneCount: 2 }));
expect(result).toEqual(expect.objectContaining({ accepted: false, result: 8, phoneCount: 2 }));
expect(prisma.smsMessageRecord.create).toHaveBeenCalledTimes(2);
expect(prisma.smsReceiptRecord.create).toHaveBeenCalledTimes(2);
expect(prisma.smsReceiptRecord.create).toHaveBeenCalledWith({
data: expect.objectContaining({ errorCode: 'DAILY_LIMIT', receiptStatus: 'undelivered' }),
expect(prisma.smsMessageRecord.create).toHaveBeenCalledWith({
data: expect.objectContaining({ status: 'rejected', errorCode: 'DAILY_LIMIT' }),
});
expect(prisma.smsReceiptRecord.create).not.toHaveBeenCalled();
expect(prisma.cmppDownstreamDelivery.create).not.toHaveBeenCalled();
expect(billing.freeze).not.toHaveBeenCalled();
});