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 schema validate #4093

Merged
merged 2 commits into from
Aug 24, 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
3 changes: 1 addition & 2 deletions tests/functional/cypress.env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"AUTH0_TOKEN_API":"https://linuxfoundation-dev.auth0.com/oauth/token",
"AUTH0_USER_NAME":"vthakur",
"AUTH0_PASSWORD":"Test@123",
"AUTH0_CLIENT_ID":"hquZHO8JNsaIScoayPtCS5VELdn7TnVq"

"AUTH0_CLIENT_ID":"hquZHO8JNsaIScoayPtCS5VELdn7TnVq"
}
48 changes: 17 additions & 31 deletions tests/functional/cypress/e2e/cla-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
claGroupId = response.body.cla_group_id;

//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("claGroup/create_claGroup2.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;
});
schemaValidate("claGroup/create_claGroup2.json",response.body);
});
});

Expand All @@ -140,16 +131,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
expect(list[0].cla_group_name).to.eql(cla_group_name)

//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("claGroup/list_claGroup.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;
});
schemaValidate("claGroup/list_claGroup.json",response.body);
});
});

Expand All @@ -174,16 +156,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
expect(response.body).to.have.property('cla_group_description', update_cla_group_description);

//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("claGroup/update_claGroup2.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;
});
schemaValidate("claGroup/update_claGroup2.json",response.body);
});
});

Expand Down Expand Up @@ -307,8 +280,21 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
}
});
}else{
console.log('claGroupId is null'+ claGroupId)
console.log('claGroupId is null'+ claGroupId)
}
});

function schemaValidate(schemaPath,body){
//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture(schemaPath).then(
(schema) => {
const validate = ajv.compile(schema);
const isValid = validate(body);
// Assert that the response matches the schema
expect(isValid, 'API response schema is valid').to.be.true;
});
}

})
199 changes: 199 additions & 0 deletions tests/functional/cypress/e2e/events.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
describe("To Validate events are properly capture via API call", function () {
//Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/events
const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/events`;
let claEndpointForNextKey="";
let bearerToken: string = "";
let NextKey: string="";
const foundationSFID='a09P000000DsNGsIAN'; //project name: easyAutom foundation
const projectSfid='a09P000000DsNH2IAN'; //project name: easyAutom-child2
const companyID="f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc";
const compProjectSFID="a092h000004x5tVAAQ";
const Ajv = require('ajv');

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 recent events of company and project - Record should Returns 200 Response", function () {
claEndpointForNextKey=`${Cypress.env("APP_URL")}cla-service/v4/company/${companyID}/project/${compProjectSFID}/events`
cy.request({
method: 'GET',
url: `${claEndpointForNextKey}`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
// Validate specific data in the response
let list=response.body;
NextKey=list.NextKey;
expect(list).to.have.property('NextKey');
expect(list).to.have.property('ResultCount');
expect(list).to.have.property('Events');
let Events = list.Events;
// Assert that the response contains an array
expect(Events).to.be.an('array');
// Assert that the array has at least one item
expect(Events.length).to.be.greaterThan(0);
// schemaValidate("events/getFoundationEvents.json",list);
schemaValidate("events/getCompanyProjectEvents.json",list);
fetchNextRecords(claEndpointForNextKey,NextKey);
});
});

it("Get events of foundation project - Record should Returns 200 Response", function () {
claEndpointForNextKey=`${claEndpoint}/foundation/${foundationSFID}`
cy.request({
method: 'GET',
url: `${claEndpointForNextKey}`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
// Validate specific data in the response
let list=response.body;
NextKey=list.NextKey;
expect(list).to.have.property('NextKey');
expect(list).to.have.property('ResultCount');
expect(list).to.have.property('Events');
let Events = list.Events;
// Assert that the response contains an array
expect(Events).to.be.an('array');
// Assert that the array has at least one item
expect(Events.length).to.be.greaterThan(0);
// schemaValidate("events/getFoundationEvents.json",list);
schemaValidate("events/getFoundationEvents.json",list);
fetchNextRecords(claEndpointForNextKey,NextKey);
});
});

it("Get events of child project - Record should Returns 200 Response", function () {
claEndpointForNextKey=`${claEndpoint}/project/${projectSfid}`;
cy.request({
method: 'GET',
url: `${claEndpointForNextKey}`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
let list=response.body;
// Validate specific data in the response
expect(list).to.have.property('NextKey');
expect(list).to.have.property('ResultCount');
expect(list).to.have.property('Events');
let Events = response.body.Events;
// Assert that the response contains an array
expect(Events).to.be.an('array');
// Assert that the array has at least one item
expect(Events.length).to.be.greaterThan(0);
//To validate schema of response
schemaValidate("events/getProjectEvents",list)
fetchNextRecords(claEndpointForNextKey,NextKey);
});
});

it.skip("Get List of recent events - requires Admin-level access - Record should Returns 200 Response", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}/recent?pageSize=2`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
// Validate specific data in the response
let list=response.body;
expect(list).to.have.property('NextKey');
expect(list).to.have.property('ResultCount');
expect(list).to.have.property('Events');
let Events = list.Events;
// Assert that the response contains an array
expect(Events).to.be.an('array');
// Assert that the array has at least one item
expect(Events.length).to.be.greaterThan(0);
//To validate schema of response
schemaValidate("events/getProjectEvents.json",list)
});
});

