feat: enhance operations dashboard and reporting controls

This commit is contained in:
hectorzhao
2026-09-04 16:26:22 +08:00
parent bc18c7ff12
commit 48d0363920
23 changed files with 544 additions and 49 deletions
+19 -2
View File
@@ -511,6 +511,11 @@ describe('OperationsService', () => {
todaySpendCents: 24000n,
balanceCents: 1000000n,
creditCents: 50000n,
}]).mockResolvedValueOnce([{
segmentCount: 20n,
deliveredSegmentCount: 18n,
billedCents: 360n,
costCents: 216n,
}]).mockResolvedValueOnce([
{ hour: 9, submittedCount: 12n, successCount: 10n },
{ hour: 10, submittedCount: 5n, successCount: 4n },
@@ -541,7 +546,15 @@ describe('OperationsService', () => {
templates: 1,
total: 5,
},
today: expect.objectContaining({ returnedCents: 10 }),
today: expect.objectContaining({
returnedCents: 10,
segmentCount: 20,
deliveredSegmentCount: 18,
arrivalRate: 90,
billedCents: 360,
profitCents: 144,
profitRate: 40,
}),
hourlySendTrend: expect.arrayContaining([
{ hour: 9, label: '09:00', submittedCount: 12, successCount: 10 },
{ hour: 10, label: '10:00', submittedCount: 5, successCount: 4 },
@@ -592,7 +605,11 @@ describe('OperationsService', () => {
updatedAt: { gte: expect.any(Date) },
},
});
const hourlyTrendQuery = prisma.$queryRaw.mock.calls[1]?.[0] as { sql?: string };
const dashboardMetricsQuery = prisma.$queryRaw.mock.calls[1]?.[0] as { sql?: string };
expect(dashboardMetricsQuery.sql).toContain('FROM "SmsMessageSegmentAudit" segment');
expect(dashboardMetricsQuery.sql).toContain('message."billingUnits" * message."unitPrice"');
expect(dashboardMetricsQuery.sql).toContain('submit."costUnitPrice"');
const hourlyTrendQuery = prisma.$queryRaw.mock.calls[2]?.[0] as { sql?: string };
expect(hourlyTrendQuery.sql).toContain(
`HOUR FROM (message."queuedAt" AT TIME ZONE 'UTC') AT TIME ZONE 'Asia/Shanghai'`,
);