fix: simplify balance billing and govern operation logs
This commit is contained in:
@@ -437,6 +437,36 @@ describe('SmsConfigService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
['heartbeat', 'lastHeartbeatAt'],
|
||||
['submit', 'lastSubmitAt'],
|
||||
['deliver', 'lastDeliverAt'],
|
||||
] as const)('updates downstream %s state without appending high-frequency operation logs', async (status, timestampField) => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.cmppDownstreamConnection.findUnique.mockResolvedValue({
|
||||
id: 'downstream-1',
|
||||
connectedAt: new Date('2026-07-11T11:00:00.000Z'),
|
||||
lastHeartbeatAt: new Date('2026-07-11T11:00:00.000Z'),
|
||||
lastSubmitAt: null,
|
||||
lastDeliverAt: null,
|
||||
lastError: null,
|
||||
});
|
||||
const service = new SmsConfigService(prisma as never);
|
||||
|
||||
await service.recordDownstreamConnectionEvent({
|
||||
account: '100001',
|
||||
connectionId: 'gateway-1-1',
|
||||
status,
|
||||
observedAt: '2026-07-11T11:00:30.000Z',
|
||||
});
|
||||
|
||||
expect(prisma.cmppDownstreamConnection.update).toHaveBeenCalledWith(expect.objectContaining({
|
||||
where: { id: 'downstream-1' },
|
||||
data: expect.objectContaining({ [timestampField]: new Date('2026-07-11T11:00:30.000Z') }),
|
||||
}));
|
||||
expect(prisma.operationLog.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('lists enterprise signatures with keyword filters and real relations', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new SmsConfigService(prisma as never);
|
||||
|
||||
@@ -593,13 +593,15 @@ export class SmsConfigService {
|
||||
const connection = existing
|
||||
? await this.prisma.cmppDownstreamConnection.update({ where: { id: existing.id }, data: payload })
|
||||
: await this.prisma.cmppDownstreamConnection.create({ data: { connectionId: data.connectionId, ...payload } });
|
||||
await this.writeOperationLog(application.tenantId, undefined, `cmpp_downstream_connection.${data.status}`, 'cmpp_downstream_connection', data.connectionId, {
|
||||
applicationId: application.id,
|
||||
account: data.account,
|
||||
remoteIp: data.remoteIp,
|
||||
protocol: data.protocol,
|
||||
status: connection.status,
|
||||
});
|
||||
if (data.status === 'connected' || data.status === 'disconnected') {
|
||||
await this.writeOperationLog(application.tenantId, undefined, `cmpp_downstream_connection.${data.status}`, 'cmpp_downstream_connection', data.connectionId, {
|
||||
applicationId: application.id,
|
||||
account: data.account,
|
||||
remoteIp: data.remoteIp,
|
||||
protocol: data.protocol,
|
||||
status: connection.status,
|
||||
});
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user