From 40e1aba28358222a688472297a461152c49e658d Mon Sep 17 00:00:00 2001 From: veerendra thakur Date: Thu, 5 Oct 2023 16:56:57 +0530 Subject: [PATCH] Added cypress test case for cypress-template API Signed-off-by: veerendra thakur --- tests/functional/cypress/e2e/template.cy.ts | 172 ++++++++++++++++++ .../fixtures/templates/getTemplates.json | 172 ++++++++++++++++++ 2 files changed, 344 insertions(+) create mode 100644 tests/functional/cypress/e2e/template.cy.ts create mode 100644 tests/functional/cypress/fixtures/templates/getTemplates.json diff --git a/tests/functional/cypress/e2e/template.cy.ts b/tests/functional/cypress/e2e/template.cy.ts new file mode 100644 index 000000000..b1bc05d4e --- /dev/null +++ b/tests/functional/cypress/e2e/template.cy.ts @@ -0,0 +1,172 @@ +import {validateApiResponse,validate_200_Status,getTokenKey} from '../support/commands' + +describe("To Validate & get list of template via API call", function () { + + // Define a variable for the environment + const environment = Cypress.env("CYPRESS_ENV"); + + // Import the appropriate configuration based on the environment + let appConfig; + if (environment === 'dev') { + appConfig = require('../appConfig/config.dev.ts').appConfig; + } else if (environment === 'production') { + appConfig = require('../appConfig/config.production.ts').appConfig; + } + + //Reference api doc: https://api-gw.dev.platform.linuxfoundation.org/cla-service/v4/api-docs#tag/template + const claEndpoint = `${Cypress.env("APP_URL")}cla-service/v4`; + const claGroupId=appConfig.claGroupId; //project name: easyAutom foundation + let templateId=""; + + let bearerToken: string = null; + before(() => { + if(bearerToken==null){ + getTokenKey(bearerToken); + cy.window().then((win) => { + bearerToken = win.localStorage.getItem('bearerToken'); + }); + } + }); + +it("Endpoint to return the list of available templates", function () { + cy.request({ + method: 'GET', + url: `${claEndpoint}/template`, + auth: { + 'bearer': bearerToken, + } + }).then((response) => { + validate_200_Status(response); + let list=response.body; + templateId=list[0].ID; + expect(list[0].Name).to.eql('Apache Style'); + expect(list[1].Name).to.eql('ASWF 2020 v2.1'); + //To validate schema of response + validateApiResponse("templates/getTemplates.json",response) + }); + }); + +it("Create new templates for a CLA Group", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}/clagroup/${claGroupId}/template`, + auth: { + 'bearer': bearerToken, + },body:{ + "MetaFields": [ + { + "description": "Project's Full Name.", + "name": "Project Name", + "templateVariable": "PROJECT_NAME", + "value" : "Test" + }, + { + "description": "The Full Entity Name of the Project.", + "name": "Project Entity Name", + "templateVariable": "PROJECT_ENTITY_NAME", + "value" : "Test" + }, + { + "description": "The E-Mail Address of the Person managing the CLA. ", + "name": "Contact Email Address", + "templateVariable": "CONTACT_EMAIL", + "value" : "veerendrat@proximabiz.com" + } + ], + "TemplateID": templateId + }, + failOnStatusCode: false + }).then((response) => { + validate_200_Status(response); + expect(response.body.corporatePDFURL); + expect(response.body.individualPDFURL); + }); + }); + +it("Preview ICLA templates for CLA Group", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}/template/preview?template_for=icla`, + auth: { + 'bearer': bearerToken, + },body:{ + "MetaFields": [ + { + "description": "Project's Full Name.", + "name": "Project Name", + "templateVariable": "PROJECT_NAME", + "value" : "Test" + }, + { + "description": "The Full Entity Name of the Project.", + "name": "Project Entity Name", + "templateVariable": "PROJECT_ENTITY_NAME", + "value" : "Test" + }, + { + "description": "The E-Mail Address of the Person managing the CLA. ", + "name": "Contact Email Address", + "templateVariable": "CONTACT_EMAIL", + "value" : "veerendrat@proximabiz.com" + } + ], + "TemplateID": templateId + }, + failOnStatusCode: false + }).then((response) => { + validate_200_Status(response); + expect(response.body.corporatePDFURL); + expect(response.body.individualPDFURL); + }); + }); + +it("Preview CCLA templates for CLA Group", function () { + cy.request({ + method: 'POST', + url: `${claEndpoint}/template/preview?template_for=ccla`, + auth: { + 'bearer': bearerToken, + },body:{ + "MetaFields": [ + { + "description": "Project's Full Name.", + "name": "Project Name", + "templateVariable": "PROJECT_NAME", + "value" : "Test" + }, + { + "description": "The Full Entity Name of the Project.", + "name": "Project Entity Name", + "templateVariable": "PROJECT_ENTITY_NAME", + "value" : "Test" + }, + { + "description": "The E-Mail Address of the Person managing the CLA. ", + "name": "Contact Email Address", + "templateVariable": "CONTACT_EMAIL", + "value" : "veerendrat@proximabiz.com" + } + ], + "TemplateID": templateId + }, + failOnStatusCode: false + }).then((response) => { + validate_200_Status(response); + expect(response.body.corporatePDFURL); + expect(response.body.individualPDFURL); + }); + }); + +it("Preview CLA Group Template PDF", function () { + cy.request({ + method: 'GET', + url: `${claEndpoint}/template/${claGroupId}/preview?claType=ccla&watermark=false`, + auth: { + 'bearer': bearerToken, + } + }).then((response) => { + validate_200_Status(response); + }); + }); + +}) \ No newline at end of file diff --git a/tests/functional/cypress/fixtures/templates/getTemplates.json b/tests/functional/cypress/fixtures/templates/getTemplates.json new file mode 100644 index 000000000..e0aa62f3b --- /dev/null +++ b/tests/functional/cypress/fixtures/templates/getTemplates.json @@ -0,0 +1,172 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "ID": { + "type": "string" + }, + "Name": { + "type": "string" + }, + "cclaFields": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "anchorString": { + "type": "string" + }, + "fieldType": { + "type": "string" + }, + "height": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "isEditable": { + "type": "boolean" + }, + "isOptional": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "offsetX": { + "type": "integer" + }, + "offsetY": { + "type": "integer" + }, + "width": { + "type": "integer" + } + }, + "required": [ + "anchorString", + "fieldType", + "height", + "id", + "isEditable", + "isOptional", + "name", + "offsetX", + "offsetY", + "width" + ] + } + ] + }, + "cclaHtmlBody": { + "type": "string" + }, + "description": { + "type": "string" + }, + "iclaFields": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "anchorString": { + "type": "string" + }, + "fieldType": { + "type": "string" + }, + "height": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "isEditable": { + "type": "boolean" + }, + "isOptional": { + "type": "boolean" + }, + "name": { + "type": "string" + }, + "offsetX": { + "type": "integer" + }, + "offsetY": { + "type": "integer" + }, + "width": { + "type": "integer" + } + }, + "required": [ + "anchorString", + "fieldType", + "id", + "isEditable", + "isOptional", + "name", + "offsetX", + "offsetY", + "width" + ] + } + ] + }, + "iclaHtmlBody": { + "type": "string" + }, + "metaFields": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "name": { + "type": "string" + }, + "templateVariable": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "required": [ + "description", + "name", + "templateVariable", + "value" + ] + } + ] + }, + "templateMajorVersion": { + "type": "integer" + }, + "templateMinorVersion": { + "type": "integer" + } + }, + "required": [ + "ID", + "Name", + "cclaFields", + "description", + "iclaFields", + "metaFields", + "templateMajorVersion" + ] + } + ] + } \ No newline at end of file