From 46e3a768ef316e687ae794c5d83c2f3b235a91da Mon Sep 17 00:00:00 2001 From: veerendra thakur Date: Tue, 22 Aug 2023 12:14:01 +0530 Subject: [PATCH] add cypress test case for github-organizations services Signed-off-by: veerendra thakur --- .../cypress/e2e/github-organizations.spec.ts | 143 ++++++++++++++++++ .../addProjectGithubOrganization.json | 129 ++++++++++++++++ .../getProjectGithubOrganizations.json | 94 ++++++++++++ tests/functional/cypress/support/commands.js | 5 +- 4 files changed, 369 insertions(+), 2 deletions(-) create mode 100644 tests/functional/cypress/e2e/github-organizations.spec.ts create mode 100644 tests/functional/cypress/fixtures/github-organizations/addProjectGithubOrganization.json create mode 100644 tests/functional/cypress/fixtures/github-organizations/getProjectGithubOrganizations.json diff --git a/tests/functional/cypress/e2e/github-organizations.spec.ts b/tests/functional/cypress/e2e/github-organizations.spec.ts new file mode 100644 index 000000000..475938360 --- /dev/null +++ b/tests/functional/cypress/e2e/github-organizations.spec.ts @@ -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); + }); + }); + +}) \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/github-organizations/addProjectGithubOrganization.json b/tests/functional/cypress/fixtures/github-organizations/addProjectGithubOrganization.json new file mode 100644 index 000000000..e8e25b07e --- /dev/null +++ b/tests/functional/cypress/fixtures/github-organizations/addProjectGithubOrganization.json @@ -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" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/github-organizations/getProjectGithubOrganizations.json b/tests/functional/cypress/fixtures/github-organizations/getProjectGithubOrganizations.json new file mode 100644 index 000000000..99ee92956 --- /dev/null +++ b/tests/functional/cypress/fixtures/github-organizations/getProjectGithubOrganizations.json @@ -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" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/support/commands.js b/tests/functional/cypress/support/commands.js index f82b7271d..b37158a7d 100644 --- a/tests/functional/cypress/support/commands.js +++ b/tests/functional/cypress/support/commands.js @@ -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)