-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cypress test case for gitlab-organizations API
Signed-off-by: veerendra thakur <[email protected]>
- Loading branch information
1 parent
90d568b
commit b4f5749
Showing
7 changed files
with
586 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
tests/functional/cypress/e2e/gitlab-organizations.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
|
||
}) |
126 changes: 126 additions & 0 deletions
126
tests/functional/cypress/fixtures/gitlab-organizations/addProjectGitlabOrganization.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/functional/cypress/fixtures/gitlab-organizations/getGitLabGroupMembers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
Oops, something went wrong.