fix: restore daily operations quality metrics
This commit is contained in:
@@ -2,6 +2,7 @@ import { OperationsService } from './operations.service';
|
||||
|
||||
function createPrismaMock() {
|
||||
return {
|
||||
$queryRaw: jest.fn().mockResolvedValue([]),
|
||||
user: {
|
||||
findFirst: jest.fn().mockResolvedValue({ tenantId: 'tenant-1' }),
|
||||
},
|
||||
@@ -391,6 +392,50 @@ describe('OperationsService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns real daily channel and signature quality for the selected Shanghai date', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.$queryRaw
|
||||
.mockResolvedValueOnce([{
|
||||
channelId: 'channel-1',
|
||||
channelName: '通道一',
|
||||
total: 5,
|
||||
successCount: 3,
|
||||
unknownCount: 1,
|
||||
failureCount: 1,
|
||||
successRate: 60,
|
||||
unknownRate: 20,
|
||||
failureRate: 20,
|
||||
averageArrivalMs: 1200,
|
||||
}])
|
||||
.mockResolvedValueOnce([{
|
||||
id: 'signature-1:plain',
|
||||
signatureId: 'signature-1',
|
||||
signatureName: '【测试签名】',
|
||||
tenantId: 'tenant-1',
|
||||
tenantName: '租户A',
|
||||
hasDrainage: false,
|
||||
total: 5,
|
||||
successCount: 3,
|
||||
unknownCount: 1,
|
||||
failureCount: 1,
|
||||
successRate: 60,
|
||||
averageArrivalMs: 1200,
|
||||
}]);
|
||||
const service = new OperationsService(prisma as never);
|
||||
|
||||
await expect(service.sendQuality('2026-07-24')).resolves.toEqual({
|
||||
date: '2026-07-24',
|
||||
channels: [expect.objectContaining({ channelId: 'channel-1', total: 5, successRate: 60 })],
|
||||
signatures: [expect.objectContaining({ signatureId: 'signature-1', signatureName: '【测试签名】', hasDrainage: false })],
|
||||
});
|
||||
expect(prisma.$queryRaw).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('rejects invalid send quality dates', async () => {
|
||||
const service = new OperationsService(createPrismaMock() as never);
|
||||
await expect(service.sendQuality('2026-02-31')).rejects.toThrow('统计日期无效');
|
||||
});
|
||||
|
||||
it('returns trace details and reconciliation diffs', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new OperationsService(prisma as never);
|
||||
|
||||
Reference in New Issue
Block a user