statistics.integration.test.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import { describe, it, expect, beforeEach } from 'vitest';
  2. import { testClient } from 'hono/testing';
  3. import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '@d8d/shared-test-util';
  4. import { JWTUtil } from '@d8d/shared-utils';
  5. import { UserEntity, Role } from '@d8d/user-module';
  6. import { File } from '@d8d/file-module';
  7. import { DisabledPerson } from '@d8d/allin-disability-module';
  8. import { BankName } from '@d8d/bank-names-module';
  9. import { Company } from '@d8d/allin-company-module/entities';
  10. import { Platform } from '@d8d/allin-platform-module';
  11. import { DataSource } from 'typeorm';
  12. import statisticsRoutes from '../../src/routes/statistics.routes';
  13. import { EmploymentOrder } from '@d8d/allin-order-module/entities/employment-order.entity';
  14. import { OrderPerson } from '@d8d/allin-order-module/entities/order-person.entity';
  15. import { OrderPersonAsset } from '@d8d/allin-order-module/entities/order-person-asset.entity';
  16. import { WorkStatus } from '@d8d/allin-enums';
  17. // 设置集成测试钩子
  18. setupIntegrationDatabaseHooksWithEntities([
  19. UserEntity,
  20. File,
  21. Role,
  22. Platform,
  23. Company,
  24. DisabledPerson,
  25. BankName,
  26. EmploymentOrder,
  27. OrderPerson,
  28. OrderPersonAsset
  29. ])
  30. describe('数据统计API集成测试', () => {
  31. let client: ReturnType<typeof testClient<typeof statisticsRoutes>>;
  32. let testToken: string;
  33. let testUser: UserEntity;
  34. let testCompany: Company;
  35. let testDisabledPerson: DisabledPerson;
  36. let testOrder: EmploymentOrder;
  37. let testOrderPerson: OrderPerson;
  38. let dataSource: DataSource;
  39. beforeEach(async () => {
  40. // 创建测试客户端
  41. client = testClient(statisticsRoutes);
  42. // 获取数据源
  43. dataSource = await IntegrationTestDatabase.getDataSource();
  44. // 创建测试用户
  45. const userRepository = dataSource.getRepository(UserEntity);
  46. testUser = userRepository.create({
  47. username: `test_user_${Date.now()}`,
  48. password: 'test_password',
  49. nickname: '测试用户',
  50. registrationSource: 'web'
  51. });
  52. await userRepository.save(testUser);
  53. // 生成测试用户的token
  54. testToken = JWTUtil.generateToken({
  55. id: testUser.id,
  56. username: testUser.username,
  57. roles: [{name:'user'}]
  58. });
  59. // 创建测试公司
  60. const companyRepository = dataSource.getRepository(Company);
  61. testCompany = companyRepository.create({
  62. companyName: '测试公司',
  63. contactPerson: '测试联系人',
  64. contactPhone: '13800138000',
  65. status: 1
  66. });
  67. await companyRepository.save(testCompany);
  68. // 创建测试文件
  69. const fileRepository = dataSource.getRepository(File);
  70. const testFile = fileRepository.create({
  71. name: 'test_file.pdf',
  72. type: 'application/pdf',
  73. size: 1024,
  74. path: `test/${Date.now()}_test_file.pdf`,
  75. uploadUserId: testUser.id,
  76. uploadTime: new Date(),
  77. createdAt: new Date(),
  78. updatedAt: new Date()
  79. });
  80. await fileRepository.save(testFile);
  81. // 创建测试银行名称记录
  82. const bankNameRepository = dataSource.getRepository(BankName);
  83. const testBankName = bankNameRepository.create({
  84. name: '测试银行',
  85. code: 'TEST001',
  86. remark: '测试银行',
  87. createdBy: testUser.id,
  88. updatedBy: testUser.id,
  89. status: 1
  90. });
  91. await bankNameRepository.save(testBankName);
  92. // 创建测试残疾人记录
  93. const disabledPersonRepository = dataSource.getRepository(DisabledPerson);
  94. testDisabledPerson = disabledPersonRepository.create({
  95. name: '测试残疾人',
  96. gender: '男',
  97. idCard: `test_id_${Date.now()}`,
  98. disabilityType: '视力残疾',
  99. disabilityLevel: '三级',
  100. province: '北京市',
  101. city: '北京市',
  102. jobStatus: 1,
  103. birthDate: new Date('1990-01-01'),
  104. idAddress: '测试地址',
  105. phone: '13800138000',
  106. canDirectContact: 1,
  107. disabilityId: `CJZ${Date.now()}`
  108. });
  109. await disabledPersonRepository.save(testDisabledPerson);
  110. // 创建测试平台
  111. const platformRepository = dataSource.getRepository(Platform);
  112. const testPlatform = platformRepository.create({
  113. name: '测试平台',
  114. code: 'TEST',
  115. status: 1
  116. });
  117. await platformRepository.save(testPlatform);
  118. // 创建测试订单
  119. const orderRepository = dataSource.getRepository(EmploymentOrder);
  120. testOrder = orderRepository.create({
  121. orderName: '测试订单',
  122. platformId: testPlatform.id,
  123. companyId: testCompany.id,
  124. channelId: 1,
  125. expectedStartDate: new Date(),
  126. orderStatus: 'active',
  127. workStatus: WorkStatus.WORKING
  128. });
  129. await orderRepository.save(testOrder);
  130. // 创建测试订单人员
  131. const orderPersonRepository = dataSource.getRepository(OrderPerson);
  132. testOrderPerson = orderPersonRepository.create({
  133. orderId: testOrder.id,
  134. disabledPersonId: testDisabledPerson.id,
  135. salaryDetail: 5000,
  136. workStatus: WorkStatus.WORKING
  137. });
  138. await orderPersonRepository.save(testOrderPerson);
  139. // 创建测试订单人员资产(打卡视频)
  140. const orderPersonAssetRepository = dataSource.getRepository(OrderPersonAsset);
  141. const testAsset = orderPersonAssetRepository.create({
  142. orderPersonId: testOrderPerson.id,
  143. assetType: 'checkin_video',
  144. assetFileType: 'video',
  145. fileId: testFile.id
  146. });
  147. await orderPersonAssetRepository.save(testAsset);
  148. });
  149. describe('GET /statistics/disability-type-distribution', () => {
  150. it('应该返回正确的残疾类型分布统计', async () => {
  151. // 测试实现待补充
  152. expect(true).toBe(true);
  153. });
  154. });
  155. describe('GET /statistics/gender-distribution', () => {
  156. it('应该返回正确的性别分布统计', async () => {
  157. // 测试实现待补充
  158. expect(true).toBe(true);
  159. });
  160. });
  161. describe('GET /statistics/age-distribution', () => {
  162. it('应该基于birth_date字段返回正确的年龄分布统计', async () => {
  163. // 测试实现待补充
  164. expect(true).toBe(true);
  165. });
  166. });
  167. describe('GET /statistics/household-distribution', () => {
  168. it('应该返回正确的户籍分布统计', async () => {
  169. // 测试实现待补充
  170. expect(true).toBe(true);
  171. });
  172. });
  173. describe('GET /statistics/job-status-distribution', () => {
  174. it('应该返回正确的在职状态分布统计', async () => {
  175. // 测试实现待补充
  176. expect(true).toBe(true);
  177. });
  178. });
  179. describe('GET /statistics/salary-distribution', () => {
  180. it('应该基于salary_detail字段返回正确的薪资分布统计', async () => {
  181. // 测试实现待补充
  182. expect(true).toBe(true);
  183. });
  184. });
  185. describe('企业数据隔离', () => {
  186. it('不同企业用户只能看到自己企业的统计', async () => {
  187. // 测试实现待补充
  188. expect(true).toBe(true);
  189. });
  190. });
  191. });