Skip to content

Commit ccae910

Browse files
Merge branch 'dev' into unicron-rewrite-py2go
Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
2 parents 5d628cc + 86c0904 commit ccae910

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
@@ -60,6 +60,62 @@ describe('To Validate & get list of signatures of ClaGroups via API call', funct
6060
}
6161
});
6262

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

0 commit comments

Comments
 (0)