Skip to content

Commit 2918958

Browse files
committed
fix(test): mock AnalyticsModule in MCP integration test
The AnalyticsModule's controller and services depend on ConfigService and OpenSearchClient which aren't available in the MCP test module. Use overrideModule to replace the entire AnalyticsModule with mocks. Also add explicit ConfigModule import to AnalyticsModule. Signed-off-by: Aseem Shrey <LuD1161@users.noreply.github.com>
1 parent 283d37a commit 2918958

3 files changed

Lines changed: 63 additions & 24 deletions

File tree

backend/src/analytics/analytics.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Module } from '@nestjs/common';
2+
import { ConfigModule } from '@nestjs/config';
23
import { AnalyticsService } from './analytics.service';
34
import { SecurityAnalyticsService } from './security-analytics.service';
45
import { OrganizationSettingsService } from './organization-settings.service';
56
import { OpenSearchTenantService } from './opensearch-tenant.service';
67
import { AnalyticsController } from './analytics.controller';
78

89
@Module({
10+
imports: [ConfigModule],
911
controllers: [AnalyticsController],
1012
providers: [
1113
AnalyticsService,

backend/src/mcp/__tests__/mcp-internal.integration.spec.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { AuthService } from '../../auth/auth.service';
88
import { AuthGuard } from '../../auth/auth.guard';
99
import { ApiKeysService } from '../../api-keys/api-keys.service';
1010
import { AnalyticsService } from '../../analytics/analytics.service';
11+
import { OpenSearchTenantService } from '../../analytics/opensearch-tenant.service';
12+
import { SecurityAnalyticsService } from '../../analytics/security-analytics.service';
13+
import { OrganizationSettingsService } from '../../analytics/organization-settings.service';
14+
import { AnalyticsModule } from '../../analytics/analytics.module';
1115
import { AgentTraceIngestService } from '../../agent-trace/agent-trace-ingest.service';
1216
import { EventIngestService } from '../../events/event-ingest.service';
1317
import { LogIngestService } from '../../logging/log-ingest.service';
@@ -68,6 +72,39 @@ describe('MCP Internal API (Integration)', () => {
6872
const moduleFixture: TestingModule = await Test.createTestingModule({
6973
imports: [ConfigModule.forRoot({ isGlobal: true, ignoreEnvFile: true }), McpModule],
7074
})
75+
.overrideModule(AnalyticsModule)
76+
.useModule(
77+
class MockAnalyticsModule {
78+
static providers = [
79+
{
80+
provide: AnalyticsService,
81+
useValue: {
82+
isEnabled: () => false,
83+
track: () => {},
84+
trackWorkflowStarted: () => {},
85+
trackWorkflowCompleted: () => {},
86+
trackApiCall: () => {},
87+
trackComponentExecuted: () => {},
88+
},
89+
},
90+
{
91+
provide: OpenSearchTenantService,
92+
useValue: { provisionTenant: async () => true },
93+
},
94+
{
95+
provide: SecurityAnalyticsService,
96+
useValue: { indexDocument: async () => {}, bulkIndexDocuments: async () => {} },
97+
},
98+
{
99+
provide: OrganizationSettingsService,
100+
useValue: {
101+
getOrganizationSettings: async () => ({}),
102+
updateOrganizationSettings: async () => ({}),
103+
},
104+
},
105+
];
106+
},
107+
)
71108
.overrideProvider(NodeIOIngestService)
72109
.useValue({
73110
onModuleInit: async () => {},
@@ -96,15 +133,6 @@ describe('MCP Internal API (Integration)', () => {
96133
})
97134
.overrideProvider(McpGatewayService)
98135
.useValue(mockGatewayService)
99-
.overrideProvider(AnalyticsService)
100-
.useValue({
101-
isEnabled: () => false,
102-
track: () => {},
103-
trackWorkflowStarted: () => {},
104-
trackWorkflowCompleted: () => {},
105-
trackApiCall: () => {},
106-
trackComponentExecuted: () => {},
107-
})
108136
.overrideProvider(AuthService)
109137
.useValue({
110138
authenticate: async () => {

bun.lock

Lines changed: 24 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)