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

Cypress foundation #4091

Merged
merged 2 commits 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
66 changes: 66 additions & 0 deletions tests/functional/cypress/e2e/foundation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
describe("To Validate github-organizations API call", function () {
//Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/foundation
const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/foundation-mapping`;
let bearerToken: string = "";
const foundationSFID='a09P000000DsNGsIAN'; //project name: easyAutom foundation
const Ajv = require('ajv');
//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 CLA Groups under a foundation- Record should Returns 200 Response", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}?foundationSFID=${foundationSFID}`,
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;
expect(list[0].foundation_sfid).to.eql(foundationSFID)
// Assert that the response contains an array
expect(list[0].cla_groups).to.be.an('array');
// Assert that the array has at least one item
expect(list[0].cla_groups.length).to.be.greaterThan(0);
//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("foundation/listFoundationClaGroups.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;
});
});
});

})
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,51 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"cla_groups": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"cla_group_id": {
"type": "string"
},
"project_sfid_list": {
"type": "array",
"items": [
{
"type": "string"
}
]
}
},
"required": [
"cla_group_id",
"project_sfid_list"
]
}
]
},
"foundation_sfid": {
"type": "string"
}
},
"required": [
"cla_groups",
"foundation_sfid"
]
}
]
}
},
"required": [
"list"
]
}
Loading
Loading