Skip to content

Commit

Permalink
Merge pull request #4088 from communitybridge/cypress-github-organiza…
Browse files Browse the repository at this point in the history
…tions

Cypress GitHub organizations
  • Loading branch information
nickmango authored Aug 22, 2023
2 parents 528ef98 + 46e3a76 commit fc41f68
Show file tree
Hide file tree
Showing 4 changed files with 369 additions and 2 deletions.
143 changes: 143 additions & 0 deletions tests/functional/cypress/e2e/github-organizations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// import {schemaValidate} from '../support/commands.js';
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

const Ajv = require('ajv');
//Variable for GitHub
const gitHubOrgName='ApiAutomStandaloneOrg';
const projectSfidOrg='a09P000000DsNH2IAN'; //project name: easyAutom-child2
const gitHubOrg='cypressioTest';


const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/project/${projectSfidOrg}/github/organizations`;
let bearerToken: string = "";
const claGroupId: string ="1baf67ab-d894-4edf-b6fc-c5f939db59f7";

//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 list of Github organization associated with project - 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;
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;
});
});
});

it("Update GitHub Organization Configuration - Record should Returns 200 Response", function () {
cy.request({
method: 'PUT',
url: `${claEndpoint}/${gitHubOrgName}/config`,
headers: optionalHeaders,
auth: {
'bearer': bearerToken,
},
body: {
"autoEnabled": true,
"autoEnabledClaGroupID": claGroupId,
"branchProtectionEnabled": true
},
}).then((response) => {
expect(response.status).to.eq(200);
});
});

it("Add new GitHub Oranization in the project - Record should Returns 200 Response", function () {
cy.request({
method: 'POST',
url: `${claEndpoint}`,
headers: optionalHeaders,
auth: {
'bearer': bearerToken,
},
body: {
"autoEnabled": false,
"autoEnabledClaGroupID": claGroupId,
"branchProtectionEnabled": false,
"organizationName": gitHubOrg
},
}).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[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;
});
});
});

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,
},

}).then((response) => {
expect(response.status).to.eq(204);
});
});

})
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"autoEnabled": {
"type": "boolean"
},
"autoEnabledClaGroupID": {
"type": "string"
},
"branchProtectionEnabled": {
"type": "boolean"
},
"dateCreated": {
"type": "string"
},
"dateModified": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"githubInfo": {
"type": "object",
"properties": {
"details": {
"type": "object",
"properties": {
"bio": {
"type": "string"
},
"htmlUrl": {
"type": "string"
},
"id": {
"type": "integer"
},
"installationURL": {
"type": "string"
}
},
"required": [
"bio",
"htmlUrl",
"id",
"installationURL"
]
},
"error": {
"type": "string"
}
},
"required": [
"details",
"error"
]
},
"organizationInstallationID": {
"type": "integer"
},
"organizationName": {
"type": "string"
},
"organizationSfid": {
"type": "string"
},
"projectSFID": {
"type": "string"
},
"repositories": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"repositoryGithubID": {
"type": "integer"
},
"repositoryName": {
"type": "string"
},
"repositoryType": {
"type": "string"
},
"repositoryUrl": {
"type": "string"
}
},
"required": [
"repositoryGithubID",
"repositoryName",
"repositoryType",
"repositoryUrl"
]
}
]
}
},
"required": [
"error",
"list"
]
},
"version": {
"type": "string"
}
},
"required": [
"autoEnabled",
"autoEnabledClaGroupID",
"branchProtectionEnabled",
"dateCreated",
"dateModified",
"enabled",
"githubInfo",
"organizationInstallationID",
"organizationName",
"organizationSfid",
"projectSFID",
"repositories",
"version"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"list": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"autoEnableCLAGroupID": {
"type": "string"
},
"autoEnabledCLAGroupName": {
"type": "string"
},
"auto_enabled": {
"type": "boolean"
},
"branchProtectionEnabled": {
"type": "boolean"
},
"connection_status": {
"type": "string"
},
"github_organization_name": {
"type": "string"
},
"installationURL": {
"type": "string"
},
"repositories": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"cla_group_id": {
"type": "string"
},
"connection_status": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"parent_project_id": {
"type": "string"
},
"project_id": {
"type": "string"
},
"repository_github_id": {
"type": "integer"
},
"repository_id": {
"type": "string"
},
"repository_name": {
"type": "string"
}
},
"required": [
"cla_group_id",
"connection_status",
"enabled",
"parent_project_id",
"project_id",
"repository_github_id",
"repository_id",
"repository_name"
]
}
]
}
},
"required": [
"autoEnableCLAGroupID",
"autoEnabledCLAGroupName",
"auto_enabled",
"branchProtectionEnabled",
"connection_status",
"github_organization_name",
"installationURL",
"repositories"
]
}
]
}
},
"required": [
"list"
]
}
5 changes: 3 additions & 2 deletions tests/functional/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@


/*
const Ajv = require('ajv');
Cypress.Commands.add('schemaValidate', (schemaPath,body) => {
Cypress.Commands.add('schemaValidate', (schemaPath,body) => {
cy.fixture(schemaPath).then(
(schema) => {
console.log(schema)
Expand Down

0 comments on commit fc41f68

Please sign in to comment.