diff --git a/package.json b/package.json new file mode 100644 index 000000000..49d1f62bb --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "prettier": "^3.0.2" + } +} diff --git a/tests/functional/cypress/e2e/cla-group.spec.ts b/tests/functional/cypress/e2e/cla-group.spec.ts index 8325a35ba..485c34e01 100644 --- a/tests/functional/cypress/e2e/cla-group.spec.ts +++ b/tests/functional/cypress/e2e/cla-group.spec.ts @@ -102,20 +102,16 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch // expect(response.duration).to.be.lessThan(20000); expect(response.status).to.eq(200); expect(response.body).to.not.be.null; - let list = response.body - console.log('Create cla group body: '+list) // Validate specific data in the response expect(response.body).to.have.property('cla_group_name', cla_group_name); claGroupId = response.body.cla_group_id; - console.log(claGroupId) //To validate schema of response const ajv = new Ajv(); // Load the JSON schema cy.fixture("claGroup/create_claGroup2.json").then( (schema) => { - console.log(schema) - const validate = ajv.compile(schema); + const validate = ajv.compile(schema); const isValid = validate(response.body); // Assert that the response matches the schema @@ -148,8 +144,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch // Load the JSON schema cy.fixture("claGroup/list_claGroup.json").then( (schema) => { - console.log(schema) - const validate = ajv.compile(schema); + const validate = ajv.compile(schema); const isValid = validate(response.body); // Assert that the response matches the schema @@ -174,7 +169,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch // expect(response.duration).to.be.lessThan(20000); expect(response.status).to.eq(200); expect(response.body).to.not.be.null; - console.log('Updates a CLA Group details API Response:', response.body); // Validate specific data in the response expect(response.body).to.have.property('cla_group_name', updated_cla_group_name); expect(response.body).to.have.property('cla_group_description', update_cla_group_description); @@ -184,7 +178,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch // Load the JSON schema cy.fixture("claGroup/update_claGroup2.json").then( (schema) => { - console.log(schema) const validate = ajv.compile(schema); const isValid = validate(response.body); @@ -283,7 +276,6 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch }); it("Deletes the CLA Group - Record should Returns 204 Response", function () { - console.log('claGroupId: '+ claGroupId) if(claGroupId!=null){ cy.request({ method: 'DELETE', diff --git a/tests/functional/cypress/e2e/github-repositories.spec.ts b/tests/functional/cypress/e2e/github-repositories.spec.ts new file mode 100644 index 000000000..1c79be68e --- /dev/null +++ b/tests/functional/cypress/e2e/github-repositories.spec.ts @@ -0,0 +1,201 @@ +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-repositories + + const Ajv = require('ajv'); + //Variable for GitHub + const projectSfidOrg='a09P000000DsNH2IAN'; //project name: easyAutom-child2 + + const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/project/${projectSfidOrg}/github/repositories`; + let bearerToken: string = ""; + let claGroupId: string ="1baf67ab-d894-4edf-b6fc-c5f939db59f7"; + let repository_id: string=""; + let repository_external_id: string=""; + let repository_external_id2: string=""; + let gitHubOrgName: string=""; + let branch_name: string=""; + + //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 the GitHub repositories of the project which are CLA Enforced- 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; + repository_id=list[0].repository_id; + claGroupId= list[0].repository_cla_group_id; + gitHubOrgName=list[0].repository_organization_name; + repository_external_id=list[0].repository_external_id; + repository_external_id2=list[1].repository_external_id; + expect(list[0].repository_name).to.eql('ApiAutomStandaloneOrg/repo01') + //To validate schema of response + const ajv = new Ajv(); + // Load the JSON schema + cy.fixture("github-repositories/getRepositories.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; +}); + }); + }); + + it("Remove 'disable CLA Enforced' the GitHub repository from the project - Record should Returns 204 Response", function () { + cy.request({ + method: 'DELETE', + url: `${claEndpoint}/${repository_id}`, + headers: optionalHeaders, + auth: { + 'bearer': bearerToken, + } + }).then((response) => { + expect(response.status).to.eq(204); + + }); + }); + + it("User should able to Add 'CLA Enforced' a GitHub repository to the project - Record should Returns 200 Response", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}`, + headers: optionalHeaders, + auth: { + 'bearer': bearerToken, + }, + body:{ + + "cla_group_id": claGroupId, + "github_organization_name": gitHubOrgName, + "repository_github_id": repository_external_id.toString(), + "repository_github_ids": [ + repository_external_id.toString(),repository_external_id2.toString() + ] + + } + }).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; + repository_id=list[0].repository_id; + claGroupId= list[0].repository_cla_group_id; + gitHubOrgName=list[0].repository_organization_name; + expect(list[0].repository_name).to.eql('ApiAutomStandaloneOrg/repo01') + + //To validate schema of response + const ajv = new Ajv(); + // Load the JSON schema + cy.fixture("github-repositories/getRepositories.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; +}); +}); + }); + + it("Get GitHub branch protection for given repository - Record should Returns 200 Response", function () { + cy.request({ + method: 'GET', + url: `${claEndpoint}/${repository_id}/branch-protection`, + headers: optionalHeaders, + auth: { + 'bearer': bearerToken, + } + }).then((response) => { + expect(response.status).to.eq(200); + let list = response.body + branch_name=list.branch_name; + if(list.protection_enabled){ + + //To validate schema of response + const ajv = new Ajv(); + // Load the JSON schema + cy.fixture("github-repositories/getBranchProtection.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; + }); +} +else{ + console.log('branch protection is false') +} + }); + }); + +it("Update github branch protection for given repository - Record should Returns 200 Response", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}/${repository_id}/branch-protection`, + headers: optionalHeaders, + auth: { + 'bearer': bearerToken, + }, + body:{ + "branch_name": branch_name, + "enforce_admin": true, + "status_checks": [ + { + "enabled": true, + "name": "EasyCLA" + } + ] + } + }).then((response) => { + expect(response.status).to.eq(200); + //To validate schema of response + const ajv = new Ajv(); + // Load the JSON schema + cy.fixture("github-repositories/getBranchProtection.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; + }); + }); + }); + +}) \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/github-repositories/getBranchProtection.json b/tests/functional/cypress/fixtures/github-repositories/getBranchProtection.json new file mode 100644 index 000000000..8089db4ae --- /dev/null +++ b/tests/functional/cypress/fixtures/github-repositories/getBranchProtection.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "branch_name": { + "type": "string" + }, + "enforce_admin": { + "type": "boolean" + }, + "protection_enabled": { + "type": "boolean" + }, + "status_checks": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "name": { + "type": "string" + } + }, + "required": [ + "enabled", + "name" + ] + } + ] + } + }, + "required": [ + "branch_name", + "enforce_admin", + "protection_enabled", + "status_checks" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/github-repositories/getRepositories.json b/tests/functional/cypress/fixtures/github-repositories/getRepositories.json new file mode 100644 index 000000000..5c2faed0a --- /dev/null +++ b/tests/functional/cypress/fixtures/github-repositories/getRepositories.json @@ -0,0 +1,81 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "list": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "date_created": { + "type": "string" + }, + "date_modified": { + "type": "string" + }, + "enabled": { + "type": "boolean" + }, + "is_remote_deleted": { + "type": "boolean" + }, + "note": { + "type": "string" + }, + "repository_cla_group_id": { + "type": "string" + }, + "repository_external_id": { + "type": "integer" + }, + "repository_id": { + "type": "string" + }, + "repository_name": { + "type": "string" + }, + "repository_organization_name": { + "type": "string" + }, + "repository_project_sfid": { + "type": "string" + }, + "repository_type": { + "type": "string" + }, + "repository_url": { + "type": "string" + }, + "version": { + "type": "string" + }, + "was_cla_enforced": { + "type": "boolean" + } + }, + "required": [ + "date_created", + "date_modified", + "enabled", + "is_remote_deleted", + "note", + "repository_cla_group_id", + "repository_external_id", + "repository_id", + "repository_name", + "repository_organization_name", + "repository_project_sfid", + "repository_type", + "repository_url", + "version", + "was_cla_enforced" + ] + } + ] + } + }, + "required": [ + "list" + ] + } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 000000000..ebecb0424 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +prettier@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.2.tgz#78fcecd6d870551aa5547437cdae39d4701dca5b" + integrity sha512-o2YR9qtniXvwEZlOKbveKfDQVyqxbEIWn48Z8m3ZJjBjcCmUy3xZGIv+7AkaeuaTr6yPXJjwv07ZWlsWbEy1rQ==