fix: Gate E2E — override AdminAuthGuard with mock to resolve Reflector dependency
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 0s
Deploy API Server / m-ai-03-synthetic-e2e (push) Failing after 10s
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 0s
Deploy API Server / m-ai-03-synthetic-e2e (push) Failing after 10s
Deploy API Server / deploy (push) Has been skipped
Test.createTestingModule 不会将 Reflector 传播到子模块 AppConfigModule。 用 overrideGuard(MockAdminAuthGuard) 绕过 AdminAuthGuard 的 Reflector 依赖。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2f5989be49
commit
06e58f2ebe
@ -1,9 +1,14 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { INestApplication, Injectable, CanActivate, ExecutionContext } 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';
|
||||
@ -44,8 +49,10 @@ describe('M-AI-03 GATE E2E (fail-closed)', () => {
|
||||
// AppModule.init() 连接 Prisma + Redis — 失败则测试 fail-closed
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
providers: [Reflector],
|
||||
}).compile();
|
||||
})
|
||||
.overrideGuard(require('../src/common/guards/admin-auth.guard').AdminAuthGuard)
|
||||
.useClass(MockAdminAuthGuard)
|
||||
.compile();
|
||||
|
||||
app = module.createNestApplication();
|
||||
app.setGlobalPrefix('api', { exclude: ['admin-api/(.*)', 'internal/(.*)'] });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user