-
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.
Merge pull request #4090 from communitybridge/cypress-github-reposito…
…ries add cypress test case for github-repositories services
- Loading branch information
Showing
6 changed files
with
338 additions
and
10 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,5 @@ | ||
{ | ||
"dependencies": { | ||
"prettier": "^3.0.2" | ||
} | ||
} |
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
201 changes: 201 additions & 0 deletions
201
tests/functional/cypress/e2e/github-repositories.spec.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,201 @@ | ||
describe("To Validate github-organizations API call", function () { | ||
//Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/github-repositories | ||
|
||
const Ajv = require('ajv'); | ||
//Variable for GitHub | ||
const projectSfidOrg='a09P000000DsNH2IAN'; //project name: easyAutom-child2 | ||
|
||
const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/project/${projectSfidOrg}/github/repositories`; | ||
let bearerToken: string = ""; | ||
let claGroupId: string ="1baf67ab-d894-4edf-b6fc-c5f939db59f7"; | ||
let repository_id: string=""; | ||
let repository_external_id: string=""; | ||
let repository_external_id2: string=""; | ||
let gitHubOrgName: string=""; | ||
let branch_name: string=""; | ||
|
||
//Headers | ||
let optionalHeaders: Headers = { | ||
"X-LFX-CACHE": false, | ||
} | ||
|
||
before(() => { | ||
|
||
cy.request({ | ||
method: 'POST', | ||
url: Cypress.env("AUTH0_TOKEN_API"), | ||
|
||
body: { | ||
"grant_type": "http://auth0.com/oauth/grant-type/password-realm", | ||
"realm": "Username-Password-Authentication", | ||
"username":Cypress.env("AUTH0_USER_NAME"), | ||
"password":Cypress.env("AUTH0_PASSWORD"), | ||
"client_id":Cypress.env("AUTH0_CLIENT_ID"), | ||
"audience": "https://api-gw.dev.platform.linuxfoundation.org/", | ||
"scope": "access:api openid profile email" | ||
} | ||
}).then(response => { | ||
expect(response.status).to.eq(200); | ||
bearerToken = response.body.access_token; | ||
|
||
}); | ||
}); | ||
|
||
it("Get the GitHub repositories of the project which are CLA Enforced- Record should Returns 200 Response", function () { | ||
cy.request({ | ||
method: 'GET', | ||
url: `${claEndpoint}`, | ||
headers: optionalHeaders, | ||
auth: { | ||
'bearer': bearerToken, | ||
} | ||
}).then((response) => { | ||
expect(response.status).to.eq(200); | ||
expect(response.body).to.not.be.null; | ||
// Validate specific data in the response | ||
expect(response.body).to.have.property('list'); | ||
let list = response.body.list; | ||
repository_id=list[0].repository_id; | ||
claGroupId= list[0].repository_cla_group_id; | ||
gitHubOrgName=list[0].repository_organization_name; | ||
repository_external_id=list[0].repository_external_id; | ||
repository_external_id2=list[1].repository_external_id; | ||
expect(list[0].repository_name).to.eql('ApiAutomStandaloneOrg/repo01') | ||
//To validate schema of response | ||
const ajv = new Ajv(); | ||
// Load the JSON schema | ||
cy.fixture("github-repositories/getRepositories.json").then( | ||
(schema) => { | ||
const validate = ajv.compile(schema); | ||
const isValid = validate(response.body); | ||
|
||
// Assert that the response matches the schema | ||
expect(isValid, 'API response schema is valid').to.be.true; | ||
}); | ||
}); | ||
}); | ||
|
||
it("Remove 'disable CLA Enforced' the GitHub repository from the project - Record should Returns 204 Response", function () { | ||
cy.request({ | ||
method: 'DELETE', | ||
url: `${claEndpoint}/${repository_id}`, | ||
headers: optionalHeaders, | ||
auth: { | ||
'bearer': bearerToken, | ||
} | ||
}).then((response) => { | ||
expect(response.status).to.eq(204); | ||
|
||
}); | ||
}); | ||
|
||
it("User should able to Add 'CLA Enforced' a GitHub repository to the project - Record should Returns 200 Response", function () { | ||
cy.request({ | ||
method: 'POST', | ||
url: `${claEndpoint}`, | ||
headers: optionalHeaders, | ||
auth: { | ||
'bearer': bearerToken, | ||
}, | ||
body:{ | ||
|
||
"cla_group_id": claGroupId, | ||
"github_organization_name": gitHubOrgName, | ||
"repository_github_id": repository_external_id.toString(), | ||
"repository_github_ids": [ | ||
repository_external_id.toString(),repository_external_id2.toString() | ||
] | ||
|
||
} | ||
}).then((response) => { | ||
expect(response.status).to.eq(200); | ||
expect(response.body).to.not.be.null; | ||
// Validate specific data in the response | ||
expect(response.body).to.have.property('list'); | ||
let list = response.body.list; | ||
repository_id=list[0].repository_id; | ||
claGroupId= list[0].repository_cla_group_id; | ||
gitHubOrgName=list[0].repository_organization_name; | ||
expect(list[0].repository_name).to.eql('ApiAutomStandaloneOrg/repo01') | ||
|
||
//To validate schema of response | ||
const ajv = new Ajv(); | ||
// Load the JSON schema | ||
cy.fixture("github-repositories/getRepositories.json").then( | ||
(schema) => { | ||
const validate = ajv.compile(schema); | ||
const isValid = validate(response.body); | ||
|
||
// Assert that the response matches the schema | ||
expect(isValid, 'API response schema is valid').to.be.true; | ||
}); | ||
}); | ||
}); | ||
|
||
it("Get GitHub branch protection for given repository - Record should Returns 200 Response", function () { | ||
cy.request({ | ||
method: 'GET', | ||
url: `${claEndpoint}/${repository_id}/branch-protection`, | ||
headers: optionalHeaders, | ||
auth: { | ||
'bearer': bearerToken, | ||
} | ||
}).then((response) => { | ||
expect(response.status).to.eq(200); | ||
let list = response.body | ||
branch_name=list.branch_name; | ||
if(list.protection_enabled){ | ||
|
||
//To validate schema of response | ||
const ajv = new Ajv(); | ||
// Load the JSON schema | ||
cy.fixture("github-repositories/getBranchProtection.json").then( | ||
(schema) => { | ||
const validate = ajv.compile(schema); | ||
const isValid = validate(response.body); | ||
|
||
// Assert that the response matches the schema | ||
expect(isValid, 'API response schema is valid').to.be.true; | ||
}); | ||
} | ||
else{ | ||
console.log('branch protection is false') | ||
} | ||
}); | ||
}); | ||
|
||
it("Update github branch protection for given repository - Record should Returns 200 Response", function () { | ||
cy.request({ | ||
method: 'POST', | ||
url: `${claEndpoint}/${repository_id}/branch-protection`, | ||
headers: optionalHeaders, | ||
auth: { | ||
'bearer': bearerToken, | ||
}, | ||
body:{ | ||
"branch_name": branch_name, | ||
"enforce_admin": true, | ||
"status_checks": [ | ||
{ | ||
"enabled": true, | ||
"name": "EasyCLA" | ||
} | ||
] | ||
} | ||
}).then((response) => { | ||
expect(response.status).to.eq(200); | ||
//To validate schema of response | ||
const ajv = new Ajv(); | ||
// Load the JSON schema | ||
cy.fixture("github-repositories/getBranchProtection.json").then( | ||
(schema) => { | ||
const validate = ajv.compile(schema); | ||
const isValid = validate(response.body); | ||
|
||
// Assert that the response matches the schema | ||
expect(isValid, 'API response schema is valid').to.be.true; | ||
}); | ||
}); | ||
}); | ||
|
||
}) |
41 changes: 41 additions & 0 deletions
41
tests/functional/cypress/fixtures/github-repositories/getBranchProtection.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,41 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"branch_name": { | ||
"type": "string" | ||
}, | ||
"enforce_admin": { | ||
"type": "boolean" | ||
}, | ||
"protection_enabled": { | ||
"type": "boolean" | ||
}, | ||
"status_checks": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"enabled": { | ||
"type": "boolean" | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"enabled", | ||
"name" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"branch_name", | ||
"enforce_admin", | ||
"protection_enabled", | ||
"status_checks" | ||
] | ||
} |
81 changes: 81 additions & 0 deletions
81
tests/functional/cypress/fixtures/github-repositories/getRepositories.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,81 @@ | ||
{ | ||
"$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" | ||
}, | ||
"is_remote_deleted": { | ||
"type": "boolean" | ||
}, | ||
"note": { | ||
"type": "string" | ||
}, | ||
"repository_cla_group_id": { | ||
"type": "string" | ||
}, | ||
"repository_external_id": { | ||
"type": "integer" | ||
}, | ||
"repository_id": { | ||
"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" | ||
}, | ||
"was_cla_enforced": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"date_created", | ||
"date_modified", | ||
"enabled", | ||
"is_remote_deleted", | ||
"note", | ||
"repository_cla_group_id", | ||
"repository_external_id", | ||
"repository_id", | ||
"repository_name", | ||
"repository_organization_name", | ||
"repository_project_sfid", | ||
"repository_type", | ||
"repository_url", | ||
"version", | ||
"was_cla_enforced" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"list" | ||
] | ||
} |
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,8 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
prettier@^3.0.2: | ||
version "3.0.2" | ||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.2.tgz#78fcecd6d870551aa5547437cdae39d4701dca5b" | ||
integrity sha512-o2YR9qtniXvwEZlOKbveKfDQVyqxbEIWn48Z8m3ZJjBjcCmUy3xZGIv+7AkaeuaTr6yPXJjwv07ZWlsWbEy1rQ== |