@@ -45,7 +45,7 @@ describe('To Validate & Get the GitLab repositories of the project via API call'
4545 }
4646 } ) ;
4747
48- it ( 'Get the GitLab repositories of the project' , function ( ) {
48+ const getGitLabRepositories = ( ) =>
4949 cy . request ( {
5050 method : 'GET' ,
5151 url : `${ claEndpoint } ` ,
@@ -55,7 +55,46 @@ describe('To Validate & Get the GitLab repositories of the project via API call'
5555 auth : {
5656 bearer : bearerToken ,
5757 } ,
58- } ) . then ( ( response ) => {
58+ } ) ;
59+
60+ const findGitLabRepositoryByExternalId = ( list : any [ ] , targetRepositoryExternalId : string ) =>
61+ list . find ( ( item : any ) => `${ item . repository_external_id } ` === `${ targetRepositoryExternalId } ` ) ;
62+
63+ const waitForGitLabRepositoryState = (
64+ targetRepositoryExternalId : string ,
65+ expectedEnabled : boolean ,
66+ retries : number = 6 ,
67+ ) : Cypress . Chainable < any > => {
68+ const attempt = ( remaining : number ) : Cypress . Chainable < any > =>
69+ getGitLabRepositories ( ) . then ( ( response ) => {
70+ validate_200_Status ( response ) ;
71+ const list = response . body . list || [ ] ;
72+ const repository = findGitLabRepositoryByExternalId ( list , targetRepositoryExternalId ) ;
73+
74+ expect ( repository , `GitLab repository ${ targetRepositoryExternalId } should exist` ) . to . exist ;
75+
76+ if ( repository . enabled === expectedEnabled ) {
77+ return cy . wrap ( repository ) ;
78+ }
79+
80+ if ( remaining === 0 ) {
81+ expect ( repository . enabled ) . to . eql ( expectedEnabled ) ;
82+ return cy . wrap ( repository ) ;
83+ }
84+
85+ cy . task (
86+ 'log' ,
87+ `GitLab repository ${ targetRepositoryExternalId } currently has enabled=${ repository . enabled } ; waiting for enabled=${ expectedEnabled } ` ,
88+ ) ;
89+
90+ return cy . wait ( 2000 ) . then ( ( ) => attempt ( remaining - 1 ) ) ;
91+ } ) ;
92+
93+ return attempt ( retries ) ;
94+ } ;
95+
96+ it ( 'Get the GitLab repositories of the project' , function ( ) {
97+ getGitLabRepositories ( ) . then ( ( response ) => {
5998 validate_200_Status ( response ) ;
6099 let list = response . body . list ;
61100 for ( let i = 0 ; i <= list . length - 1 ; i ++ ) {
@@ -65,6 +104,8 @@ describe('To Validate & Get the GitLab repositories of the project via API call'
65104 break ;
66105 }
67106 }
107+ expect ( repoExternalId , `expected a GitLab repository under organization ${ gitLabOrgName } ` ) . to . not . eql ( '' ) ;
108+ expect ( claGroupId , `expected a CLA group for organization ${ gitLabOrgName } ` ) . to . not . eql ( '' ) ;
68109 //To validate schema of response
69110 validateApiResponse ( 'gitlab-repositories/getProjectGitLabRepositories.json' , response . body ) ;
70111 } ) ;
@@ -86,15 +127,9 @@ describe('To Validate & Get the GitLab repositories of the project via API call'
86127 } ,
87128 } ) . then ( ( response ) => {
88129 validate_200_Status ( response ) ;
89- let list = response . body . list ;
90- for ( let i = 0 ; i <= list . length - 1 ; i ++ ) {
91- if ( list [ i ] . repository_organization_name === gitLabOrgName ) {
92- expect ( list [ i ] . enabled ) . to . eql ( false ) ;
93- break ;
94- }
95- }
96130 //To validate schema of response
97131 validateApiResponse ( 'gitlab-repositories/enrollGitLabRepository.json' , response . body ) ;
132+ return waitForGitLabRepositoryState ( repoExternalId , false ) ;
98133 } ) ;
99134 } ) ;
100135
@@ -114,15 +149,9 @@ describe('To Validate & Get the GitLab repositories of the project via API call'
114149 } ,
115150 } ) . then ( ( response ) => {
116151 validate_200_Status ( response ) ;
117- let list = response . body . list ;
118- for ( let i = 0 ; i <= list . length - 1 ; i ++ ) {
119- if ( list [ i ] . repository_organization_name === gitLabOrgName ) {
120- expect ( list [ i ] . enabled ) . to . eql ( true ) ;
121- break ;
122- }
123- }
124152 //To validate schema of response
125153 validateApiResponse ( 'gitlab-repositories/enrollGitLabRepository.json' , response . body ) ;
154+ return waitForGitLabRepositoryState ( repoExternalId , true ) ;
126155 } ) ;
127156 } ) ;
128157
0 commit comments