Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cypress test case for github-repositories services #4090

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"prettier": "^3.0.2"
}
}
12 changes: 2 additions & 10 deletions tests/functional/cypress/e2e/cla-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,16 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
// expect(response.duration).to.be.lessThan(20000);
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
let list = response.body
console.log('Create cla group body: '+list)
// Validate specific data in the response
expect(response.body).to.have.property('cla_group_name', cla_group_name);
claGroupId = response.body.cla_group_id;
console.log(claGroupId)

//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("claGroup/create_claGroup2.json").then(
(schema) => {
console.log(schema)
const validate = ajv.compile(schema);
const validate = ajv.compile(schema);
const isValid = validate(response.body);

// Assert that the response matches the schema
Expand Down Expand Up @@ -148,8 +144,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
// Load the JSON schema
cy.fixture("claGroup/list_claGroup.json").then(
(schema) => {
console.log(schema)
const validate = ajv.compile(schema);
const validate = ajv.compile(schema);
const isValid = validate(response.body);

// Assert that the response matches the schema
Expand All @@ -174,7 +169,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
// expect(response.duration).to.be.lessThan(20000);
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
console.log('Updates a CLA Group details API Response:', response.body);
// Validate specific data in the response
expect(response.body).to.have.property('cla_group_name', updated_cla_group_name);
expect(response.body).to.have.property('cla_group_description', update_cla_group_description);
Expand All @@ -184,7 +178,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
// Load the JSON schema
cy.fixture("claGroup/update_claGroup2.json").then(
(schema) => {
console.log(schema)
const validate = ajv.compile(schema);
const isValid = validate(response.body);

Expand Down Expand Up @@ -283,7 +276,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
});

it("Deletes the CLA Group - Record should Returns 204 Response", function () {
console.log('claGroupId: '+ claGroupId)
if(claGroupId!=null){
cy.request({
method: 'DELETE',
Expand Down
201 changes: 201 additions & 0 deletions tests/functional/cypress/e2e/github-repositories.spec.ts
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;
});
});
});

})
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"
]
}
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"
]
}
8 changes: 8 additions & 0 deletions yarn.lock
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==
Loading