|
|
@@ -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 () => {
|