Skip to content

Commit

Permalink
Merge pull request #4128 from communitybridge/cypress-gitlab-organiza…
Browse files Browse the repository at this point in the history
…tions

Cypress test case for gitlab-organizations
  • Loading branch information
nickmango authored Sep 11, 2023
2 parents acf1767 + b4f5749 commit 5d59ba2
Show file tree
Hide file tree
Showing 7 changed files with 586 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/functional/cypress/appConfig/config.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ export const appConfig = {

/* project */
projectName:'easyAutom-child2',

/* GitLab-Organization*/
gitLabOrganizationName:'sunGitlabGroup',
gitLabOrganizationFullPath:'https://gitlab.com/cla_dev_automationgroup',
groupId:'72539854',
};
134 changes: 134 additions & 0 deletions tests/functional/cypress/e2e/gitlab-organizations.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import {validateApiResponse,validate_200_Status,getTokenKey} from '../support/commands';

describe("To Validate & get list of gitlab-organizations 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 claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4`;
const projectSFID=appConfig.projectSFID; //project name: sun
let gitLabOrgName=appConfig.gitLabOrganizationName;
const gitLabGroupID=appConfig.groupId;
let gitLabOrganizationFullPath=appConfig.gitLabOrganizationFullPath;// it will update on POST request
let claGroupId="";
let organizationExternalId="";

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

it("Get the Gitlab organizations of the project", function () {
getGitLabGroupMembers();
});

it("List members of a given GitLab group", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}/gitlab/group/${organizationExternalId}/members`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
validate_200_Status(response);
//To validate schema of response
validateApiResponse("gitlab-organizations/getGitLabGroupMembers.json",response.body);
});
});

it("Update Gitlab Group/Organization Configuration", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}/project/${projectSFID}/gitlab/group/${gitLabGroupID}/config`,
auth: {
'bearer': bearerToken,
},
body:{
"auto_enabled": true,
"auto_enabled_cla_group_id": claGroupId,
"branch_protection_enabled": true
}
}).then((response) => {
validate_200_Status(response);
//To validate schema of response
validateApiResponse("gitlab-organizations/updateProjectGitlabGroupConfig.json",response.body);
});
});

it("Add new Gitlab Organization in the project", function () {
console.log("gitLabOrganizationFullPath: "+gitLabOrganizationFullPath)
cy.request({
method: 'POST',
url: `${claEndpoint}/project/${projectSFID}/gitlab/organizations`,
auth: {
'bearer': bearerToken,
},body:{
"auto_enabled": false,
"auto_enabled_cla_group_id": claGroupId,
"branch_protection_enabled": false,
"group_id": parseInt(gitLabGroupID, 10),
"organization_full_path": gitLabOrganizationFullPath
},failOnStatusCode: false
}).then((response) => {
validate_200_Status(response);
//To validate schema of response
validateApiResponse("gitlab-organizations/addProjectGitlabOrganization.json",response.body);
});
});

it("Delete Gitlab Group/Organization Configuration", function () {
// Define the URL
const url = gitLabOrganizationFullPath;
// Use JavaScript string methods to extract the desired substring
gitLabOrganizationFullPath = url.split('/').pop();
// Log or use the extracted substring as needed
cy.log(gitLabOrganizationFullPath);
cy.request({
method: 'DELETE',
url: `${claEndpoint}/project/${projectSFID}/gitlab/organization?organization_full_path=${gitLabOrganizationFullPath}`,
auth: {
'bearer': bearerToken,
},failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(204);
});
});

function getGitLabGroupMembers(){
cy.request({
method: 'GET',
url: `${claEndpoint}/project/${projectSFID}/gitlab/organizations`,
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].organization_name===gitLabOrgName){
organizationExternalId=list[i].organization_external_id;
// gitLabOrganizationFullPath=list[i].organization_full_path;
claGroupId=list[i].repositories[0].cla_group_id
break;
}
}
//To validate schema of response
validateApiResponse("gitlab-organizations/getProjectGitlabOrganizations.json",response.body);
});
}

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"auto_enable_cla_group_id": {
"type": "string"
},
"auto_enabled": {
"type": "boolean"
},
"auto_enabled_cla_group_name": {
"type": "string"
},
"branch_protection_enabled": {
"type": "boolean"
},
"connection_status": {
"type": "string"
},
"connection_status_message": {
"type": "string"
},
"installation_url": {
"type": "string"
},
"organization_external_id": {
"type": "integer"
},
"organization_full_path": {
"type": "string"
},
"organization_name": {
"type": "string"
},
"organization_url": {
"type": "string"
},
"parent_project_sfid": {
"type": "string"
},
"project_sfid": {
"type": "string"
},
"repositories": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"cla_group_id": {
"type": "string"
},
"connection_status": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"parent_project_id": {
"type": "string"
},
"project_id": {
"type": "string"
},
"repository_full_path": {
"type": "string"
},
"repository_gitlab_id": {
"type": "integer"
},
"repository_id": {
"type": "string"
},
"repository_name": {
"type": "string"
},
"repository_url": {
"type": "string"
}
},
"required": [
"cla_group_id",
"connection_status",
"enabled",
"parent_project_id",
"project_id",
"repository_full_path",
"repository_gitlab_id",
"repository_id",
"repository_name",
"repository_url"
]
}
]
}
},
"required": [
"auto_enable_cla_group_id",
"auto_enabled",
"auto_enabled_cla_group_name",
"branch_protection_enabled",
"connection_status",
"connection_status_message",
"installation_url",
"organization_external_id",
"organization_full_path",
"organization_name",
"organization_url",
"parent_project_sfid",
"project_sfid",
"repositories"
]
}
]
}
},
"required": [
"list"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"access_level": {
"type": "string"
},
"avatar_url": {
"type": "string"
},
"created_at": {
"type": "string"
},
"expired_at": {
"type": "string"
},
"group_saml_identity": {
"type": "string"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"state": {
"type": "string"
},
"username": {
"type": "string"
},
"web_url": {
"type": "string"
}
},
"required": [
"access_level",
"avatar_url",
"created_at",
"expired_at",
"group_saml_identity",
"id",
"name",
"state",
"username",
"web_url"
]
}
]
}
},
"required": [
"list"
]
}
Loading

0 comments on commit 5d59ba2

Please sign in to comment.