Merge "Create API test that verify original template should not be changed after...
[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           {path: [...vnfPath, "vnfStoreKey"], value: "vProbe_NC_VNF 0"}, // side-effect
68         ]);
69         });
70
71       it(`Given a stored template - when "edit" service is opened - then template’s details are visible as expected`,  function ()  {
72
73         loadDrawingBoardWithRecreateMode();
74
75         cy.openServiceContextMenu()
76         .getElementByDataTestsId("context-menu-header-edit-item").click()
77         .getElementByDataTestsId("instanceName").should('have.value', 'vProbe_NC_Service_DG_new_SI')
78         .getElementByDataTestsId("subscriberName").should('contain', 'SILVIA ROBBINS')
79         .getElementByDataTestsId("serviceType").should('contain', 'TYLER SILVIA')
80         .getElementByDataTestsId("owningEntity").should('contain', 'WayneHolland')
81         .getElementByDataTestsId("project").should('contain', 'WATKINS')
82         .getElementByDataTestsId("rollback").should('contain', 'Rollback');
83
84       });
85
86       it(`Given a stored template - add one VfModule, edit its details, and deploy - deploy is added with the vfModule details`, () => {
87         loadDrawingBoardWithRecreateMode();
88
89         let newVfModuleName = "new.vfmodule.name";
90         let module1ModelId = "VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1";
91         let module1CustomizationId = `vprobe_nc_vnf0..${module1ModelId}`;
92
93         // Click target VNF on right tree
94         cy.getElementByDataTestsId('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0').click();
95
96         // Click [+] vfModule on left tree
97         cy.drawingBoardPressAddButtonByElementName(`node-${module1CustomizationId}`)
98           .click({force: true});
99
100         editNode(`node-c09e4530-8fd8-418f-9483-2f57ce927b05-${module1CustomizationId}`, 1);
101           cy.clearInput("instanceName");
102           cy.typeToInput("instanceName", newVfModuleName);
103           cy.selectDropdownOptionByText('lcpRegion', 'hvf6');
104           cy.selectDropdownOptionByText('tenant', 'DN5242-Nov21-T1');
105           cy.getElementByDataTestsId('form-set').click();
106
107         // Then...
108         cy.getReduxState().then((state) => {
109           let vfModules_1Path = [
110             ...vnfPath, "vfModules", module1CustomizationId,
111           ];
112
113           let serviceInstanceElementOnRedux = state.service.serviceInstance[serviceModelId];
114           let latestVfModule_1Path = findPathOfLatestVfModule(serviceInstanceElementOnRedux, vfModules_1Path);
115
116           // This is a funny merge, as values are already there, but that way ensures
117           // the values that selected are really deployed, while limiting the cost of
118           // maintenance, by taking other vfModule's fields as granted.
119           let latestVfModule_1ExpectedValue = _.merge(
120             _.get(serviceInstanceElementOnRedux, latestVfModule_1Path),
121             {
122               instanceName: newVfModuleName,
123               volumeGroupName: `${newVfModuleName}_vol`,
124               lcpCloudRegionId: "hvf6",
125               tenantId: "4914ab0ab3a743e58f0eefdacc1dde77",
126             }
127           );
128
129           assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd([
130             {path: [...vnfPath, "vnfStoreKey"], value: "vProbe_NC_VNF 0"},   // side-effect
131             {path: ["existingNames", newVfModuleName], value: ""},
132             {path: ["existingNames", `${newVfModuleName}_vol`], value: ""},
133             {path: latestVfModule_1Path, value: latestVfModule_1ExpectedValue},
134             {path: ["validationCounter"], value: null},  // side-effect
135           ]);
136         });
137
138       });
139
140       [
141         {desc: "with changes", modifySomeValues: true},
142         {desc: "without changes", modifySomeValues: false},
143       ].forEach((testCase) => {
144
145         it(`Given a stored template - edit service vnf and vfmodule ${testCase.desc} - deploy request should be ${testCase.desc}`, function () {
146
147           loadDrawingBoardWithRecreateMode();
148
149           //edit service
150           cy.openServiceContextMenu();
151           cy.getElementByDataTestsId("context-menu-header-edit-item").click();
152           if (testCase.modifySomeValues) {
153             cy.clearInput("instanceName");
154             cy.typeToInput("instanceName", "different.instance.name");
155           }
156           cy.getElementByDataTestsId('form-set').click();
157
158           // edit vnf
159           editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0");
160           if (testCase.modifySomeValues) {
161             cy.selectPlatformValue('platform');
162             cy.selectDropdownOptionByText("tenant", "CESAR-100-D-spjg61909");
163           }
164           cy.getElementByDataTestsId('form-set').click();
165
166           //edit vf module
167           editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0");
168           if (testCase.modifySomeValues) {
169             cy.getElementByDataTestsId('sdncPreLoad').click();
170           }
171           cy.getElementByDataTestsId('form-set').click();
172
173           // Then...
174           let vfModule_0Path = [
175             ...vnfPath, "vfModules",
176             "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0",
177             "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0ahubg",
178           ];
179
180           assertThatBodyFromDeployRequestEqualsToFile(testCase.modifySomeValues ? [
181             {path: ["instanceName"], value: "different.instance.name"},
182             {path: ["existingNames", "vprobe_nc_service_dg_new_si"], value: undefined},
183             {path: ["existingNames", "different.instance.name"], value: ""},
184
185             {path: [...vnfPath, "platformName"], value: "xxx1,platform"},
186             {path: [...vnfPath, "tenantId"], value: "f2f3830e4c984d45bcd00e1a04158a79"},
187
188             {path: [...vfModule_0Path, "sdncPreLoad"], value: true},
189           ] : []);
190         })
191
192       });
193
194     });
195   });
196 });
197
198 const serviceModelId = '6cfeeb18-c2b0-49df-987a-da47493c8e38';
199
200 const vnfPath = [
201   "vnfs", "vProbe_NC_VNF 0"
202 ];
203
204 function loadDrawingBoardWithRecreateMode() {
205   const templateUuid = "46390edd-7100-46b2-9f18-419bd24fb60b";
206
207   const drawingBoardAction = `RECREATE`;
208   const templateTopologyEndpoint = "templateTopology";
209   cy.route(`**/rest/models/services/${serviceModelId}`,
210     'fixture:../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json')
211   .as('serviceModel');
212
213   cy.route(`**/instantiationTemplates/${templateTopologyEndpoint}/${templateUuid}`,
214     'fixture:../../../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json')
215   .as('templateTopology');
216
217   // When...
218
219   cy.openIframe(`app/ui/#/servicePlanning/${drawingBoardAction}` +
220     `?jobId=${templateUuid}` +
221     `&serviceModelId=${serviceModelId}`);
222
223   cy.wait('@serviceModel');
224   cy.wait('@templateTopology');
225 }
226
227 function editNode(dataTestId: string, index ?: number) {
228   return cy.drawingBoardTreeOpenContextMenuByElementDataTestId(dataTestId, index)
229     .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
230 }
231
232 function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
233   cy.getDrawingBoardDeployBtn().click();
234   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
235     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json').then((expectedResult) => {
236       convertRollbackOnFailureValueFromStringToBoolean(expectedResult);
237
238       let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
239       setDeviationInExpected(expectedResult, deviationFromExpected);
240       cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
241     });
242   });
243 }
244
245
246 function assertThatBodyFromDeployRequestEqualsToFile(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
247   cy.getDrawingBoardDeployBtn().click();
248   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
249
250     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_from_template__set_without_modify1.json').then((expectedResult) => {
251       setDeviationInExpected(expectedResult, deviationFromExpected);
252       cy.deepCompare(xhr.request.body, expectedResult);
253     });
254
255   });
256 }
257
258 function setDeviationInExpected(expectedResult: any, deviations: { path: PropertyPath; value: any }[]) {
259   for (const deviation of deviations) {
260     _.set(expectedResult, deviation.path, deviation.value);
261   }
262 }
263
264 function findPathOfLatestVfModule(serviceInstanceElementFromRedux: any, vfModulesContainerPath: string[]) {
265   let latestVfModuleRandomlySelectedKey: string = _.last(_.keys(
266     _.get(serviceInstanceElementFromRedux, vfModulesContainerPath)
267   )) as string;
268
269   return [...vfModulesContainerPath, latestVfModuleRandomlySelectedKey];
270 }
271
272   //We use this function because the deployService() on drawing-board-header.component class
273   // changes rollbackOnFailure value from string type to boolean.
274   function convertRollbackOnFailureValueFromStringToBoolean(expectedResult: any) {
275     expectedResult.rollbackOnFailure = Boolean(expectedResult.rollbackOnFailure);
276   }
277
278 function removeIsDirtyFieldFromXhrRequestBody(xhr : any) {
279   let xhrTempBody = JSON.parse(JSON.stringify(xhr.request.body));
280   delete xhrTempBody.isDirty;
281   return xhrTempBody;
282 }
283
284   function mockAsyncBulkResponse() {
285     cy.server().route({
286       url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
287       method: 'POST',
288       status: 200,
289       response: "[]",
290     }).as("expectedPostAsyncInstantiation");
291   }