-
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-repositories API
Signed-off-by: veerendra thakur <[email protected]>
- Loading branch information
1 parent
b4f5749
commit 1e66f9c
Showing
3 changed files
with
265 additions
and
0 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
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); | ||
}); | ||
}); | ||
|
||
}); |
77 changes: 77 additions & 0 deletions
77
tests/functional/cypress/fixtures/gitlab-repositories/enrollGitLabRepository.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,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" | ||
] | ||
} |
77 changes: 77 additions & 0 deletions
77
tests/functional/cypress/fixtures/gitlab-repositories/getProjectGitLabRepositories.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,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" | ||
] | ||
} |