Skip to content

Commit

Permalink
Added cypress test case for gitlab-repositories API
Browse files Browse the repository at this point in the history
Signed-off-by: veerendra thakur <[email protected]>
  • Loading branch information
thakurveerendras committed Sep 12, 2023
1 parent b4f5749 commit 1e66f9c
Show file tree
Hide file tree
Showing 3 changed files with 265 additions and 0 deletions.
111 changes: 111 additions & 0 deletions tests/functional/cypress/e2e/gitlab-repositories.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {validateApiResponse,validate_200_Status,getTokenKey} from '../support/commands';

describe("To Validate & Get the GitLab repositories of the project via API call", function () {

// Define a variable for the environment
const environment = Cypress.env("CYPRESS_ENV");

// Import the appropriate configuration based on the environment
let appConfig;
if (environment === 'dev') {
appConfig = require('../appConfig/config.dev.ts').appConfig;
} else if (environment === 'production') {
appConfig = require('../appConfig/config.production.ts').appConfig;
}

//Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/gitlab-organizations
const projectSFID=appConfig.projectSFID; //project name: sun
const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/project/${projectSFID}/gitlab/repositories`;

let gitLabOrgName=appConfig.gitLabOrganizationName;
const gitLabGroupID=appConfig.groupId;
let claGroupId="";
let repoExternalId="";

let bearerToken: string = null;
before(() => {
if(bearerToken==null){
getTokenKey(bearerToken);
cy.window().then((win) => {
bearerToken = win.localStorage.getItem('bearerToken');
});
}
});

it("Get the GitLab repositories of the project", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
validate_200_Status(response);
let list=response.body.list;
for(let i=0;i<=list.length-1;i++){
if(list[i].repository_organization_name===gitLabOrgName){
repoExternalId=list[i].repository_external_id;
claGroupId=list[i].repository_cla_group_id
break;
}
}
//To validate schema of response
validateApiResponse("gitlab-repositories/getProjectGitLabRepositories.json",response.body);
});
});

it("Un-Enrolls 'Enforce CLA' GitLab repositories for the CLA Group", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}`,
auth: {
'bearer': bearerToken,
},
body:{
"cla_group_id": claGroupId,
"unenroll": [
parseInt(repoExternalId, 10)
]
}
}).then((response) => {
validate_200_Status(response);
let list=response.body.list;
for(let i=0;i<=list.length-1;i++){
if(list[i].repository_organization_name===gitLabOrgName){
expect(list[i].enabled).to.eql(false);
break;
}
}
//To validate schema of response
validateApiResponse("gitlab-repositories/enrollGitLabRepository.json",response.body);
});
});

it("Enrolls 'Enforce CLA' GitLab repositories for the CLA Group", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}`,
auth: {
'bearer': bearerToken,
},
body:{
"cla_group_id": claGroupId,
"enroll": [
parseInt(repoExternalId, 10)
]
}
}).then((response) => {
validate_200_Status(response);
let list=response.body.list;
for(let i=0;i<=list.length-1;i++){
if(list[i].repository_organization_name===gitLabOrgName){
expect(list[i].enabled).to.eql(true);
break;
}
}
//To validate schema of response
validateApiResponse("gitlab-repositories/enrollGitLabRepository.json",response.body);
});
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"date_created": {
"type": "string"
},
"date_modified": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"note": {
"type": "string"
},
"repositoryID": {
"type": "string"
},
"repository_cla_group_id": {
"type": "string"
},
"repository_external_id": {
"type": "integer"
},
"repository_full_path": {
"type": "string"
},
"repository_name": {
"type": "string"
},
"repository_organization_name": {
"type": "string"
},
"repository_project_sfid": {
"type": "string"
},
"repository_type": {
"type": "string"
},
"repository_url": {
"type": "string"
},
"version": {
"type": "string"
}
},
"required": [
"date_created",
"date_modified",
"enabled",
"note",
"repositoryID",
"repository_cla_group_id",
"repository_external_id",
"repository_full_path",
"repository_name",
"repository_organization_name",
"repository_project_sfid",
"repository_type",
"repository_url",
"version"
]
}
]
}
},
"required": [
"list"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"date_created": {
"type": "string"
},
"date_modified": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"note": {
"type": "string"
},
"repositoryID": {
"type": "string"
},
"repository_cla_group_id": {
"type": "string"
},
"repository_external_id": {
"type": "integer"
},
"repository_full_path": {
"type": "string"
},
"repository_name": {
"type": "string"
},
"repository_organization_name": {
"type": "string"
},
"repository_project_sfid": {
"type": "string"
},
"repository_type": {
"type": "string"
},
"repository_url": {
"type": "string"
},
"version": {
"type": "string"
}
},
"required": [
"date_created",
"date_modified",
"enabled",
"note",
"repositoryID",
"repository_cla_group_id",
"repository_external_id",
"repository_full_path",
"repository_name",
"repository_organization_name",
"repository_project_sfid",
"repository_type",
"repository_url",
"version"
]
}
]
}
},
"required": [
"list"
]
}

0 comments on commit 1e66f9c

Please sign in to comment.