Skip to content

Commit

Permalink
Merge pull request #4092 from communitybridge/cypress-events
Browse files Browse the repository at this point in the history
add cypress test case for events services
  • Loading branch information
nickmango authored Aug 24, 2023
2 parents 52eca0d + ba9659c commit 62640f7
Show file tree
Hide file tree
Showing 7 changed files with 2,114 additions and 13 deletions.
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"
}
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
Loading

0 comments on commit 62640f7

Please sign in to comment.