fix: harden real backend admin workflows and ui
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { TenantsService } from './tenants.service';
|
||||
|
||||
function createPrismaMock() {
|
||||
const tenant = {
|
||||
id: 'tenant-1',
|
||||
name: '测试企业',
|
||||
code: 'TENANT001',
|
||||
status: 'active',
|
||||
createdAt: new Date('2026-07-03T00:00:00.000Z'),
|
||||
updatedAt: new Date('2026-07-03T00:00:00.000Z'),
|
||||
};
|
||||
return {
|
||||
tenant: {
|
||||
findMany: jest.fn().mockResolvedValue([{ ...tenant, enterpriseCertifications: [] }]),
|
||||
findUnique: jest.fn().mockResolvedValue({ ...tenant, enterpriseCertifications: [] }),
|
||||
create: jest.fn().mockResolvedValue(tenant),
|
||||
update: jest.fn().mockResolvedValue(tenant),
|
||||
},
|
||||
enterpriseCertification: {
|
||||
findFirst: jest.fn().mockResolvedValue(null),
|
||||
create: jest.fn().mockResolvedValue({ id: 'cert-1' }),
|
||||
update: jest.fn().mockResolvedValue({ id: 'cert-1' }),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe('TenantsService', () => {
|
||||
it('creates tenants with a real enterprise profile', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new TenantsService(prisma as never);
|
||||
|
||||
await service.create({
|
||||
name: '测试企业',
|
||||
code: 'TENANT001',
|
||||
creditCode: '91370000123456789X',
|
||||
province: '山东',
|
||||
city: '济南',
|
||||
address: '历下区测试路 1 号',
|
||||
contactName: '张三',
|
||||
contactIdCard: '370100199001010011',
|
||||
contactPhone: '13800000000',
|
||||
contactEmail: 'contact@example.com',
|
||||
});
|
||||
|
||||
expect(prisma.enterpriseCertification.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({
|
||||
tenantId: 'tenant-1',
|
||||
companyName: '测试企业',
|
||||
licenseNo: '91370000123456789X',
|
||||
contactName: '张三',
|
||||
contactPhone: '13800000000',
|
||||
status: 'approved',
|
||||
materials: expect.objectContaining({
|
||||
province: '山东',
|
||||
city: '济南',
|
||||
address: '历下区测试路 1 号',
|
||||
contactIdCard: '370100199001010011',
|
||||
contactEmail: 'contact@example.com',
|
||||
}),
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
it('throws 404 when updating or deleting a missing tenant', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.tenant.findUnique.mockResolvedValue(null);
|
||||
const service = new TenantsService(prisma as never);
|
||||
|
||||
await expect(service.update('missing', { name: '不存在' })).rejects.toBeInstanceOf(NotFoundException);
|
||||
await expect(service.delete('missing')).rejects.toBeInstanceOf(NotFoundException);
|
||||
expect(prisma.tenant.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user