move templates API to a intended controller
[vid.git] / vid-webpack-master / cypress / integration / iFrames / instantiation-templates.e2e.ts
1 import * as _ from "lodash";
2 import {PropertyPath} from "lodash";
3
4 describe('Drawing Board: Instantiation Templates', function () {
5
6   describe('Instantiation templates ', () => {
7
8     beforeEach(() => {
9       cy.clearSessionStorage();
10       cy.setTestApiParamToGR();
11       cy.initAAIMock();
12       cy.initGetAAISubDetails();
13       cy.initVidMock();
14       cy.initDrawingBoardUserPermission();
15       cy.login();
16
17       mockAsyncBulkResponse();
18     });
19
20     afterEach(() => {
21       cy.screenshot();
22     });
23
24     describe('Load Page and Deploy', () => {
25
26       it(`Given a stored template - when click "deploy" - then a coherent request should be sent upon deploy`,  () => {
27
28         loadDrawingBoardWithRecreateMode();
29
30         // Then...
31         cy.getElementByDataTestsId("node-vProbe_NC_VNF 0").should('be.visible');
32         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
33       });
34
35       it('Given a stored template - when "edit" vnf and vfmodules are opened - then template’s details are visible as expected and deploy without changes', () => {
36
37         loadDrawingBoardWithRecreateMode();
38
39         // Then...
40         editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0")
41         .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007')
42         .getElementByDataTestsId("productFamily").should('contain', 'Emanuel')
43         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
44         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
45         .getElementByDataTestsId("lineOfBusiness").should('contain', 'zzz1')
46         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
47         .checkPlatformValue('xxx1')
48          .getElementByDataTestsId("cancelButton").click();
49
50         editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0")
51         .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007_lba_Base_01')
52         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
53         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
54         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
55         .getElementByDataTestsId("cancelButton").click();
56
57         editNode("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1")
58         .getElementByDataTestsId("instanceName").should('have.value', 'my_hvf6arlba007_lba_dj_01')
59         .getElementByDataTestsId("volumeGroupName").should('have.value', 'my_special_hvf6arlba007_lba_dj_01_vol')
60         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
61         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
62         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
63         .getElementByDataTestsId("sdncPreLoad").should('have.value', 'on')
64         .getElementByDataTestsId("cancelButton").click();
65
66         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
67         });
68
69       it(`Given a stored template - when "edit" service is opened - then template’s details are visible as expected`,  function ()  {
70
71         loadDrawingBoardWithRecreateMode();
72
73         cy.openServiceContextMenu()
74         .getElementByDataTestsId("context-menu-header-edit-item").click()
75         .getElementByDataTestsId("instanceName").should('have.value', 'vProbe_NC_Service_DG_new_SI')
76         .getElementByDataTestsId("subscriberName").should('contain', 'SILVIA ROBBINS')
77         .getElementByDataTestsId("serviceType").should('contain', 'TYLER SILVIA')
78         .getElementByDataTestsId("owningEntity").should('contain', 'WayneHolland')
79         .getElementByDataTestsId("project").should('contain', 'WATKINS')
80         .getElementByDataTestsId("rollback").should('contain', 'Rollback');
81
82       });
83
84       [
85         {desc: "with changes", modifySomeValues: true},
86         {desc: "without changes", modifySomeValues: false},
87       ].forEach((testCase) => {
88
89         it(`Given a stored template - edit service vnf and vfmodule ${testCase.desc} - deploy request should be ${testCase.desc}`, function () {
90
91           loadDrawingBoardWithRecreateMode();
92
93           //edit service
94           cy.openServiceContextMenu();
95           cy.getElementByDataTestsId("context-menu-header-edit-item").click();
96           if (testCase.modifySomeValues) {
97             cy.clearInput("instanceName");
98             cy.typeToInput("instanceName", "different.instance.name");
99           }
100           cy.getElementByDataTestsId('form-set').click();
101
102           // edit vnf
103           editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0");
104           if (testCase.modifySomeValues) {
105             cy.selectPlatformValue('platform');
106             cy.selectDropdownOptionByText("tenant", "CESAR-100-D-spjg61909");
107           }
108           cy.getElementByDataTestsId('form-set').click();
109
110           //edit vf module
111           editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0");
112           if (testCase.modifySomeValues) {
113             cy.getElementByDataTestsId('sdncPreLoad').click();
114           }
115           cy.getElementByDataTestsId('form-set').click();
116
117           // Then...
118           let vnfPath = [
119             "vnfs", "vProbe_NC_VNF 0"
120           ];
121           let vfModule_0Path = [
122             ...vnfPath, "vfModules",
123             "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0",
124             "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0ahubg",
125           ];
126
127           assertThatBodyFromDeployRequestEqualsToFile(testCase.modifySomeValues ? [
128             {path: ["instanceName"], value: "different.instance.name"},
129             {path: ["existingNames", "vprobe_nc_service_dg_new_si"], value: undefined},
130             {path: ["existingNames", "different.instance.name"], value: ""},
131
132             {path: [...vnfPath, "platformName"], value: "xxx1,platform"},
133             {path: [...vnfPath, "tenantId"], value: "f2f3830e4c984d45bcd00e1a04158a79"},
134
135             {path: [...vfModule_0Path, "sdncPreLoad"], value: true},
136           ] : []);
137         })
138
139       });
140
141     });
142   });
143 });
144
145 function loadDrawingBoardWithRecreateMode() {
146   const serviceModelId = '6cfeeb18-c2b0-49df-987a-da47493c8e38';
147   const templateUuid = "46390edd-7100-46b2-9f18-419bd24fb60b";
148
149   const drawingBoardAction = `RECREATE`;
150   const templateTopologyEndpoint = "templateTopology";
151   cy.route(`**/rest/models/services/${serviceModelId}`,
152     'fixture:../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json')
153   .as('serviceModel');
154
155   cy.route(`**/instantiationTemplates/${templateTopologyEndpoint}/${templateUuid}`,
156     'fixture:../../../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json')
157   .as('templateTopology');
158
159   // When...
160
161   cy.openIframe(`app/ui/#/servicePlanning/${drawingBoardAction}` +
162     `?jobId=${templateUuid}` +
163     `&serviceModelId=${serviceModelId}`);
164
165   cy.wait('@serviceModel');
166   cy.wait('@templateTopology');
167 }
168
169 function editNode(dataTestId: string) {
170   return cy.drawingBoardTreeOpenContextMenuByElementDataTestId(dataTestId)
171     .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
172 }
173
174 function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd() {
175   cy.getDrawingBoardDeployBtn().click();
176   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
177     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json').then((expectedResult) => {
178       convertRollbackOnFailureValueFromStringToBoolean(expectedResult);
179
180       let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
181       cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
182     });
183   });
184 }
185
186
187 function assertThatBodyFromDeployRequestEqualsToFile(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
188   cy.getDrawingBoardDeployBtn().click();
189   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
190
191     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_from_template__set_without_modify1.json').then((expectedResult) => {
192       setDeviationInExpected(expectedResult, deviationFromExpected);
193       cy.deepCompare(xhr.request.body, expectedResult);
194     });
195
196   });
197 }
198
199 function setDeviationInExpected(expectedResult: any, deviation: { path: PropertyPath; value: any }[]) {
200   for (const caveat of deviation) {
201     _.set(expectedResult, caveat.path, caveat.value);
202   }
203 }
204
205   //We use this function because the deployService() on drawing-board-header.component class
206   // changes rollbackOnFailure value from string type to boolean.
207   function convertRollbackOnFailureValueFromStringToBoolean(expectedResult: any) {
208     expectedResult.rollbackOnFailure = Boolean(expectedResult.rollbackOnFailure);
209   }
210
211 function removeIsDirtyFieldFromXhrRequestBody(xhr : any) {
212   let xhrTempBody = JSON.parse(JSON.stringify(xhr.request.body));
213   delete xhrTempBody.isDirty;
214   return xhrTempBody;
215 }
216
217   function mockAsyncBulkResponse() {
218     cy.server().route({
219       url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
220       method: 'POST',
221       status: 200,
222       response: "[]",
223     }).as("expectedPostAsyncInstantiation");
224   }