fix: use TestingModule as application context, fix $executeRaw
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s
- TestingModule.compile() returns an application context directly - Use $executeRaw tagged template instead of $executeRawUnsafe - Add jest.setTimeout(30000) for integration tests Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
cfa882a9e9
commit
762a9c1791
@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { INestApplicationContext } from '@nestjs/common';
|
||||
import { WorkerModule } from '../src/worker.module';
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { PrismaService } from '../src/infrastructure/database/prisma.service';
|
||||
@ -46,9 +46,11 @@ import { WorkerHeartbeatService } from '../src/workers/worker-heartbeat.service'
|
||||
// 注意: runtime-internal.service.ts 是 Heavy Runtime (Rust) 链路, 不参与 BullMQ 链路.
|
||||
// Gate 报告若引用 runtime-internal.service.ts 则属于证据错误.
|
||||
|
||||
jest.setTimeout(30_000);
|
||||
|
||||
describe('M-AI-01-09 Integration', () => {
|
||||
let apiApp: INestApplication;
|
||||
let workerApp: INestApplication;
|
||||
let apiApp: INestApplicationContext;
|
||||
let workerApp: INestApplicationContext;
|
||||
let prisma: PrismaService;
|
||||
let redis: RedisService;
|
||||
let queueService: QueueService;
|
||||
@ -65,16 +67,15 @@ describe('M-AI-01-09 Integration', () => {
|
||||
const apiModule: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
apiApp = apiModule.createNestApplication();
|
||||
await apiApp.init();
|
||||
// TestingModule IS an application context — use directly
|
||||
apiApp = apiModule as any;
|
||||
apiApp.enableShutdownHooks();
|
||||
|
||||
// Worker context (Consumer, all Processors)
|
||||
const workerModule: TestingModule = await Test.createTestingModule({
|
||||
imports: [WorkerModule],
|
||||
}).compile();
|
||||
workerApp = workerModule.createNestApplication();
|
||||
await workerApp.init();
|
||||
workerApp = workerModule as any;
|
||||
workerApp.enableShutdownHooks();
|
||||
|
||||
prisma = workerApp.get(PrismaService);
|
||||
@ -145,7 +146,7 @@ describe('M-AI-01-09 Integration', () => {
|
||||
'LearningSession', 'KnowledgeItem', 'KnowledgeBase',
|
||||
];
|
||||
for (const table of tables) {
|
||||
await prisma.$executeRawUnsafe(`DELETE FROM \`${table}\` WHERE userId = ?`, testUserId).catch(() => {});
|
||||
await prisma.$executeRaw`DELETE FROM \`${table}\` WHERE userId = ${testUserId}`.catch(() => {});
|
||||
}
|
||||
await prisma.user.delete({ where: { id: testUserId } }).catch(() => {});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user