@@ -35,17 +35,37 @@ type ProjectTestFunction = (args: ProjectTestArgs) => void;
3535export function withProject ( integration : IntegrationTest , fn : ProjectTestFunction ) : void {
3636 describe ( "with project" , ( ) => {
3737 let projectId : string = "" ;
38+ const projectName = `testProj-${ new ObjectId ( ) } ` ;
3839
3940 beforeAll ( async ( ) => {
4041 const apiClient = integration . mcpServer ( ) . session . apiClient ;
4142
42- const group = await createProject ( apiClient ) ;
43+ const group = await createProject ( apiClient , projectName ) ;
4344 projectId = group . id || "" ;
4445 } ) ;
4546
4647 afterAll ( async ( ) => {
4748 const apiClient = integration . mcpServer ( ) . session . apiClient ;
4849
50+ const clusters = await apiClient . listClusters ( {
51+ params : {
52+ path : {
53+ groupId : projectId ,
54+ } ,
55+ } ,
56+ } ) ;
57+
58+ const deletePromises =
59+ clusters ?. results ?. map ( ( cluster ) => {
60+ if ( cluster . name ) {
61+ return deleteAndWaitCluster ( integration . mcpServer ( ) . session , projectId , cluster . name ) ;
62+ }
63+
64+ return Promise . resolve ( ) ;
65+ } ) ?? [ ] ;
66+
67+ await Promise . all ( deletePromises ) ;
68+
4969 await apiClient . deleteProject ( {
5070 params : {
5171 path : {
@@ -55,11 +75,9 @@ export function withProject(integration: IntegrationTest, fn: ProjectTestFunctio
5575 } ) ;
5676 } ) ;
5777
58- const args = {
78+ fn ( {
5979 getProjectId : ( ) => projectId ,
60- } ;
61-
62- fn ( args ) ;
80+ } ) ;
6381 } ) ;
6482}
6583
@@ -81,11 +99,7 @@ export function parseTable(text: string): Record<string, string>[] {
8199 } ) ;
82100}
83101
84- export const randomId = new ObjectId ( ) . toString ( ) ;
85-
86- async function createProject ( apiClient : ApiClient ) : Promise < Group > {
87- const projectName : string = `testProj-` + randomId ;
88-
102+ async function createProject ( apiClient : ApiClient , projectName : string ) : Promise < Group > {
89103 const orgs = await apiClient . listOrganizations ( ) ;
90104 if ( ! orgs ?. results ?. length || ! orgs . results [ 0 ] . id ) {
91105 throw new Error ( "No orgs found" ) ;
@@ -122,7 +136,7 @@ export async function waitClusterState(session: Session, projectId: string, clus
122136 }
123137}
124138
125- export async function deleteAndWaitCluster ( session : Session , projectId : string , clusterName : string ) {
139+ async function deleteAndWaitCluster ( session : Session , projectId : string , clusterName : string ) {
126140 await session . apiClient . deleteCluster ( {
127141 params : {
128142 path : {
0 commit comments