fix: simplify balance billing and govern operation logs
This commit is contained in:
@@ -23,11 +23,14 @@ function createPrismaMock() {
|
||||
update: jest.fn().mockResolvedValue({ id: 'cert-1' }),
|
||||
},
|
||||
tenantAccount: {
|
||||
findMany: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', balanceCents: 12000, smsUnits: 300, creditCents: 5000, status: 'active' }]),
|
||||
findMany: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', balanceCents: 12000, status: 'active' }]),
|
||||
},
|
||||
smsMessageRecord: {
|
||||
groupBy: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', _sum: { amountCents: 350 } }]),
|
||||
},
|
||||
accountTransaction: {
|
||||
groupBy: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', _sum: { amountCents: 125 } }]),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ describe('TenantsService', () => {
|
||||
expect(prisma.tenant.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('lists management rows with real account and today spend fields', async () => {
|
||||
it('lists management rows with real account, today spend and actual refund fields', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new TenantsService(prisma as never);
|
||||
|
||||
@@ -86,8 +89,9 @@ describe('TenantsService', () => {
|
||||
expect.objectContaining({
|
||||
id: 'tenant-1',
|
||||
name: '测试企业',
|
||||
account: expect.objectContaining({ balanceCents: 12000, creditCents: 5000 }),
|
||||
account: expect.objectContaining({ balanceCents: 12000 }),
|
||||
todaySpendCents: 350,
|
||||
todayRefundCents: 125,
|
||||
}),
|
||||
]);
|
||||
expect(prisma.tenant.findMany).toHaveBeenCalledWith(expect.objectContaining({
|
||||
@@ -99,5 +103,10 @@ describe('TenantsService', () => {
|
||||
by: ['tenantId'],
|
||||
_sum: { amountCents: true },
|
||||
}));
|
||||
expect(prisma.accountTransaction.groupBy).toHaveBeenCalledWith(expect.objectContaining({
|
||||
by: ['tenantId'],
|
||||
where: expect.objectContaining({ transactionType: 'refunded' }),
|
||||
_sum: { amountCents: true },
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user