fix: paginate operational list pages

This commit is contained in:
hectorzhao
2026-07-28 23:20:13 +08:00
parent 87c5b1eccc
commit b8560372cc
40 changed files with 1208 additions and 422 deletions
+23 -1
View File
@@ -15,9 +15,10 @@ function createPrismaMock() {
},
smsMessageRecord: {
findMany: jest.fn().mockResolvedValue([{ messageId: 'MSG-1' }]),
count: jest.fn().mockResolvedValue(51),
groupBy: jest.fn().mockResolvedValue([{ status: 'delivered', _count: { _all: 2 }, _sum: { amountCents: 20, billingUnits: 2 } }]),
aggregate: jest.fn().mockResolvedValue({ _count: { _all: 2 }, _sum: { amountCents: 20, billingUnits: 2 } }),
},
},
smsReceiptRecord: {
findMany: jest.fn().mockResolvedValue([]),
},
@@ -254,6 +255,27 @@ describe('OperationsService', () => {
}));
});
it('paginates message records in PostgreSQL and limits heavy relations to the requested page', async () => {
const prisma = createPrismaMock();
const service = new OperationsService(prisma as never);
await expect(service.listMessagesPage({ tenantId: 'tenant-1', page: 2, pageSize: 25 })).resolves.toEqual({
items: [{ messageId: 'MSG-1' }],
total: 51,
page: 2,
pageSize: 25,
});
expect(prisma.smsMessageRecord.findMany).toHaveBeenCalledWith(expect.objectContaining({
where: expect.objectContaining({ tenantId: 'tenant-1' }),
skip: 25,
take: 25,
orderBy: [{ queuedAt: 'desc' }, { id: 'desc' }],
}));
expect(prisma.smsMessageRecord.count).toHaveBeenCalledWith({
where: expect.objectContaining({ tenantId: 'tenant-1' }),
});
});
it('returns uplink messages with tenant and channel display data', async () => {
const prisma = createPrismaMock();
const service = new OperationsService(prisma as never);