fix: harden real backend workflows and channel connections
This commit is contained in:
@@ -22,6 +22,12 @@ function createPrismaMock() {
|
||||
create: jest.fn().mockResolvedValue({ id: 'cert-1' }),
|
||||
update: jest.fn().mockResolvedValue({ id: 'cert-1' }),
|
||||
},
|
||||
tenantAccount: {
|
||||
findMany: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', balanceCents: 12000, smsUnits: 300, creditCents: 5000, status: 'active' }]),
|
||||
},
|
||||
smsMessageRecord: {
|
||||
groupBy: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', _sum: { amountCents: 350 } }]),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -71,4 +77,25 @@ describe('TenantsService', () => {
|
||||
await expect(service.delete('missing')).rejects.toBeInstanceOf(NotFoundException);
|
||||
expect(prisma.tenant.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('lists management rows with real account and today spend fields', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new TenantsService(prisma as never);
|
||||
|
||||
await expect(service.listManagementRows()).resolves.toEqual([
|
||||
expect.objectContaining({
|
||||
id: 'tenant-1',
|
||||
name: '测试企业',
|
||||
account: expect.objectContaining({ balanceCents: 12000, creditCents: 5000 }),
|
||||
todaySpendCents: 350,
|
||||
}),
|
||||
]);
|
||||
expect(prisma.tenant.findMany).toHaveBeenCalledWith(expect.objectContaining({
|
||||
where: { status: { not: 'deleted' } },
|
||||
}));
|
||||
expect(prisma.smsMessageRecord.groupBy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
by: ['tenantId'],
|
||||
_sum: { amountCents: true },
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user