it("Download all the events for the foundation as a CSV document - Record should Returns 200 Response", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}/foundation/${foundationSFID}/csv`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
});
});

it("Download all the events for the project as a CSV document - Record should Returns 200 Response", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}/project/${projectSfid}/csv`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
});
});

function fetchNextRecords(URL,NextKey){

cy.request({
method: 'GET',
url: `${URL}?nextKey=${NextKey}&pageSize=50`,
auth: {
'bearer': bearerToken,
}
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.not.be.null;
// Validate specific data in the response
let updatedNextKey=response.body.NextKey;
if(updatedNextKey!==undefined){
fetchNextRecords(URL,updatedNextKey);
}
});
}

function schemaValidate(schemaPath,body){
//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture(schemaPath).then(
(schema) => {
const validate = ajv.compile(schema);
const isValid = validate(body);
// Assert that the response matches the schema
expect(isValid, 'API response schema is valid').to.be.true;
});
}

})
7 changes: 1 addition & 6 deletions tests/functional/cypress/e2e/foundation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
describe("To Validate github-organizations API call", function () {
describe("To Validate & get list of Foundation ClaGroups via 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(() => {

Expand Down Expand Up @@ -35,7 +31,6 @@ it("Get CLA Groups under a foundation- Record should Returns 200 Response", func
cy.request({
method: 'GET',
url: `${claEndpoint}?foundationSFID=${foundationSFID}`,
headers: optionalHeaders,
auth: {
'bearer': bearerToken,
}
Expand Down
38 changes: 15 additions & 23 deletions tests/functional/cypress/e2e/github-organizations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,7 @@ it("Get list of Github organization associated with project - Record should Retu
expect(list[0].github_organization_name).to.eql('ApiAutomStandaloneOrg')
expect(list[0].connection_status).to.eql('connected')
//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("github-organizations/getProjectGithubOrganizations.json").then(
(schema) => {
console.log(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;
});
schemaValidate("github-organizations/getProjectGithubOrganizations.json",response.body);
});
});

Expand Down Expand Up @@ -111,18 +101,8 @@ it("Get list of Github organization associated with project - Record should Retu
let list = response.body.list;
expect(list[1].github_organization_name).to.eql(gitHubOrg)
expect(list[1].connection_status).to.eql('connected')
//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture("github-organizations/addProjectGithubOrganization.json").then(
(schema) => {
console.log(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;
});
//To validate schema of response
schemaValidate("github-organizations/addProjectGithubOrganization.json",response.body);
});
});

Expand All @@ -140,4 +120,16 @@ it("Get list of Github organization associated with project - Record should Retu
});
});

function schemaValidate(schemaPath,body){
//To validate schema of response
const ajv = new Ajv();
// Load the JSON schema
cy.fixture(schemaPath).then(
(schema) => {
const validate = ajv.compile(schema);
const isValid = validate(body);
// Assert that the response matches the schema
expect(isValid, 'API response schema is valid').to.be.true;
});
}
})
Loading
Loading