Skip to content

Commit 86c0904

Browse files
Merge branch 'main' into dev
Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
2 parents 38dee4a + 7661d06 commit 86c0904

2 files changed

Lines changed: 103 additions & 22 deletions

File tree

tests/functional/cypress/e2e/v4/gitlab-repositories.cy.ts

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/functional/cypress/e2e/v4/signatures.cy.ts

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,62 @@ describe('To Validate & get list of signatures of ClaGroups via API call', funct
5959
}
6060
});
6161

62+
const getProjectCompanySignatures = () =>
63+
cy.request({
64+
method: 'GET',
65+
url: `${claEndpoint}signatures/project/${projectSFID}/company/${companyID}`,
66+
timeout: timeout,
67+
failOnStatusCode: allowFail,
68+
headers: getXACLHeader(),
69+
auth: {
70+
bearer: bearerToken,
71+
},
72+
});
73+
74+
const findProjectCompanySignature = (signatures: any[]) =>
75+
signatures.find((item: any) => item.signatureID === signatureCclaID) || signatures[0];
76+
77+
const waitForDomainApprovalListState = (
78+
domain: string,
79+
shouldExist: boolean,
80+
retries: number = 6,
81+
): Cypress.Chainable<any> => {
82+
const attempt = (remaining: number): Cypress.Chainable<any> =>
83+
getProjectCompanySignatures().then((response) => {
84+
validate_200_Status(response);
85+
const signatures = response.body.signatures || [];
86+
const signature = findProjectCompanySignature(signatures);
87+
88+
expect(signature, `CCLA signature ${signatureCclaID} should exist`).to.exist;
89+
90+
const list = signature.domainApprovalList || [];
91+
const isPresent = list.includes(domain);
92+
93+
if (isPresent === shouldExist) {
94+
return cy.wrap(signature);
95+
}
96+
97+
if (remaining === 0) {
98+
if (shouldExist) {
99+
expect(list).to.include(domain);
100+
} else {
101+
expect(list).to.not.include(domain);
102+
}
103+
104+
return cy.wrap(signature);
105+
}
106+
107+
cy.task(
108+
'log',
109+
`Domain ${domain} is currently ${isPresent ? 'present' : 'absent'} in the approval list; waiting for it to be ${shouldExist ? 'present' : 'absent'}`,
110+
);
111+
112+
return cy.wait(2000).then(() => attempt(remaining - 1));
113+
});
114+
115+
return attempt(retries);
116+
};
117+
62118
it('Returns a list of corporate contributor for the CLA Group', function () {
63119
let url = `${claEndpoint}cla-group/${claGroupID}/corporate-contributors?companyID=${companyID}&pageSize=100`;
64120
cy.task('log', 'Returns a list of corporate contributor for the CLA Group URL: ' + url);
@@ -778,8 +834,7 @@ describe('To Validate & get list of signatures of ClaGroups via API call', funct
778834
return cy.logJson('response', response).then(() => {
779835
validate_200_Status(response);
780836
cy.task('log', 'domain ' + domainApprovalList + ' should be added to approval list');
781-
let list = response.body.domainApprovalList;
782-
expect(list).to.include(domainApprovalList);
837+
return waitForDomainApprovalListState(domainApprovalList, true);
783838
});
784839
});
785840
});
@@ -801,10 +856,7 @@ describe('To Validate & get list of signatures of ClaGroups via API call', funct
801856
return cy.logJson('response', response).then(() => {
802857
validate_200_Status(response);
803858
cy.task('log', 'domain ' + domainApprovalList + ' should be removed from approval list');
804-
let list = response.body.domainApprovalList;
805-
if (list != null && list.length > 0) {
806-
expect(list).to.not.include(domainApprovalList);
807-
}
859+
return waitForDomainApprovalListState(domainApprovalList, false);
808860
});
809861
});
810862
});

0 commit comments

Comments
 (0)