11import { ObjectId } from "mongodb" ;
22import { Group } from "../../../../src/common/atlas/openapi.js" ;
33import { ApiClient } from "../../../../src/common/atlas/apiClient.js" ;
4- import { setupIntegrationTest , IntegrationTest , defaultTestConfig } from "../../helpers.js" ;
4+ import { setupIntegrationTest , IntegrationTest , defaultTestConfig , sleep } from "../../helpers.js" ;
5+ import { Session } from "../../../../src/session.js" ;
56
67export type IntegrationTestFunction = ( integration : IntegrationTest ) => void ;
78
8- export function describeWithAtlas ( name : string , fn : IntegrationTestFunction ) {
9+ export function describeWithAtlas ( name : string , fn : IntegrationTestFunction ) : void {
910 const testDefinition = ( ) => {
1011 const integration = setupIntegrationTest ( ( ) => ( {
1112 ...defaultTestConfig ,
@@ -21,7 +22,8 @@ export function describeWithAtlas(name: string, fn: IntegrationTestFunction) {
2122 if ( ! process . env . MDB_MCP_API_CLIENT_ID ?. length || ! process . env . MDB_MCP_API_CLIENT_SECRET ?. length ) {
2223 return describe . skip ( "atlas" , testDefinition ) ;
2324 }
24- return describe ( "atlas" , testDefinition ) ;
25+
26+ describe ( "atlas" , testDefinition ) ;
2527}
2628
2729interface ProjectTestArgs {
@@ -30,8 +32,8 @@ interface ProjectTestArgs {
3032
3133type ProjectTestFunction = ( args : ProjectTestArgs ) => void ;
3234
33- export function withProject ( integration : IntegrationTest , fn : ProjectTestFunction ) {
34- return describe ( "project" , ( ) => {
35+ export function withProject ( integration : IntegrationTest , fn : ProjectTestFunction ) : void {
36+ describe ( "with project" , ( ) => {
3537 let projectId : string = "" ;
3638
3739 beforeAll ( async ( ) => {
@@ -57,9 +59,7 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
5759 getProjectId : ( ) => projectId ,
5860 } ;
5961
60- describe ( "with project" , ( ) => {
61- fn ( args ) ;
62- } ) ;
62+ fn ( args ) ;
6363 } ) ;
6464}
6565
@@ -104,3 +104,46 @@ async function createProject(apiClient: ApiClient): Promise<Group> {
104104
105105 return group ;
106106}
107+
108+ export async function waitClusterState ( session : Session , projectId : string , clusterName : string , state : string ) {
109+ while ( true ) {
110+ const cluster = await session . apiClient . getCluster ( {
111+ params : {
112+ path : {
113+ groupId : projectId ,
114+ clusterName,
115+ } ,
116+ } ,
117+ } ) ;
118+ if ( cluster ?. stateName === state ) {
119+ return ;
120+ }
121+ await sleep ( 1000 ) ;
122+ }
123+ }
124+
125+ export async function deleteAndWaitCluster ( session : Session , projectId : string , clusterName : string ) {
126+ await session . apiClient . deleteCluster ( {
127+ params : {
128+ path : {
129+ groupId : projectId ,
130+ clusterName,
131+ } ,
132+ } ,
133+ } ) ;
134+ while ( true ) {
135+ try {
136+ await session . apiClient . getCluster ( {
137+ params : {
138+ path : {
139+ groupId : projectId ,
140+ clusterName,
141+ } ,
142+ } ,
143+ } ) ;
144+ await sleep ( 1000 ) ;
145+ } catch {
146+ break ;
147+ }
148+ }
149+ }
0 commit comments