|
|
@@ -427,6 +427,59 @@ describe('公司管理API集成测试', () => {
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
});
|
|
|
+
|
|
|
+ it('应该过滤已删除的公司(status=0)', async () => {
|
|
|
+ // 创建测试数据:3个正常公司,2个已删除公司
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const companyRepository = dataSource.getRepository(Company);
|
|
|
+
|
|
|
+ // 创建3个正常公司
|
|
|
+ for (let i = 1; i <= 3; i++) {
|
|
|
+ const company = companyRepository.create({
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ companyName: `正常公司${i}`,
|
|
|
+ contactPerson: `联系人${i}`,
|
|
|
+ contactPhone: `1380013800${i}`,
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ await companyRepository.save(company);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建2个已删除公司
|
|
|
+ for (let i = 4; i <= 5; i++) {
|
|
|
+ const company = companyRepository.create({
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ companyName: `已删除公司${i}`,
|
|
|
+ contactPerson: `联系人${i}`,
|
|
|
+ contactPhone: `1380013800${i}`,
|
|
|
+ status: 0
|
|
|
+ });
|
|
|
+ await companyRepository.save(company);
|
|
|
+ }
|
|
|
+
|
|
|
+ const response = await client.getAllCompanies.$get({
|
|
|
+ query: { skip: 0, take: 10 }
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+
|
|
|
+ if (response.status === 200) {
|
|
|
+ const data = await response.json();
|
|
|
+ // 应该只返回3个正常公司,不返回已删除的公司
|
|
|
+ expect(data.data).toHaveLength(3);
|
|
|
+ expect(data.total).toBe(3);
|
|
|
+
|
|
|
+ // 验证返回的都是正常公司
|
|
|
+ data.data.forEach((company: any) => {
|
|
|
+ expect(company.status).toBe(1);
|
|
|
+ expect(company.companyName).toMatch(/^正常公司/);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('GET /company/searchCompanies', () => {
|
|
|
@@ -461,6 +514,52 @@ describe('公司管理API集成测试', () => {
|
|
|
expect(data.data[0].companyName).toContain('科技');
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ it('应该过滤已删除的公司(搜索时)', async () => {
|
|
|
+ // 创建测试数据
|
|
|
+ const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
+ const companyRepository = dataSource.getRepository(Company);
|
|
|
+
|
|
|
+ // 创建正常公司
|
|
|
+ const normalCompany = companyRepository.create({
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ companyName: '测试搜索公司正常',
|
|
|
+ contactPerson: '张三',
|
|
|
+ contactPhone: '13800138000',
|
|
|
+ status: 1
|
|
|
+ });
|
|
|
+ await companyRepository.save(normalCompany);
|
|
|
+
|
|
|
+ // 创建已删除的公司(不同名称)
|
|
|
+ const deletedCompany = companyRepository.create({
|
|
|
+ platformId: testPlatform.id,
|
|
|
+ companyName: '测试搜索公司已删除',
|
|
|
+ contactPerson: '李四',
|
|
|
+ contactPhone: '13900139000',
|
|
|
+ status: 0
|
|
|
+ });
|
|
|
+ await companyRepository.save(deletedCompany);
|
|
|
+
|
|
|
+ const response = await client.searchCompanies.$get({
|
|
|
+ query: { name: '测试搜索', skip: 0, take: 10 }
|
|
|
+ }, {
|
|
|
+ headers: {
|
|
|
+ 'Authorization': `Bearer ${testToken}`
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(response.status).toBe(200);
|
|
|
+
|
|
|
+ if (response.status === 200) {
|
|
|
+ const data = await response.json();
|
|
|
+ // 应该只返回1个正常公司,不返回已删除的公司
|
|
|
+ expect(data.data).toHaveLength(1);
|
|
|
+ expect(data.total).toBe(1);
|
|
|
+ expect(data.data[0].companyName).toBe('测试搜索公司正常');
|
|
|
+ expect(data.data[0].status).toBe(1);
|
|
|
+ expect(data.data[0].contactPerson).toBe('张三'); // 正常公司的联系人
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('GET /company/getCompaniesByPlatform/:platformId', () => {
|