Browse Source

✨ feat(shared-types): add disabled status enum and mapping

- 添加DisabledStatus枚举定义(DISABLED=1, ENABLED=0)
- 添加DisabledStatusNameMap中文映射关系

♻️ refactor(shared-utils): adjust tsconfig rootDir configuration

- 将rootDir从"src"修改为"."以适应项目结构

✅ test(user-module): optimize integration test setup

- 替换getTestDataSource为initializeDataSource初始化测试数据源
- 将测试数据库初始化/销毁移至beforeEach/afterEach确保测试隔离
- 移除手动清理数据库操作,简化测试代码
yourname 3 tuần trước cách đây
mục cha
commit
6042a21c2d

+ 12 - 0
packages/shared-types/src/index.ts

@@ -52,6 +52,18 @@ export const DeleteStatusNameMap: Record<DeleteStatus, string> = {
   [DeleteStatus.DELETED]: '已删除'
 };
 
+// 启用/禁用状态枚举(反向定义)
+export enum DisabledStatus {
+  DISABLED = 1, // 禁用
+  ENABLED = 0   // 启用
+}
+
+// 启用/禁用状态中文映射
+export const DisabledStatusNameMap: Record<DisabledStatus, string> = {
+  [DisabledStatus.DISABLED]: '禁用',
+  [DisabledStatus.ENABLED]: '启用'
+};
+
 // 认证上下文类型
 export interface AuthContextType<T> {
   user: T | null;

+ 1 - 1
packages/shared-utils/tsconfig.json

@@ -2,7 +2,7 @@
   "extends": "../../tsconfig.json",
   "compilerOptions": {
     "composite": true,
-    "rootDir": "src",
+    "rootDir": ".",
     "outDir": "dist"
   },
   "include": [

+ 7 - 10
packages/user-module/tests/integration/role.integration.test.ts

@@ -1,29 +1,26 @@
-import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
+import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
 import { DataSource } from 'typeorm';
 import { RoleService } from '../../src/services/role.service';
 import { Role } from '../../src/entities/role.entity';
-import { getTestDataSource } from '@d8d/shared-utils';
+import { AppDataSource, initializeDataSource } from '@d8d/shared-utils';
 
 describe('Role Integration Tests', () => {
   let dataSource: DataSource;
   let roleService: RoleService;
 
-  beforeAll(async () => {
-    dataSource = await getTestDataSource();
+  beforeEach(async () => {
+    initializeDataSource([Role])
+    dataSource = AppDataSource;
+    await dataSource.initialize();
     roleService = new RoleService(dataSource);
   });
 
-  afterAll(async () => {
+  afterEach(async () => {
     if (dataSource.isInitialized) {
       await dataSource.destroy();
     }
   });
 
-  beforeEach(async () => {
-    // Clean up database before each test
-    await dataSource.getRepository(Role).delete({});
-  });
-
   describe('Role CRUD Operations', () => {
     it('should create and retrieve a role', async () => {
       // Create role

+ 8 - 10
packages/user-module/tests/integration/user.integration.test.ts

@@ -1,33 +1,31 @@
-import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
+import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
 import { DataSource } from 'typeorm';
 import { UserService } from '../../src/services/user.service';
 import { RoleService } from '../../src/services/role.service';
 import { UserEntity } from '../../src/entities/user.entity';
 import { Role } from '../../src/entities/role.entity';
-import { getTestDataSource } from '@d8d/shared-utils';
+import { AppDataSource, initializeDataSource } from '@d8d/shared-utils';
 
 describe('User Integration Tests', () => {
   let dataSource: DataSource;
   let userService: UserService;
   let roleService: RoleService;
 
-  beforeAll(async () => {
-    dataSource = await getTestDataSource();
+  beforeEach(async () => {
+    initializeDataSource([UserEntity, Role])
+    dataSource = AppDataSource;
+    await dataSource.initialize();
     userService = new UserService(dataSource);
     roleService = new RoleService(dataSource);
   });
 
-  afterAll(async () => {
+  afterEach(async () => {
     if (dataSource.isInitialized) {
       await dataSource.destroy();
     }
   });
 
-  beforeEach(async () => {
-    // Clean up database before each test
-    await dataSource.getRepository(UserEntity).delete({});
-    await dataSource.getRepository(Role).delete({});
-  });
+
 
   describe('User CRUD Operations', () => {
     it('should create and retrieve a user', async () => {