diff --git a/tests/functional/cypress.env.json b/tests/functional/cypress.env.json index 902e02687..6fdceb0f1 100644 --- a/tests/functional/cypress.env.json +++ b/tests/functional/cypress.env.json @@ -3,5 +3,7 @@ "AUTH0_TOKEN_API":"https://linuxfoundation-dev.auth0.com/oauth/token", "AUTH0_USER_NAME":"vthakur", "AUTH0_PASSWORD":"Test@123", + "LFX_API_TOKEN":"gDYBt6VYW6cmXelL/a3wTmHMa9sD37Xo9gsgaIjncbw=", + "AUTH0_CLIENT_SECRET":"eyJuYW1lIjoiYXV0aDAuanMtdWxwIiwidmVyc2lvbiI6IjkuMTIuMiJ9", "AUTH0_CLIENT_ID":"hquZHO8JNsaIScoayPtCS5VELdn7TnVq" } \ No newline at end of file diff --git a/tests/functional/cypress/e2e/cla-manager.spec.ts b/tests/functional/cypress/e2e/cla-manager.spec.ts new file mode 100644 index 000000000..7905b2311 --- /dev/null +++ b/tests/functional/cypress/e2e/cla-manager.spec.ts @@ -0,0 +1,231 @@ +import {validateApiResponse,validate_200_Status} from '../support/commands' +describe("To Validate cla-manager API call", function () { + //Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/cla-manager +/* +https://api-gw.dev.platform.linuxfoundation.org/acs/v1/api-docs#tag/UserRole +https://api-gw.dev.platform.linuxfoundation.org/acs/v1/api-docs#tag/Role/operation/getRoles +*/ + //Variable for GitHub + const companyID="f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc"; + const projectSFID="a09P000000DsCE5IAN";//sun + const projectSFID_Designee="a09P000000DsNH2IAN" + const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4/`; + let bearerToken: string = ""; + const claGroupID="1baf67ab-d894-4edf-b6fc-c5f939db59f7"; + const sun_claGroupID="01af041c-fa69-4052-a23c-fb8c1d3bef24" + const userEmail="veerendrat@proximabiz.com"; + let companyName="Infosys limited"; + let organization_id=""; + let organization_name=""; + let companySFID=""; + let userLFID="veerendrat"; + let userId="c5ac2857-c263-11ed-94d1-d2349de32229";//veerendrat + + 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("Assigns CLA Manager designee to a given user.", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}company/${companyID}/claGroup/${claGroupID}/cla-manager-designee`, + + auth: { + 'bearer': bearerToken, + }, + body:{ + "userEmail": userEmail + } + }).then((response) => { + // expect(response.duration).to.be.lessThan(20000); + validate_200_Status(response); + companySFID=response.body.list[0].company_sfid; + userLFID=response.body.list[0].lf_username; + cy.log('company_sfid : '+ companySFID); + cy.log('lf_username : '+ userLFID); + //To validate Post response + if (response.status === 200) { + getClaManager(); + } + validateApiResponse("cla-manager/assignCLAManager.json",response) + }); + }); + + it("Allows an existing CLA Manager to add another CLA Manager to the specified Company and Project.", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}company/${companyID}/project/${projectSFID}/cla-manager`, + + auth: { + 'bearer': bearerToken, + }, + failOnStatusCode: false, + body:{ + + "firstName": "veerendrat", + "lastName": "thakur", + "userEmail": userEmail + + } + }).then((response) => { + + // expect(response.duration).to.be.lessThan(20000); + + if(response.status === 200) { + validate_200_Status(response); + // Validate specific data in the response + let list = response.body; + organization_id=list.organization_id; + organization_name=list.organization_name; + expect(list.project_sfid).to.eql(projectSFID) + //To validate schema of response + }else{ + expect(response.body.Message).to.include('error: manager already in signature ACL'); + } + validateApiResponse("cla-manager/createCLAManager.json",response) + }); + }); + + it("Deletes the CLA Manager from CLA Manager list for specified Company and Project", function () { + cy.request({ + method: 'DELETE', + url: `${claEndpoint}company/${companyID}/project/${projectSFID}/cla-manager/${userLFID}`, + + auth: { + 'bearer': bearerToken, + }, + + }).then((response) => { + // expect(response.duration).to.be.lessThan(20000); + expect(response.status).to.eq(204); + }); + }); + + it("Assigns CLA Manager designee to a given user", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}company/${companyID}/project/${projectSFID_Designee}/cla-manager-designee`, + + auth: { + 'bearer': bearerToken, + }, + body:{ + "userEmail": userEmail + } + }).then((response) => { + // expect(response.duration).to.be.lessThan(20000); + validate_200_Status(response); + // Validate specific data in the response + expect(response.body.project_sfid).to.eql(projectSFID_Designee) + if (response.status === 200) { + getClaManager(); + } + validateApiResponse("cla-manager/createCLAManagerDesignee.json",response) + }); + }); + + it("Adds a CLA Manager Designee to the specified Company and Project", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}company/${companyID}/project/${projectSFID_Designee}/cla-manager/requests`, + + auth: { + 'bearer': bearerToken, + }, + body:{ + "contactAdmin": false, + "fullName": "veerendrat cla", + "userEmail": "veerendrat+cla@proximabiz.com" + } + }).then((response) => { + // expect(response.duration).to.be.lessThan(20000); + validate_200_Status(response); + // Validate specific data in the response + expect(response.body.project_sfid).to.eql(projectSFID_Designee) + //To validate schema of response + validateApiResponse("cla-manager/createCLAManagerDesignee.json",response) + }); + }); + + it("Send Notification to CLA Managaers", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}notify-cla-managers`, + + auth: { + 'bearer': bearerToken, + }, + body:{ + "claGroupID": claGroupID, + "companyName": companyName, + "list": [ + { + "email": "vthakur@contractor.linuxfoundation.org", + "name": "vthakur" + } + ], + "signingEntityName": "Linux Foundation", + "userID": userId + } + }).then((response) => { + // expect(response.duration).to.be.lessThan(20000); + expect(response.status).to.eq(204); + }); + }); + + it("Invite Company Admin based on user request to sign CLA", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}user/${userId}/invite-company-admin`, + + auth: { + 'bearer': bearerToken, + }, + body:{ + "claGroupID": sun_claGroupID, + "companyID": companyID, + "contactAdmin": true, + "name": "veerendra thakur", + "userEmail": userEmail + } + }).then((response) => { + // expect(response.duration).to.be.lessThan(20000); + validate_200_Status(response); + // validateApiResponse("cla-manager/assignCLAManager.json",response) + }); + }); + + + function getClaManager(){ + cy.request({ + method: 'GET', + url: `${claEndpoint}company/${companySFID}/user/${userLFID}/claGroupID/${claGroupID}/is-cla-manager-designee`, + auth: { + 'bearer': bearerToken, + }, + }).then((response) => { + validate_200_Status(response); + expect(response.body.hasRole).to.eq(true); + expect(response.body.lfUsername).to.eq(userLFID); + // validateApiResponse("cla-manager/isCLAManagerDesignee.json",response) + }) + } +}); \ No newline at end of file diff --git a/tests/functional/cypress/e2e/events.spec.ts b/tests/functional/cypress/e2e/events.spec.ts index 90e6469c3..cffff74ca 100644 --- a/tests/functional/cypress/e2e/events.spec.ts +++ b/tests/functional/cypress/e2e/events.spec.ts @@ -9,10 +9,9 @@ describe("To Validate events are properly capture via API call", function () { const projectSfid='a09P000000DsNH2IAN'; //project name: easyAutom-child2 const companyID="f7c7ac9c-4dbf-4104-ab3f-6b38a26d82dc"; const compProjectSFID="a092h000004x5tVAAQ"; - const Ajv = require('ajv'); -before(() => { - +before(() => { + cy.request({ method: 'POST', url: Cypress.env("AUTH0_TOKEN_API"), @@ -23,6 +22,7 @@ before(() => { "username":Cypress.env("AUTH0_USER_NAME"), "password":Cypress.env("AUTH0_PASSWORD"), "client_id":Cypress.env("AUTH0_CLIENT_ID"), + // "client_secret": Cypress.env("AUTH0_CLIENT_SECRET"), "audience": "https://api-gw.dev.platform.linuxfoundation.org/", "scope": "access:api openid profile email" } @@ -31,6 +31,7 @@ before(() => { 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 () { @@ -82,7 +83,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); - validateApiResponse("events/getFoundationEvents.json",list); + // validateApiResponse("events/getFoundationEvents.json",list); fetchNextRecords(claEndpointForNextKey,NextKey); }); }); @@ -91,13 +92,13 @@ it("Get events of foundation project - Record should Returns 200 Response", func claEndpointForNextKey=`${claEndpoint}/project/${projectSfid}`; cy.request({ method: 'GET', - url: `${claEndpointForNextKey}`, + url: `${claEndpoint}/project/${projectSfid}`, auth: { 'bearer': bearerToken, } }).then((response) => { expect(response.status).to.eq(200); - expect(response.body).to.not.be.null; + expect(response.body).to.not.be.null; let list=response.body; // Validate specific data in the response expect(list).to.have.property('NextKey'); @@ -164,7 +165,7 @@ it("Get events of foundation project - Record should Returns 200 Response", func }); function fetchNextRecords(URL,NextKey){ - + if(NextKey!==undefined){ cy.request({ method: 'GET', url: `${URL}?nextKey=${NextKey}&pageSize=50`, @@ -180,5 +181,6 @@ it("Get events of foundation project - Record should Returns 200 Response", func fetchNextRecords(URL,updatedNextKey); } }); + } } }) \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/cla-manager/assignCLAManager.json b/tests/functional/cypress/fixtures/cla-manager/assignCLAManager.json new file mode 100644 index 000000000..0a527fe26 --- /dev/null +++ b/tests/functional/cypress/fixtures/cla-manager/assignCLAManager.json @@ -0,0 +1,61 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "list": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "assigned_on": { + "type": "string" + }, + "company_id": { + "type": "string" + }, + "company_sfid": { + "type": "string" + }, + "email": { + "type": "string" + }, + "lf_username": { + "type": "string" + }, + "name": { + "type": "string" + }, + "project_name": { + "type": "string" + }, + "project_sfid": { + "type": "string" + }, + "type": { + "type": "string" + }, + "user_sfid": { + "type": "string" + } + }, + "required": [ + "assigned_on", + "company_id", + "company_sfid", + "email", + "lf_username", + "name", + "project_name", + "project_sfid", + "type", + "user_sfid" + ] + } + ] + } + }, + "required": [ + "list" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/cla-manager/createCLAManager.json b/tests/functional/cypress/fixtures/cla-manager/createCLAManager.json new file mode 100644 index 000000000..3fcc3e97a --- /dev/null +++ b/tests/functional/cypress/fixtures/cla-manager/createCLAManager.json @@ -0,0 +1,64 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "added_on": { + "type": "string" + }, + "approved_on": { + "type": "string" + }, + "cla_group_name": { + "type": "string" + }, + "email": { + "type": "string" + }, + "lf_username": { + "type": "string" + }, + "name": { + "type": "string" + }, + "organization_id": { + "type": "string" + }, + "organization_name": { + "type": "string" + }, + "organization_sfid": { + "type": "string" + }, + "project_id": { + "type": "string" + }, + "project_name": { + "type": "string" + }, + "project_sfid": { + "type": "string" + }, + "signing_entity_name": { + "type": "string" + }, + "user_sfid": { + "type": "string" + } + }, + "required": [ + "added_on", + "approved_on", + "cla_group_name", + "email", + "lf_username", + "name", + "organization_id", + "organization_name", + "organization_sfid", + "project_id", + "project_name", + "project_sfid", + "signing_entity_name", + "user_sfid" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/cla-manager/createCLAManagerDesignee.json b/tests/functional/cypress/fixtures/cla-manager/createCLAManagerDesignee.json new file mode 100644 index 000000000..87cedeee4 --- /dev/null +++ b/tests/functional/cypress/fixtures/cla-manager/createCLAManagerDesignee.json @@ -0,0 +1,48 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "assigned_on": { + "type": "string" + }, + "company_id": { + "type": "string" + }, + "company_sfid": { + "type": "string" + }, + "email": { + "type": "string" + }, + "lf_username": { + "type": "string" + }, + "name": { + "type": "string" + }, + "project_name": { + "type": "string" + }, + "project_sfid": { + "type": "string" + }, + "type": { + "type": "string" + }, + "user_sfid": { + "type": "string" + } + }, + "required": [ + "assigned_on", + "company_id", + "company_sfid", + "email", + "lf_username", + "name", + "project_name", + "project_sfid", + "type", + "user_sfid" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/cla-manager/isCLAManagerDesignee.json b/tests/functional/cypress/fixtures/cla-manager/isCLAManagerDesignee.json new file mode 100644 index 000000000..b9a7c71f3 --- /dev/null +++ b/tests/functional/cypress/fixtures/cla-manager/isCLAManagerDesignee.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "companySFID": { + "type": "string" + }, + "hasRole": { + "type": "boolean" + }, + "lfUsername": { + "type": "string" + } + }, + "required": [ + "companySFID", + "hasRole", + "lfUsername" + ] + } \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/events/getProjectEvents.json b/tests/functional/cypress/fixtures/events/getProjectEvents.json index e590fcd78..c2e738121 100644 --- a/tests/functional/cypress/fixtures/events/getProjectEvents.json +++ b/tests/functional/cypress/fixtures/events/getProjectEvents.json @@ -17,6 +17,15 @@ "EventCLAGroupNameLower": { "type": "string" }, + "EventCompanyID": { + "type": "string" + }, + "EventCompanyName": { + "type": "string" + }, + "EventCompanySFID": { + "type": "string" + }, "EventData": { "type": "string" }, @@ -29,9 +38,6 @@ "EventParentProjectSFID": { "type": "string" }, - "EventProjectID": { - "type": "string" - }, "EventProjectName": { "type": "string" }, @@ -64,11 +70,13 @@ "EventCLAGroupID", "EventCLAGroupName", "EventCLAGroupNameLower", + "EventCompanyID", + "EventCompanyName", + "EventCompanySFID", "EventData", "EventID", "EventParentProjectName", "EventParentProjectSFID", - "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", @@ -86,6 +94,12 @@ "EventCLAGroupID": { "type": "string" }, + "EventCLAGroupName": { + "type": "string" + }, + "EventCLAGroupNameLower": { + "type": "string" + }, "EventData": { "type": "string" }, @@ -98,9 +112,6 @@ "EventParentProjectSFID": { "type": "string" }, - "EventProjectID": { - "type": "string" - }, "EventProjectName": { "type": "string" }, @@ -131,11 +142,12 @@ }, "required": [ "EventCLAGroupID", + "EventCLAGroupName", + "EventCLAGroupNameLower", "EventData", "EventID", "EventParentProjectName", "EventParentProjectSFID", - "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", @@ -242,9 +254,6 @@ "EventParentProjectSFID": { "type": "string" }, - "EventProjectID": { - "type": "string" - }, "EventProjectName": { "type": "string" }, @@ -281,7 +290,6 @@ "EventID", "EventParentProjectName", "EventParentProjectSFID", - "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", @@ -299,6 +307,12 @@ "EventCLAGroupID": { "type": "string" }, + "EventCLAGroupName": { + "type": "string" + }, + "EventCLAGroupNameLower": { + "type": "string" + }, "EventData": { "type": "string" }, @@ -344,6 +358,8 @@ }, "required": [ "EventCLAGroupID", + "EventCLAGroupName", + "EventCLAGroupNameLower", "EventData", "EventID", "EventParentProjectName", @@ -366,12 +382,6 @@ "EventCLAGroupID": { "type": "string" }, - "EventCLAGroupName": { - "type": "string" - }, - "EventCLAGroupNameLower": { - "type": "string" - }, "EventData": { "type": "string" }, @@ -384,6 +394,9 @@ "EventParentProjectSFID": { "type": "string" }, + "EventProjectID": { + "type": "string" + }, "EventProjectName": { "type": "string" }, @@ -414,12 +427,11 @@ }, "required": [ "EventCLAGroupID", - "EventCLAGroupName", - "EventCLAGroupNameLower", "EventData", "EventID", "EventParentProjectName", "EventParentProjectSFID", + "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", @@ -455,9 +467,6 @@ "EventParentProjectSFID": { "type": "string" }, - "EventProjectID": { - "type": "string" - }, "EventProjectName": { "type": "string" }, @@ -494,7 +503,6 @@ "EventID", "EventParentProjectName", "EventParentProjectSFID", - "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", @@ -512,6 +520,12 @@ "EventCLAGroupID": { "type": "string" }, + "EventCLAGroupName": { + "type": "string" + }, + "EventCLAGroupNameLower": { + "type": "string" + }, "EventData": { "type": "string" }, @@ -557,6 +571,8 @@ }, "required": [ "EventCLAGroupID", + "EventCLAGroupName", + "EventCLAGroupNameLower", "EventData", "EventID", "EventParentProjectName", @@ -579,12 +595,6 @@ "EventCLAGroupID": { "type": "string" }, - "EventCLAGroupName": { - "type": "string" - }, - "EventCLAGroupNameLower": { - "type": "string" - }, "EventData": { "type": "string" }, @@ -597,6 +607,9 @@ "EventParentProjectSFID": { "type": "string" }, + "EventProjectID": { + "type": "string" + }, "EventProjectName": { "type": "string" }, @@ -627,12 +640,11 @@ }, "required": [ "EventCLAGroupID", - "EventCLAGroupName", - "EventCLAGroupNameLower", "EventData", "EventID", "EventParentProjectName", "EventParentProjectSFID", + "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", @@ -650,6 +662,12 @@ "EventCLAGroupID": { "type": "string" }, + "EventCLAGroupName": { + "type": "string" + }, + "EventCLAGroupNameLower": { + "type": "string" + }, "EventData": { "type": "string" }, @@ -662,9 +680,6 @@ "EventParentProjectSFID": { "type": "string" }, - "EventProjectID": { - "type": "string" - }, "EventProjectName": { "type": "string" }, @@ -695,11 +710,12 @@ }, "required": [ "EventCLAGroupID", + "EventCLAGroupName", + "EventCLAGroupNameLower", "EventData", "EventID", "EventParentProjectName", "EventParentProjectSFID", - "EventProjectID", "EventProjectName", "EventProjectSFID", "EventSummary", diff --git a/tests/functional/cypress/support/commands.js b/tests/functional/cypress/support/commands.js index cf18537fb..d7bd79773 100644 --- a/tests/functional/cypress/support/commands.js +++ b/tests/functional/cypress/support/commands.js @@ -15,39 +15,12 @@ export function validateApiResponse (schemaPath,response) { } expect(isValid, 'API response schema is valid').to.be.true; }); -} -// let bearerToken={}; - -// Cypress.Commands.add('setBearerToken', (value) => { -// bearerToken = value; -// }); - -/* -Cypress.Commands.add('getBearerToken', () => { - // console.log('Here is token key at getBearerToken: '+bearerToken) - return bearerToken; -}); +}; -Cypress.Commands.add('login', () => { - - 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; - // console.log('Here is token key at cmd: '+bearerToken) - // return bearerToken; - }); -}) -*/ \ No newline at end of file +//To validate & assert 200 response of api +export function validate_200_Status(response){ + expect(response.status).to.eq(200); + expect(response.body).to.not.be.null; + const jsonResponse = JSON.stringify(response.body, null, 2); + cy.log(jsonResponse); +}; \ No newline at end of file diff --git a/tests/functional/run-local-cli.sh b/tests/functional/run-local-cli.sh new file mode 100644 index 000000000..317e57d3b --- /dev/null +++ b/tests/functional/run-local-cli.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Copyright The Linux Foundation and each contributor to LFX. +# SPDX-License-Identifier: MIT + +function validate_env_var() { + if [[ -z "${!1}" ]]; then + echo "$1 is not set." + exit 1 + fi +} + +validate_env_var AUTH0_TOKEN_API +validate_env_var AUTH0_CLIENT_ID +validate_env_var AUTH0_CLIENT_SECRET +validate_env_var AUTH0_TOKEN_AUDIENCE +validate_env_var X_ACL_DEV +validate_env_var LFX_API_TOKEN + +./node_modules/.bin/cypress run \ + --env apiUrl="http://localhost:8080",LFX_API_TOKEN="${LFX_API_TOKEN}",X_ACL_DEV="${X_ACL_DEV}",AUTH0_TOKEN_API="${AUTH0_TOKEN_API}",AUTH0_CLIENT_ID="${AUTH0_CLIENT_ID}",AUTH0_CLIENT_SECRET="${AUTH0_CLIENT_SECRET}",AUTH0_TOKEN_AUDIENCE="${AUTH0_TOKEN_AUDIENCE}" \ No newline at end of file