@@ -7,11 +7,6 @@ global.fetch = mockFetch as any;
77
88// Mock config module
99vi . mock ( '../utils/config.js' , ( ) => ( {
10- getApiUrl : vi . fn ( async ( override ?: string ) => override || 'http://localhost:3002' ) ,
11- getAgentsManageApiUrl : vi . fn ( async ( override ?: string ) => override || 'http://localhost:3002' ) ,
12- getAgentsRunApiUrl : vi . fn ( async ( override ?: string ) => override || 'http://localhost:3003' ) ,
13- getTenantId : vi . fn ( async ( ) => 'test-tenant-id' ) ,
14- getProjectId : vi . fn ( async ( ) => 'test-project-id' ) ,
1510 loadConfig : vi . fn ( ) ,
1611 validateConfiguration : vi . fn ( async ( ) => ( {
1712 tenantId : 'test-tenant-id' ,
@@ -32,8 +27,18 @@ describe('ApiClient', () => {
3227 let executionApiClient : ExecutionApiClient ;
3328
3429 beforeEach ( async ( ) => {
35- apiClient = await ManagementApiClient . create ( ) ;
36- executionApiClient = await ExecutionApiClient . create ( ) ;
30+ apiClient = await ManagementApiClient . create (
31+ undefined ,
32+ undefined ,
33+ undefined ,
34+ 'test-project-id'
35+ ) ;
36+ executionApiClient = await ExecutionApiClient . create (
37+ undefined ,
38+ undefined ,
39+ undefined ,
40+ 'test-project-id'
41+ ) ;
3742 mockFetch . mockClear ( ) ;
3843 vi . clearAllMocks ( ) ;
3944 } ) ;
@@ -75,6 +80,7 @@ describe('ApiClient', () => {
7580 method : 'GET' ,
7681 headers : {
7782 'Content-Type' : 'application/json' ,
83+ Accept : 'application/json' ,
7884 } ,
7985 }
8086 ) ;
@@ -101,8 +107,20 @@ describe('ApiClient', () => {
101107 } ) ;
102108
103109 it ( 'should throw error when tenant ID is not configured' , async ( ) => {
104- const { getTenantId } = await import ( '../utils/config.js' ) ;
105- vi . mocked ( getTenantId ) . mockResolvedValueOnce ( undefined ) ;
110+ const { validateConfiguration } = await import ( '../utils/config.js' ) ;
111+ // Mock validateConfiguration to return a config with empty tenant ID
112+ vi . mocked ( validateConfiguration ) . mockResolvedValueOnce ( {
113+ tenantId : '' ,
114+ agentsManageApiUrl : 'http://localhost:3002' ,
115+ agentsRunApiUrl : 'http://localhost:3003' ,
116+ agentsManageApiKey : undefined ,
117+ agentsRunApiKey : undefined ,
118+ sources : {
119+ tenantId : 'test' ,
120+ agentsManageApiUrl : 'test' ,
121+ agentsRunApiUrl : 'test' ,
122+ } ,
123+ } ) ;
106124
107125 const client = await ManagementApiClient . create ( ) ;
108126
@@ -126,7 +144,12 @@ describe('ApiClient', () => {
126144 } ,
127145 } ) ;
128146
129- const clientWithApiKey = await ManagementApiClient . create ( ) ;
147+ const clientWithApiKey = await ManagementApiClient . create (
148+ undefined ,
149+ undefined ,
150+ undefined ,
151+ 'test-project-id'
152+ ) ;
130153
131154 const mockGraphs = [ { id : 'graph1' , name : 'Test Graph 1' } ] ;
132155 mockFetch . mockResolvedValueOnce ( {
@@ -142,6 +165,7 @@ describe('ApiClient', () => {
142165 method : 'GET' ,
143166 headers : {
144167 'Content-Type' : 'application/json' ,
168+ Accept : 'application/json' ,
145169 Authorization : 'Bearer test-api-key-123' ,
146170 } ,
147171 }
@@ -207,6 +231,7 @@ describe('ApiClient', () => {
207231 method : 'PUT' ,
208232 headers : {
209233 'Content-Type' : 'application/json' ,
234+ Accept : 'application/json' ,
210235 } ,
211236 body : JSON . stringify ( {
212237 ...graphDefinition ,
@@ -260,7 +285,12 @@ describe('ApiClient', () => {
260285 } ,
261286 } ) ;
262287
263- const clientWithApiKey = await ManagementApiClient . create ( ) ;
288+ const clientWithApiKey = await ManagementApiClient . create (
289+ undefined ,
290+ undefined ,
291+ undefined ,
292+ 'test-project-id'
293+ ) ;
264294
265295 const graphDefinition = {
266296 id : 'test-graph' ,
@@ -280,6 +310,7 @@ describe('ApiClient', () => {
280310 method : 'PUT' ,
281311 headers : {
282312 'Content-Type' : 'application/json' ,
313+ Accept : 'application/json' ,
283314 Authorization : 'Bearer test-manage-key-456' ,
284315 } ,
285316 body : JSON . stringify ( {
@@ -427,7 +458,12 @@ describe('ApiClient', () => {
427458 } ,
428459 } ) ;
429460
430- const clientWithApiKey = await ExecutionApiClient . create ( ) ;
461+ const clientWithApiKey = await ExecutionApiClient . create (
462+ undefined ,
463+ undefined ,
464+ undefined ,
465+ 'test-project-id'
466+ ) ;
431467
432468 const messages = [ { role : 'user' , content : 'Hello' } ] ;
433469 const mockStream = new ReadableStream ( ) ;
@@ -442,33 +478,42 @@ describe('ApiClient', () => {
442478
443479 await clientWithApiKey . chatCompletion ( 'test-graph' , messages ) ;
444480
445- expect ( mockFetch ) . toHaveBeenCalledWith (
446- 'http://localhost:3003/v1/chat/completions' ,
447- {
448- method : 'POST' ,
449- headers : {
450- 'Content-Type' : 'application/json' ,
451- Accept : 'text/event-stream' ,
452- Authorization : 'Bearer test-run-key-789' ,
453- 'x-inkeep-tenant-id' : 'test-tenant-id' ,
454- 'x-inkeep-project-id' : 'test-project-id' ,
455- 'x-inkeep-graph-id' : 'test-graph' ,
456- } ,
457- body : JSON . stringify ( {
458- model : 'gpt-4o-mini' ,
459- messages,
460- conversationId : undefined ,
461- stream : true ,
462- } ) ,
463- }
464- ) ;
481+ expect ( mockFetch ) . toHaveBeenCalledWith ( 'http://localhost:3003/v1/chat/completions' , {
482+ method : 'POST' ,
483+ headers : {
484+ 'Content-Type' : 'application/json' ,
485+ Accept : 'text/event-stream' ,
486+ Authorization : 'Bearer test-run-key-789' ,
487+ 'x-inkeep-tenant-id' : 'test-tenant-id' ,
488+ 'x-inkeep-project-id' : 'test-project-id' ,
489+ 'x-inkeep-graph-id' : 'test-graph' ,
490+ } ,
491+ body : JSON . stringify ( {
492+ model : 'gpt-4o-mini' ,
493+ messages,
494+ conversationId : undefined ,
495+ stream : true ,
496+ } ) ,
497+ } ) ;
465498 } ) ;
466499 } ) ;
467500
468501 describe ( 'checkTenantId' , ( ) => {
469502 it ( 'should throw error for all methods when tenant ID is not configured' , async ( ) => {
470- const { getTenantId } = await import ( '../utils/config.js' ) ;
471- vi . mocked ( getTenantId ) . mockResolvedValue ( undefined ) ;
503+ const { validateConfiguration } = await import ( '../utils/config.js' ) ;
504+ // Mock validateConfiguration to return a config with no tenant ID
505+ vi . mocked ( validateConfiguration ) . mockResolvedValue ( {
506+ tenantId : '' ,
507+ agentsManageApiUrl : 'http://localhost:3002' ,
508+ agentsRunApiUrl : 'http://localhost:3003' ,
509+ agentsManageApiKey : undefined ,
510+ agentsRunApiKey : undefined ,
511+ sources : {
512+ tenantId : 'test' ,
513+ agentsManageApiUrl : 'test' ,
514+ agentsRunApiUrl : 'test' ,
515+ } ,
516+ } ) ;
472517
473518 const client = await ManagementApiClient . create ( ) ;
474519 const execClient = await ExecutionApiClient . create ( ) ;
0 commit comments