feat: complete reporting and filing workflows

This commit is contained in:
hectorzhao
2026-07-28 20:28:47 +08:00
parent 352a6293b4
commit 99c8c7c68b
52 changed files with 3490 additions and 376 deletions
+30 -1
View File
@@ -10,7 +10,8 @@ function createPrismaMock() {
createdAt: new Date('2026-07-03T00:00:00.000Z'),
updatedAt: new Date('2026-07-03T00:00:00.000Z'),
};
return {
const prisma = {
$executeRaw: jest.fn().mockResolvedValue(1),
tenant: {
findMany: jest.fn().mockResolvedValue([{ ...tenant, enterpriseCertifications: [] }]),
findUnique: jest.fn().mockResolvedValue({ ...tenant, enterpriseCertifications: [] }),
@@ -27,6 +28,7 @@ function createPrismaMock() {
},
tenantAccount: {
findMany: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', balanceCents: 12000, status: 'active' }]),
findUnique: jest.fn().mockResolvedValue({ balanceCents: 0 }),
},
smsMessageRecord: {
groupBy: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', _sum: { amountCents: 350 } }]),
@@ -35,6 +37,10 @@ function createPrismaMock() {
groupBy: jest.fn().mockResolvedValue([{ tenantId: 'tenant-1', _sum: { amountCents: 125 } }]),
},
};
return {
...prisma,
$transaction: jest.fn((callback: (tx: typeof prisma) => unknown) => callback(prisma)),
};
}
describe('TenantsService', () => {
@@ -96,6 +102,29 @@ describe('TenantsService', () => {
});
});
it('blocks enterprise deletion until a non-zero account balance is cleared', async () => {
const prisma = createPrismaMock();
prisma.tenantAccount.findUnique.mockResolvedValue({ balanceCents: -1250 });
const service = new TenantsService(prisma as never);
await expect(service.delete('tenant-1')).rejects.toThrow('完成余额清算后方可删除,请给企业充值到金额为0');
expect(prisma.tenant.update).not.toHaveBeenCalled();
expect(prisma.smsApplication.count).not.toHaveBeenCalled();
expect(prisma.$executeRaw).toHaveBeenCalledTimes(1);
});
it('allows enterprise deletion only when the account balance is zero and no applications are active', async () => {
const prisma = createPrismaMock();
prisma.tenantAccount.findUnique.mockResolvedValue({ balanceCents: 0 });
const service = new TenantsService(prisma as never);
await expect(service.delete('tenant-1')).resolves.toMatchObject({ id: 'tenant-1' });
expect(prisma.tenant.update).toHaveBeenCalledWith({
where: { id: 'tenant-1' },
data: { status: 'deleted' },
});
});
it('rejects enterprise credit codes containing non-alphanumeric characters', async () => {
const prisma = createPrismaMock();
const service = new TenantsService(prisma as never);