fix: Gate E2E — NestFactory.create 替代 Test.createTestingModule
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 34s
Deploy API Server / current-integration (push) Successful in 30s
Deploy API Server / backward-compat (push) Successful in 1s
Deploy API Server / m-ai-03-synthetic-e2e (push) Failing after 11s
Deploy API Server / deploy (push) Has been skipped
Some checks failed
Deploy API Server / build-and-unit (push) Successful in 34s
Deploy API Server / current-integration (push) Successful in 30s
Deploy API Server / backward-compat (push) Successful in 1s
Deploy API Server / m-ai-03-synthetic-e2e (push) Failing after 11s
Deploy API Server / deploy (push) Has been skipped
Test.createTestingModule 不提供全局 Reflector 给子模块 AppConfigModule, 导致 AdminAuthGuard 依赖解析失败。 NestFactory.create 正确初始化所有 @nestjs/core 全局 providers。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
06e58f2ebe
commit
817b17bf9e
@ -1,14 +1,8 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication, Injectable, CanActivate, ExecutionContext } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import request from 'supertest';
|
||||
import { AppModule } from '../src/app.module';
|
||||
|
||||
// Mock AdminAuthGuard — Test.createTestingModule 不提供 Reflector 给子模块
|
||||
@Injectable()
|
||||
class MockAdminAuthGuard implements CanActivate {
|
||||
canActivate(_context: ExecutionContext): boolean { return true; }
|
||||
}
|
||||
import { AiJobCreationService } from '../src/modules/ai-job/ai-job-creation.service';
|
||||
import { JobDefinitionRegistry } from '../src/modules/ai-job/job-definition-registry';
|
||||
import { AiJobLifecycleRepository } from '../src/modules/ai-job/ai-job-lifecycle.repository';
|
||||
@ -46,22 +40,15 @@ describe('M-AI-03 GATE E2E (fail-closed)', () => {
|
||||
process.env.AI_JOB_SYNTHETIC_ENABLED = 'true';
|
||||
process.env.JWT_SECRET = 'gate-e2e-secret';
|
||||
|
||||
// AppModule.init() 连接 Prisma + Redis — 失败则测试 fail-closed
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
})
|
||||
.overrideGuard(require('../src/common/guards/admin-auth.guard').AdminAuthGuard)
|
||||
.useClass(MockAdminAuthGuard)
|
||||
.compile();
|
||||
|
||||
app = module.createNestApplication();
|
||||
app.setGlobalPrefix('api', { exclude: ['admin-api/(.*)', 'internal/(.*)'] });
|
||||
// NestFactory.create 提供所有 core providers (Reflector etc.)
|
||||
// 连接 Prisma + Redis — 失败则测试 fail-closed
|
||||
app = await NestFactory.create(AppModule);
|
||||
await app.init();
|
||||
|
||||
creationService = module.get(AiJobCreationService);
|
||||
registry = module.get(JobDefinitionRegistry);
|
||||
lifecycleRepo = module.get(AiJobLifecycleRepository);
|
||||
jwtService = module.get(JwtService);
|
||||
creationService = app.get(AiJobCreationService);
|
||||
registry = app.get(JobDefinitionRegistry);
|
||||
lifecycleRepo = app.get(AiJobLifecycleRepository);
|
||||
jwtService = app.get(JwtService);
|
||||
|
||||
userToken = jwtService.sign({ sub: TEST_USER, email: 'gate@test.com', role: 'USER', type: 'user' });
|
||||
}, 30000);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user