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 { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplicationContext } from '@nestjs/common';
|
||||||
import { WorkerModule } from '../src/worker.module';
|
import { WorkerModule } from '../src/worker.module';
|
||||||
import { AppModule } from '../src/app.module';
|
import { AppModule } from '../src/app.module';
|
||||||
import { PrismaService } from '../src/infrastructure/database/prisma.service';
|
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 链路.
|
// 注意: runtime-internal.service.ts 是 Heavy Runtime (Rust) 链路, 不参与 BullMQ 链路.
|
||||||
// Gate 报告若引用 runtime-internal.service.ts 则属于证据错误.
|
// Gate 报告若引用 runtime-internal.service.ts 则属于证据错误.
|
||||||
|
|
||||||
|
jest.setTimeout(30_000);
|
||||||
|
|
||||||
describe('M-AI-01-09 Integration', () => {
|
describe('M-AI-01-09 Integration', () => {
|
||||||
let apiApp: INestApplication;
|
let apiApp: INestApplicationContext;
|
||||||
let workerApp: INestApplication;
|
let workerApp: INestApplicationContext;
|
||||||
let prisma: PrismaService;
|
let prisma: PrismaService;
|
||||||
let redis: RedisService;
|
let redis: RedisService;
|
||||||
let queueService: QueueService;
|
let queueService: QueueService;
|
||||||
@ -65,16 +67,15 @@ describe('M-AI-01-09 Integration', () => {
|
|||||||
const apiModule: TestingModule = await Test.createTestingModule({
|
const apiModule: TestingModule = await Test.createTestingModule({
|
||||||
imports: [AppModule],
|
imports: [AppModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
apiApp = apiModule.createNestApplication();
|
// TestingModule IS an application context — use directly
|
||||||
await apiApp.init();
|
apiApp = apiModule as any;
|
||||||
apiApp.enableShutdownHooks();
|
apiApp.enableShutdownHooks();
|
||||||
|
|
||||||
// Worker context (Consumer, all Processors)
|
// Worker context (Consumer, all Processors)
|
||||||
const workerModule: TestingModule = await Test.createTestingModule({
|
const workerModule: TestingModule = await Test.createTestingModule({
|
||||||
imports: [WorkerModule],
|
imports: [WorkerModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
workerApp = workerModule.createNestApplication();
|
workerApp = workerModule as any;
|
||||||
await workerApp.init();
|
|
||||||
workerApp.enableShutdownHooks();
|
workerApp.enableShutdownHooks();
|
||||||
|
|
||||||
prisma = workerApp.get(PrismaService);
|
prisma = workerApp.get(PrismaService);
|
||||||
@ -145,7 +146,7 @@ describe('M-AI-01-09 Integration', () => {
|
|||||||
'LearningSession', 'KnowledgeItem', 'KnowledgeBase',
|
'LearningSession', 'KnowledgeItem', 'KnowledgeBase',
|
||||||
];
|
];
|
||||||
for (const table of tables) {
|
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(() => {});
|
await prisma.user.delete({ where: { id: testUserId } }).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user