|
@@ -1,5 +1,5 @@
|
|
|
-import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
|
|
|
-import { IntegrationTestDatabase } from '../../src/integration-test-db';
|
|
|
|
|
|
|
+import { describe, it, expect } from 'vitest';
|
|
|
|
|
+import { IntegrationTestDatabase, setupIntegrationDatabaseHooksWithEntities } from '../../src/integration-test-db';
|
|
|
|
|
|
|
|
// 模拟实体用于测试
|
|
// 模拟实体用于测试
|
|
|
class MockEntity {
|
|
class MockEntity {
|
|
@@ -7,17 +7,10 @@ class MockEntity {
|
|
|
name?: string;
|
|
name?: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-describe('IntegrationTestDatabase', () => {
|
|
|
|
|
- beforeEach(async () => {
|
|
|
|
|
- // 确保数据库已清理
|
|
|
|
|
- await IntegrationTestDatabase.cleanup();
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- afterEach(async () => {
|
|
|
|
|
- // 清理测试数据库
|
|
|
|
|
- await IntegrationTestDatabase.cleanup();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+// 设置集成测试钩子 - 这是关键步骤!
|
|
|
|
|
+setupIntegrationDatabaseHooksWithEntities([MockEntity])
|
|
|
|
|
|
|
|
|
|
+describe('IntegrationTestDatabase', () => {
|
|
|
describe('getDataSource', () => {
|
|
describe('getDataSource', () => {
|
|
|
it('应该返回数据源实例', async () => {
|
|
it('应该返回数据源实例', async () => {
|
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
@@ -66,53 +59,5 @@ describe('IntegrationTestDatabase', () => {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- describe('createTestData', () => {
|
|
|
|
|
- it('应该创建测试数据', async () => {
|
|
|
|
|
- const dataSource = await IntegrationTestDatabase.getDataSource();
|
|
|
|
|
-
|
|
|
|
|
- // 注意:这里只是测试方法调用,实际数据库操作需要真实的实体
|
|
|
|
|
- // 在真实环境中,应该使用具体的实体类
|
|
|
|
|
- const testData = { name: 'test' };
|
|
|
|
|
-
|
|
|
|
|
- // 验证方法存在且可调用
|
|
|
|
|
- expect(IntegrationTestDatabase.createTestData).toBeDefined();
|
|
|
|
|
- expect(typeof IntegrationTestDatabase.createTestData).toBe('function');
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('findTestData', () => {
|
|
|
|
|
- it('应该查找测试数据', async () => {
|
|
|
|
|
- // 验证方法存在且可调用
|
|
|
|
|
- expect(IntegrationTestDatabase.findTestData).toBeDefined();
|
|
|
|
|
- expect(typeof IntegrationTestDatabase.findTestData).toBe('function');
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('deleteTestData', () => {
|
|
|
|
|
- it('应该删除测试数据', async () => {
|
|
|
|
|
- // 验证方法存在且可调用
|
|
|
|
|
- expect(IntegrationTestDatabase.deleteTestData).toBeDefined();
|
|
|
|
|
- expect(typeof IntegrationTestDatabase.deleteTestData).toBe('function');
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- describe('cleanupTable', () => {
|
|
|
|
|
- it('应该清理表数据', async () => {
|
|
|
|
|
- // 验证方法存在且可调用
|
|
|
|
|
- expect(IntegrationTestDatabase.cleanupTable).toBeDefined();
|
|
|
|
|
- expect(typeof IntegrationTestDatabase.cleanupTable).toBe('function');
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
-});
|
|
|
|
|
-
|
|
|
|
|
-describe('setupIntegrationDatabaseHooks', () => {
|
|
|
|
|
- it('应该定义生命周期钩子函数', () => {
|
|
|
|
|
- const hooks = require('../../src/integration-test-db');
|
|
|
|
|
-
|
|
|
|
|
- expect(hooks.setupIntegrationDatabaseHooks).toBeDefined();
|
|
|
|
|
- expect(typeof hooks.setupIntegrationDatabaseHooks).toBe('function');
|
|
|
|
|
-
|
|
|
|
|
- expect(hooks.setupIntegrationDatabaseHooksWithEntities).toBeDefined();
|
|
|
|
|
- expect(typeof hooks.setupIntegrationDatabaseHooksWithEntities).toBe('function');
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
});
|
|
});
|