perf: batch gateway submits and isolate callbacks
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { GatewayCallbackController } from './gateway-callback.controller';
|
||||
|
||||
describe('GatewayCallbackController', () => {
|
||||
const sendChain = {
|
||||
handleSubmitResult: jest.fn(), handleSubmitSegmentResult: jest.fn(),
|
||||
intakeReceipt: jest.fn(), handleReceipt: jest.fn(), handleUplink: jest.fn(),
|
||||
recordGatewaySubmitDeadLetter: jest.fn(),
|
||||
};
|
||||
const protocolLogs = { record: jest.fn() };
|
||||
const prisma = { $queryRaw: jest.fn(), getPoolState: jest.fn().mockReturnValue({ max: 16, total: 2, idle: 1, waiting: 0 }) };
|
||||
const controller = new GatewayCallbackController(sendChain as never, protocolLogs as never, prisma as never);
|
||||
|
||||
beforeEach(() => jest.clearAllMocks());
|
||||
|
||||
it('keeps Submit result persistence on the callback process without duplicating protocol logs', async () => {
|
||||
sendChain.handleSubmitResult.mockResolvedValue({ accepted: true });
|
||||
await expect(controller.submitResult({
|
||||
messageId: 'MSG-1', channelId: 'channel-1', gatewayMessageId: '1', sequenceId: 1,
|
||||
submitStatus: 'accepted',
|
||||
})).resolves.toEqual({ accepted: true });
|
||||
expect(sendChain.handleSubmitResult).toHaveBeenCalledTimes(1);
|
||||
expect(protocolLogs.record).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('durably intakes receipts before recording the callback protocol event', async () => {
|
||||
sendChain.intakeReceipt.mockResolvedValue({ accepted: true, inboxId: 'inbox-1' });
|
||||
await controller.receiptIntake({
|
||||
messageId: 'MSG-1', channelId: 'channel-1', gatewayMessageId: '1',
|
||||
phoneNumber: '13800000001', receiptStatus: 'delivered', rawStatus: 'DELIVRD',
|
||||
});
|
||||
expect(sendChain.intakeReceipt).toHaveBeenCalledTimes(1);
|
||||
expect(protocolLogs.record).toHaveBeenCalledWith(expect.objectContaining({
|
||||
eventType: 'deliver_receipt', messageId: 'MSG-1', status: 'success',
|
||||
}));
|
||||
});
|
||||
|
||||
it('rejects inbound/client packet logs from the isolated supplier callback surface', () => {
|
||||
expect(() => controller.protocolLog({
|
||||
protocol: 'cmpp', direction: 'client_to_platform', eventType: 'submit', status: 'success',
|
||||
})).toThrow(BadRequestException);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user