@@ -65,6 +65,79 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
6565 }
6666 } ) ;
6767
68+ let originalClaGroupIdForEnrollProject : string = '' ;
69+
70+ const findClaGroupById = ( list : any [ ] , targetClaGroupId : string ) =>
71+ list . find ( ( item : any ) => item . cla_group_id === targetClaGroupId ) ;
72+
73+ const findProjectBySFID = ( projectList : any [ ] , targetProjectSFID : string ) =>
74+ projectList . find ( ( item : any ) => item . project_sfid === targetProjectSFID ) ;
75+
76+ const prepareEnrollProject = ( ) => {
77+ return cy . request ( {
78+ method : 'GET' ,
79+ url : `${ claEndpoint } foundation/${ projectSfid } /cla-groups` ,
80+ timeout : timeout ,
81+ failOnStatusCode : allowFail ,
82+ headers : getXACLHeader ( ) ,
83+ auth : {
84+ bearer : bearerToken ,
85+ } ,
86+ } ) . then ( ( response ) => {
87+ validate_200_Status ( response ) ;
88+ expect ( response . body ) . to . have . property ( 'list' ) ;
89+
90+ const existingClaGroup = response . body . list . find (
91+ ( item : any ) =>
92+ item . cla_group_id !== claGroupId &&
93+ Array . isArray ( item . project_list ) &&
94+ item . project_list . some ( ( project : any ) => project . project_sfid === enrollProjectsSFID ) ,
95+ ) ;
96+
97+ if ( ! existingClaGroup ) {
98+ originalClaGroupIdForEnrollProject = '' ;
99+ return ;
100+ }
101+
102+ originalClaGroupIdForEnrollProject = existingClaGroup . cla_group_id ;
103+
104+ return cy . request ( {
105+ method : 'PUT' ,
106+ url : `${ claEndpoint } cla-group/${ originalClaGroupIdForEnrollProject } /unenroll-projects` ,
107+ timeout : timeout ,
108+ failOnStatusCode : false ,
109+ headers : getXACLHeader ( ) ,
110+ auth : {
111+ bearer : bearerToken ,
112+ } ,
113+ body : [ enrollProjectsSFID ] ,
114+ } ) . then ( ( unenrollResponse ) => {
115+ expect ( unenrollResponse . status ) . to . be . oneOf ( [ 200 , 400 ] ) ;
116+ } ) ;
117+ } ) ;
118+ } ;
119+
120+ const restoreEnrollProject = ( ) => {
121+ if ( ! originalClaGroupIdForEnrollProject ) {
122+ return cy . wrap ( null ) ;
123+ }
124+
125+ return cy . request ( {
126+ method : 'PUT' ,
127+ url : `${ claEndpoint } cla-group/${ originalClaGroupIdForEnrollProject } /enroll-projects` ,
128+ timeout : timeout ,
129+ failOnStatusCode : false ,
130+ headers : getXACLHeader ( ) ,
131+ auth : {
132+ bearer : bearerToken ,
133+ } ,
134+ body : [ enrollProjectsSFID ] ,
135+ } ) . then ( ( response ) => {
136+ expect ( response . status ) . to . be . oneOf ( [ 200 , 400 ] ) ;
137+ originalClaGroupIdForEnrollProject = '' ;
138+ } ) ;
139+ } ;
140+
68141 describe ( 'Expected failures' , ( ) => {
69142 it ( 'Returns 401 for all CLA APIs when called without token' , function ( ) {
70143 const dummyClaGroupId = '00000000-0000-0000-0000-000000000000' ;
@@ -569,9 +642,11 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
569642
570643 // Validate specific data in the response
571644 expect ( response . body ) . to . have . property ( 'list' ) ;
572- let list = response . body . list ;
573- claGroupId = list [ 0 ] . cla_group_id ;
574- expect ( list [ 0 ] . cla_group_name ) . to . eql ( cla_group_name ) ;
645+ const list = response . body . list ;
646+ const createdClaGroup = findClaGroupById ( list , claGroupId ) ;
647+
648+ expect ( createdClaGroup , `CLA group ${ claGroupId } should exist in foundation list` ) . to . exist ;
649+ expect ( createdClaGroup . cla_group_name ) . to . eql ( cla_group_name ) ;
575650
576651 //To validate schema of response
577652 validateApiResponse ( 'claGroup/list_claGroup.json' , response . body ) ;
@@ -624,43 +699,53 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
624699 } ) ;
625700 } ) ;
626701
627- it ( 'Enroll projects in a CLA Group - Record should return 200 Response' , function ( ) {
628- cy . request ( {
629- method : 'PUT' ,
630- url : `${ claEndpoint } cla-group/${ claGroupId } /enroll-projects` ,
631- timeout : timeout ,
632- failOnStatusCode : allowFail ,
633- headers : getXACLHeader ( ) ,
634- auth : {
635- bearer : bearerToken ,
636- } ,
637- body : [ enrollProjectsSFID ] ,
638- } ) . then ( ( response ) => {
639- // expect(response.duration).to.be.lessThan(20000);
640- validate_200_Status ( response ) ;
641- // Check if the first API response status is 200
642- if ( response . status === 200 ) {
643- // Run the second API request
644- cy . request ( {
645- method : 'GET' ,
646- url : `${ claEndpoint } foundation/${ projectSfid } /cla-groups` ,
647- timeout : timeout ,
648- failOnStatusCode : allowFail ,
649- headers : getXACLHeader ( ) ,
650- auth : {
651- bearer : bearerToken ,
652- } ,
653- } ) . then ( ( secondResponse ) => {
654- // Validate specific data in the response
655- expect ( secondResponse . body ) . to . have . property ( 'list' ) ;
656- let list = secondResponse . body . list ;
657- expect ( list [ 0 ] . project_list [ 1 ] . project_name ) . to . eql ( child_Project_name ) ;
658- expect ( list [ 0 ] . project_list [ 1 ] . project_sfid ) . to . eql ( enrollProjectsSFID ) ;
659- expect ( list [ 0 ] . project_list [ 0 ] . project_sfid ) . to . eql ( projectSfid ) ;
660- } ) ;
661- } else {
662- console . log ( 'First API request did not return a 200 status.' ) ;
663- }
702+ it . skip ( 'Enroll projects in a CLA Group - Record should return 200 Response' , function ( ) {
703+ prepareEnrollProject ( ) . then ( ( ) => {
704+ cy . request ( {
705+ method : 'PUT' ,
706+ url : `${ claEndpoint } cla-group/${ claGroupId } /enroll-projects` ,
707+ timeout : timeout ,
708+ failOnStatusCode : allowFail ,
709+ headers : getXACLHeader ( ) ,
710+ auth : {
711+ bearer : bearerToken ,
712+ } ,
713+ body : [ enrollProjectsSFID ] ,
714+ } ) . then ( ( response ) => {
715+ // expect(response.duration).to.be.lessThan(20000);
716+ validate_200_Status ( response ) ;
717+
718+ // Check if the first API response status is 200
719+ if ( response . status === 200 ) {
720+ // Run the second API request
721+ cy . request ( {
722+ method : 'GET' ,
723+ url : `${ claEndpoint } foundation/${ projectSfid } /cla-groups` ,
724+ timeout : timeout ,
725+ failOnStatusCode : allowFail ,
726+ headers : getXACLHeader ( ) ,
727+ auth : {
728+ bearer : bearerToken ,
729+ } ,
730+ } ) . then ( ( secondResponse ) => {
731+ // Validate specific data in the response
732+ expect ( secondResponse . body ) . to . have . property ( 'list' ) ;
733+ const list = secondResponse . body . list ;
734+ const updatedClaGroup = findClaGroupById ( list , claGroupId ) ;
735+ const rootProject = updatedClaGroup ? findProjectBySFID ( updatedClaGroup . project_list , projectSfid ) : null ;
736+ const enrolledProject = updatedClaGroup
737+ ? findProjectBySFID ( updatedClaGroup . project_list , enrollProjectsSFID )
738+ : null ;
739+
740+ expect ( updatedClaGroup , `CLA group ${ claGroupId } should exist in foundation list` ) . to . exist ;
741+ expect ( rootProject , `Root project ${ projectSfid } should still be associated with the CLA group` ) . to . exist ;
742+ expect ( enrolledProject , `Project ${ enrollProjectsSFID } should be enrolled in the CLA group` ) . to . exist ;
743+ expect ( enrolledProject . project_name ) . to . eql ( child_Project_name ) ;
744+ } ) ;
745+ } else {
746+ console . log ( 'First API request did not return a 200 status.' ) ;
747+ }
748+ } ) ;
664749 } ) ;
665750 } ) ;
666751
@@ -678,6 +763,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
678763 } ) . then ( ( response ) => {
679764 // expect(response.duration).to.be.lessThan(20000);
680765 validate_200_Status ( response ) ;
766+ return restoreEnrollProject ( ) ;
681767 } ) ;
682768 } ) ;
683769
@@ -752,9 +838,11 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
752838 } ,
753839 } ) . then ( ( secondResponse ) => {
754840 // Validate specific data in the response
755- cy . wrap ( secondResponse . body . list )
756- . should ( 'be.an' , 'array' ) // Check if the response is an array
757- . and ( 'have.length' , 0 ) ;
841+ expect ( secondResponse . body ) . to . have . property ( 'list' ) ;
842+ const list = secondResponse . body . list ;
843+ const deletedClaGroup = findClaGroupById ( list , claGroupId ) ;
844+
845+ expect ( deletedClaGroup , `CLA group ${ claGroupId } should be deleted` ) . to . not . exist ;
758846 } ) ;
759847 } else {
760848 console . log ( 'First API request did not return a 204 status.' ) ;
@@ -765,3 +853,4 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
765853 }
766854 } ) ;
767855} ) ;
856+
0 commit comments