@@ -7,7 +7,9 @@ import fs from "fs/promises";
77import { Session } from "../../src/session.js" ;
88import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
99import { MongoClient } from "mongodb" ;
10+ import { ApiClient } from "../../src/common/atlas/apiClient.js" ;
1011import { toIncludeAllMembers } from "jest-extended" ;
12+ import { Group } from "../../src/common/atlas/openapi.js" ;
1113
1214interface ParameterInfo {
1315 name : string ;
@@ -21,6 +23,7 @@ type ToolInfo = Awaited<ReturnType<Client["listTools"]>>["tools"][number];
2123export function jestTestMCPClient ( ) : ( ) => Client {
2224 let client : Client | undefined ;
2325 let server : Server | undefined ;
26+ let session : Session | undefined ;
2427
2528 beforeEach ( async ( ) => {
2629 const clientTransport = new InMemoryTransport ( ) ;
@@ -42,13 +45,16 @@ export function jestTestMCPClient(): () => Client {
4245 }
4346 ) ;
4447
48+ session = jestTestSession ( ) ;
49+
4550 server = new Server ( {
4651 mcpServer : new McpServer ( {
4752 name : "test-server" ,
4853 version : "1.2.3" ,
4954 } ) ,
50- session : new Session ( ) ,
55+ session,
5156 } ) ;
57+
5258 await server . connect ( serverTransport ) ;
5359 await client . connect ( clientTransport ) ;
5460 } ) ;
@@ -59,13 +65,15 @@ export function jestTestMCPClient(): () => Client {
5965
6066 await server ?. close ( ) ;
6167 server = undefined ;
68+
69+ session = undefined ;
70+ jest . restoreAllMocks ( ) ;
6271 } ) ;
6372
6473 return ( ) => {
6574 if ( ! client ) {
6675 throw new Error ( "beforeEach() hook not ran yet" ) ;
6776 }
68-
6977 return client ;
7078 } ;
7179}
@@ -196,3 +204,48 @@ export function validateParameters(tool: ToolInfo, parameters: ParameterInfo[]):
196204 expect ( toolParameters ) . toHaveLength ( parameters . length ) ;
197205 expect ( toolParameters ) . toIncludeAllMembers ( parameters ) ;
198206}
207+
208+ const jestTestAtlasData = {
209+ project : {
210+ id : "test-project-id" ,
211+ name : "test-project" ,
212+ orgId : "test-org-id" ,
213+ clusterCount : 0 ,
214+ created : new Date ( ) . toISOString ( ) ,
215+ regionUsageRestrictions : "COMMERCIAL_FEDRAMP_REGIONS_ONLY" as const ,
216+ withDefaultAlertsSettings : true ,
217+ } satisfies Group ,
218+ projects : {
219+ results : [ ] ,
220+ totalCount : 0 ,
221+ } ,
222+ } ;
223+
224+ function jestTestAtlasClient ( ) : ApiClient {
225+ const apiClient = new ApiClient ( {
226+ baseUrl : "http://localhost:3000" ,
227+ userAgent : "AtlasMCP-Test" ,
228+ credentials : {
229+ clientId : "test-client-id" ,
230+ clientSecret : "test-client-secret" ,
231+ } ,
232+ } ) ;
233+
234+ jest . spyOn ( apiClient , "createProject" ) . mockResolvedValue ( jestTestAtlasData . project ) ;
235+ jest . spyOn ( apiClient , "listProjects" ) . mockResolvedValue ( jestTestAtlasData . projects ) ;
236+ jest . spyOn ( apiClient , "getProject" ) . mockResolvedValue ( jestTestAtlasData . project ) ;
237+
238+ return apiClient ;
239+ }
240+
241+ function jestTestSession ( ) : Session {
242+ const session = new Session ( ) ;
243+ const apiClient = jestTestAtlasClient ( ) ;
244+
245+ Object . defineProperty ( session , "apiClient" , {
246+ get : ( ) => apiClient ,
247+ configurable : true ,
248+ } ) ;
249+
250+ return session ;
251+ }
0 commit comments