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 #4094

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
45 changes: 14 additions & 31 deletions tests/functional/cypress/e2e/cla-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import {getBearerToken,bearerToken } from '../../support/commands.js';
import {validateApiResponse} from '../support/commands'

describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on child project", function () {
//Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/cla-group
Expand Down Expand Up @@ -28,10 +28,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
const EnrollProjectsSFID='a09P000000DsNHCIA3' //project name: easyAutomChild1-GrandChild1
const child_Project_name='easyAutomChild1-GrandChild1'

//Headers
let optionalHeaders: Headers = {
"X-LFX-CACHE": false,
}

before(() => {

Expand Down Expand Up @@ -59,7 +55,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'POST',
url: `${claEndpoint}/cla-group`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand Down Expand Up @@ -107,15 +103,15 @@ 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
schemaValidate("claGroup/create_claGroup2.json",response.body);
validateApiResponse("claGroup/create_claGroup2.json",response.body);
});
});

it("Get list of cla group associated with project - Record should Returns 200 Response", function () {
cy.request({
method: 'GET',
url: `${claEndpoint}/foundation/${projectSfid}/cla-groups`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
}
Expand All @@ -131,15 +127,15 @@ 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
schemaValidate("claGroup/list_claGroup.json",response.body);
validateApiResponse("claGroup/list_claGroup.json",response.body);
});
});

it("Updates a CLA Group details - Record should Returns 200 Response", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}/cla-group/${claGroupId}`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -156,15 +152,15 @@ 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
schemaValidate("claGroup/update_claGroup2.json",response.body);
validateApiResponse("claGroup/update_claGroup2.json",response.body);
});
});

it("Enroll projects in a CLA Group - Record should Returns 200 Response", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}/cla-group/${claGroupId}/enroll-projects`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -178,7 +174,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'GET',
url: `${claEndpoint}/foundation/${projectSfid}/cla-groups`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -200,7 +196,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'PUT',
url: `${claEndpoint}/cla-group/${claGroupId}/unenroll-projects`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -215,7 +211,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'GET',
url: `${claEndpoint}/project/${projectSfidOrg}/github/organizations`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
}
Expand All @@ -234,7 +230,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'PUT',
url: `${claEndpoint}/project/${projectSfidOrg}/github/organizations/${gitHubOrgName}/config`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -253,7 +249,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'DELETE',
url: `${claEndpoint}/cla-group/${claGroupId}`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -265,7 +261,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
cy.request({
method: 'GET',
url: `${claEndpoint}/foundation/${projectSfid}/cla-groups`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -284,17 +280,4 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
}
});

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;
});
}

})
25 changes: 5 additions & 20 deletions tests/functional/cypress/e2e/events.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {validateApiResponse} from '../support/commands'
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`;
Expand Down Expand Up @@ -54,8 +55,7 @@ it("Get recent events of company and project - Record should Returns 200 Respons
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);
validateApiResponse("events/getCompanyProjectEvents.json",response);
fetchNextRecords(claEndpointForNextKey,NextKey);
});
});
Expand All @@ -82,8 +82,7 @@ it("Get events of foundation project - Record should Returns 200 Response", func
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);
validateApiResponse("events/getFoundationEvents.json",list);
fetchNextRecords(claEndpointForNextKey,NextKey);
});
});
Expand All @@ -110,7 +109,7 @@ it("Get events of foundation project - Record should Returns 200 Response", func
// 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)
validateApiResponse("events/getProjectEvents",list)
fetchNextRecords(claEndpointForNextKey,NextKey);
});
});
Expand All @@ -136,7 +135,7 @@ it("Get events of foundation project - Record should Returns 200 Response", func
// 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)
validateApiResponse("events/getProjectEvents.json",list)
});
});

Expand Down Expand Up @@ -182,18 +181,4 @@ it("Get events of foundation project - Record should Returns 200 Response", func
}
});
}

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;
});
}

})
12 changes: 2 additions & 10 deletions tests/functional/cypress/e2e/foundation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {validateApiResponse} from '../support/commands'
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');

before(() => {

Expand Down Expand Up @@ -46,15 +46,7 @@ it("Get CLA Groups under a foundation- Record should Returns 200 Response", func
// 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;
});
validateApiResponse("foundation/listFoundationClaGroups.json",response)
});
});

Expand Down
30 changes: 7 additions & 23 deletions tests/functional/cypress/e2e/github-organizations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import {schemaValidate} from '../support/commands.js';
import {validateApiResponse} from '../support/commands'
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-organizations

Expand All @@ -13,10 +13,6 @@ const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/project/${projectSf
let bearerToken: string = "";
const claGroupId: string ="1baf67ab-d894-4edf-b6fc-c5f939db59f7";

//Headers
let optionalHeaders: Headers = {
"X-LFX-CACHE": false,
}

before(() => {

Expand Down Expand Up @@ -44,7 +40,7 @@ it("Get list of Github organization associated with project - Record should Retu
cy.request({
method: 'GET',
url: `${claEndpoint}`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
}
Expand All @@ -57,15 +53,15 @@ 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
schemaValidate("github-organizations/getProjectGithubOrganizations.json",response.body);
validateApiResponse("github-organizations/getProjectGithubOrganizations.json",response.body);
});
});

it("Update GitHub Organization Configuration - Record should Returns 200 Response", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}/${gitHubOrgName}/config`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -83,7 +79,7 @@ it("Get list of Github organization associated with project - Record should Retu
cy.request({
method: 'POST',
url: `${claEndpoint}`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -102,15 +98,15 @@ it("Get list of Github organization associated with project - Record should Retu
expect(list[1].github_organization_name).to.eql(gitHubOrg)
expect(list[1].connection_status).to.eql('connected')
//To validate schema of response
schemaValidate("github-organizations/addProjectGithubOrganization.json",response.body);
validateApiResponse("github-organizations/addProjectGithubOrganization.json",response.body);
});
});

it("Delete GitHub oranization in the project - Record should Returns 204 Response", function () {
cy.request({
method: 'DELETE',
url: `${claEndpoint}/${gitHubOrg}`,
headers: optionalHeaders,

auth: {
'bearer': bearerToken,
},
Expand All @@ -120,16 +116,4 @@ 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