summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/cypress/integration/iFrames/instantiation-templates.e2e.ts
blob: 8a68a139379212bc9673114805d801754923a743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
import * as _ from "lodash";
import {PropertyPath} from "lodash";

describe('Drawing Board: Instantiation Templates', function () {

  describe('Instantiation templates ', () => {

    beforeEach(() => {
      cy.clearSessionStorage();
      cy.setTestApiParamToGR();
      cy.initAAIMock();
      cy.initGetAAISubDetails();
      cy.initVidMock();
      cy.initDrawingBoardUserPermission();
      cy.login();

      mockAsyncBulkResponse();
    });

    afterEach(() => {
      cy.screenshot();
    });

    describe('Load Page and Deploy', () => {

      it(`Given a stored template - when click "deploy" - then a coherent request should be sent upon deploy`, () => {

        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);

        // Then...
        cy.getElementByDataTestsId("node-vProbe_NC_VNF 0").should('be.visible');
        assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
      });

      it('Given a template - User can remove existing VNF', () => {

        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);

        removeVNFWithVFModules('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0');
        removeVNFWithVFModules('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0');

        cy.getDrawingBoardDeployBtn().click();
        cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
          cy.deepCompare(bodyOf(xhr).vnfs, {});
        });

      });

      it('Given a template - User can add new VNF', () => {
        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);
        // add new node
        addNewNode('node-vProbe_NC_VNF 0-add-btn')
          .fillVnfPopup()
          .getDrawingBoardDeployBtn().click()
          .wait('@expectedPostAsyncInstantiation').then(xhr => {
          const vnfRequest = bodyOf(xhr).vnfs['vProbe_NC_VNF 0_2'];

          expect(vnfRequest.action).equals("Create");
          expect(vnfRequest.rollbackOnFailure).equals("true");
          expect(vnfRequest.originalName).equals("vProbe_NC_VNF 0");
          expect(vnfRequest.productFamilyId).equals("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
          expect(vnfRequest.lcpCloudRegionId).equals("hvf6");
          expect(vnfRequest.lineOfBusiness).equals("zzz1");
          expect(vnfRequest.platformName).equals("xxx1");
          expect(vnfRequest.tenantId).equals("229bcdc6eaeb4ca59d55221141d01f8e");


          // check instance name not change if empty
          cy.editNode('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0', 0)
            .clearInput('instanceName');
          cy.getElementByDataTestsId('form-set').click({force: true}).then((done) => {
            cy.editNode('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0', 0)
              .getElementByDataTestsId('instanceName').should('be.empty')
          });
        });
      });

      it('Given a template - User can Duplicate VNF', () => {
        const numberOfDuplicate: number = 4;
        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);
        cy.nodeAction('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0', 'Duplicate')
          .getElementByDataTestsId('duplicate-amount-vfmodules').select(numberOfDuplicate.toString())
          .getTagElementContainsText('button', 'Duplicate').click()
          .getDrawingBoardDeployBtn().click()
          .wait('@expectedPostAsyncInstantiation').then(xhr => {
          expect(Object.keys(bodyOf(xhr).vnfs).length).equals(numberOfDuplicate + 2);
        });
      });

      it('Given a stored template - when "edit" vnf and vfmodules are opened - then template’s details are visible as expected and deploy without changes', () => {

        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);

        // Then...
        cy.editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0")
          .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007')
          .getElementByDataTestsId("productFamily").should('contain', 'Emanuel')
          .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
          .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
          .getElementByDataTestsId("lineOfBusiness").should('contain', 'zzz1')
          .getElementByDataTestsId("rollback").should('contain', 'Rollback')
          cy.checkPlatformValue(`xxx1`)
          .getElementByDataTestsId("cancelButton").click();

        cy.editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0")
          .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007_lba_Base_01')
          .getElementByDataTestsId("rollback").should('contain', 'Rollback')
          .getElementByDataTestsId("cancelButton").click();

        cy.editNode("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1")
          .getElementByDataTestsId("instanceName").should('have.value', 'my_hvf6arlba007_lba_dj_01')
          .getElementByDataTestsId("volumeGroupName").should('have.value', 'my_special_hvf6arlba007_lba_dj_01_vol')
          .getElementByDataTestsId("rollback").should('contain', 'Rollback')
          .getElementByDataTestsId("sdncPreLoad").should('have.value', 'on')
          .getElementByDataTestsId("cancelButton").click();

        assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd([
          {path: [...vnfPath, "vnfStoreKey"], value: "vProbe_NC_VNF 0"}, // side-effect
          {path: [...vnfPath2, "vnfStoreKey"], value: "vProbe_NC_VNF 0_1"},
        ]);
      });

      it(`Given a stored template - when "edit" service is opened - then template’s details are visible as expected`, function () {

        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);

        cy.openServiceContextMenu()
          .getElementByDataTestsId("context-menu-header-edit-item").click()
          .getElementByDataTestsId("instanceName").should('have.value', 'vProbe_NC_Service_DG_new_SI')
          .getElementByDataTestsId("subscriberName").should('contain', 'SILVIA ROBBINS')
          .getElementByDataTestsId("serviceType").should('contain', 'TYLER SILVIA')
          .getElementByDataTestsId("owningEntity").should('contain', 'WayneHolland')
          .getElementByDataTestsId("project").should('contain', 'WATKINS')
          .getElementByDataTestsId("rollback").should('contain', 'Rollback');

      });

      it(`Given a stored template - add one VfModule, edit its details, and deploy - deploy is added with the vfModule details`, () => {
        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);

        let newVfModuleName = "new.vfmodule.name";
        let module1ModelId = "VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1";
        let module1CustomizationId = `vprobe_nc_vnf0..${module1ModelId}`;

        // Click target VNF on right tree
        cy.getElementByDataTestsId('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0').first().click();

        // Click [+] vfModule on left tree
        cy.drawingBoardPressAddButtonByElementName(`node-${module1CustomizationId}`)
          .click({force: true});

        cy.editNode(`node-c09e4530-8fd8-418f-9483-2f57ce927b05-${module1CustomizationId}`, 1);
        cy.clearInput("instanceName");
        cy.typeToInput("instanceName", newVfModuleName);
        cy.getElementByDataTestsId('form-set').click();

        // Then...
        cy.getReduxState().then((state) => {
          let vfModules_1Path = [
            ...vnfPath, "vfModules", module1CustomizationId,
          ];

          let serviceInstanceElementOnRedux = state.service.serviceInstance[(templateWithVnfSetup.serviceModelId)];
          let latestVfModule_1Path = findPathOfLatestVfModule(serviceInstanceElementOnRedux, vfModules_1Path);

          // This is a funny merge, as values are already there, but that way ensures
          // the values that selected are really deployed, while limiting the cost of
          // maintenance, by taking other vfModule's fields as granted.
          let latestVfModule_1ExpectedValue = _.merge(
            _.get(serviceInstanceElementOnRedux, latestVfModule_1Path),
            {
              instanceName: newVfModuleName,
              volumeGroupName: `${newVfModuleName}_vol`,
            }
          );

          assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd([
            {path: [...vnfPath, "vnfStoreKey"], value: "vProbe_NC_VNF 0"},   // side-effect
            {path: [...vnfPath2, "vnfStoreKey"], value: "vProbe_NC_VNF 0_1"},
            {path: ["existingNames", newVfModuleName], value: ""},
            {path: ["existingNames", `${newVfModuleName}_vol`], value: ""},
            {path: latestVfModule_1Path, value: latestVfModule_1ExpectedValue},
            {path: ["validationCounter"], value: null},  // side-effect
          ]);
        });

      });

      it('Given a template - User can remove existing vfmodule', function () {

        cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);
        cy.nodeAction('node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1', 'Remove');
        let removed_vfModule_Path = [
          ...vnfPath, "vfModules",
          "vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1",
        ];

        assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd([
          {path: [...vnfPath, "vnfStoreKey"], value: "vProbe_NC_VNF 0"}, // side-effect
          {path: [...vnfPath2, "vnfStoreKey"], value: "vProbe_NC_VNF 0_1"},
          {path: [...removed_vfModule_Path], value: undefined},
        ]);
      });

      [
        {desc: "with changes", modifySomeValues: true},
        {desc: "without changes", modifySomeValues: false},
      ].forEach((testCase) => {

        it(`Given a stored template - edit service vnf and vfmodule ${testCase.desc} - deploy request should be ${testCase.desc}`, function () {

          cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);

          //edit service
          cy.openServiceContextMenu();
          cy.getElementByDataTestsId("context-menu-header-edit-item").click();
          if (testCase.modifySomeValues) {
            cy.clearInput("instanceName");
            cy.typeToInput("instanceName", "different.instance.name");
          }
          cy.getElementByDataTestsId('form-set').click();

          // edit vnf
          cy.editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0");
          if (testCase.modifySomeValues) {
            cy.selectPlatformValue(`platform`);
            cy.selectDropdownOptionByText("tenant", "CESAR-100-D-spjg61909");
          }
          cy.getElementByDataTestsId('form-set').click();

          //edit vf module
          cy.editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0");
          if (testCase.modifySomeValues) {
            cy.getElementByDataTestsId('sdncPreLoad').click();
          }
          cy.getElementByDataTestsId('form-set').click();

          // Then...
          let vfModule_0Path = [
            ...vnfPath, "vfModules",
            "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0",
            "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0ahubg",
          ];

          assertThatBodyFromDeployRequestEqualsToFile(testCase.modifySomeValues ? [
            {path: ["instanceName"], value: "different.instance.name"},
            {path: ["existingNames", "vprobe_nc_service_dg_new_si"], value: undefined},
            {path: ["existingNames", "different.instance.name"], value: ""},

            {path: [...vnfPath, "platformName"], value: "xxx1,platform"},
            {path: [...vnfPath, "tenantId"], value: "f2f3830e4c984d45bcd00e1a04158a79"},

            {path: [...vfModule_0Path, "sdncPreLoad"], value: true},
          ] : []);
        })

      });

      it(`Given a stored template of Network - - it is loaded`, () => {

        cy.loadDrawingBoardWithRecreateModeNetwork(templateWithNetworkSetup);

        // Then...
        cy.getElementByDataTestsId("node-SR-IOV Provider 2-1").should('be.visible');
        cy.getElementByDataTestsId("node-SR-IOV Provider 2-2").should('be.visible');
        assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd_network();
      });

      it(`Given a stored template of Network - User can remove existing network`, () => {

        cy.loadDrawingBoardWithRecreateModeNetwork(templateWithNetworkSetup);

        cy.nodeAction('node-01f4c475-3f89-4f00-a2f4-39a873dba0ae-SR-IOV Provider 2-1', 'Remove');
        let removed_network_Path = [
          "networks", "SR-IOV Provider 2-1",
        ];

        let removed_network_counter_Path = [
          "existingNetworksCounterMap", "f6b6d141-0d4c-427d-ad35-797f3d1abe71",
        ];

        assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd_network([
          {path: removed_network_Path, value: undefined},
          {path: removed_network_counter_Path, value: 0},
        ]);
      });

      it('Given a template - User can add a new network', () => {

        cy.loadDrawingBoardWithRecreateModeNetwork(templateWithNetworkSetup);

        // add new node
        addNewNode('node-SR-IOV Provider 2-1-add-btn')
          .fillNetworkPopup()
          .getDrawingBoardDeployBtn().click()
          .wait('@expectedPostAsyncInstantiation').then(xhr => {
          const networkRequest = bodyOf(xhr).networks['SR-IOV Provider 2-1_1'];

          expect(networkRequest.action).equals("Create");
          expect(networkRequest.rollbackOnFailure).equals("true");
          expect(networkRequest.originalName).equals("SR-IOV Provider 2-1");
          expect(networkRequest.productFamilyId).equals("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
          expect(networkRequest.lcpCloudRegionId).equals("hvf6");
          expect(networkRequest.lineOfBusiness).equals("zzz1");
          expect(networkRequest.platformName).equals("xxx1");
          expect(networkRequest.tenantId).equals("229bcdc6eaeb4ca59d55221141d01f8e");
        });
      });
    });
  });
});

let apiTestResources = '../vid-automation/src/test/resources/asyncInstantiation/';

const templateWithVnfSetup = {
  serviceModelId: '6cfeeb18-c2b0-49df-987a-da47493c8e38',
  instanceTemplateFile: apiTestResources + 'templates__instance_template.json',
  instanceTemplateSetWithoutModifyFile: apiTestResources + 'templates__instance_from_template__set_without_modify1.json',
  serviceModelFile: '../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json',
};

const templateWithNetworkSetup = {
  serviceModelId: 'a1a14610-ee40-4049-8007-0608a20dd1fa',
  instanceTemplateFile: apiTestResources + 'templates__instance_template_network.json',
  serviceModelFile: '../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model_network.json',
};

const vnfPath = [
  "vnfs", "vProbe_NC_VNF 0"
];

const vnfPath2 = [
  "vnfs", "vProbe_NC_VNF 0_1"
];



function addNewNode(dataTestId: string) {
  return cy.getElementByDataTestsId(dataTestId).click({force: true})
}

function removeVNFWithVFModules(dataTestId: string) {
  return cy.nodeAction(dataTestId, 'Remove')
    .getTagElementContainsText('button', 'Remove VNF').click()
}

function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
  assertThatBodyFromDeployRequestEqualsToTemplateFromBackEndInternal(templateWithVnfSetup.instanceTemplateFile, deviationFromExpected);
}

function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd_network(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
  assertThatBodyFromDeployRequestEqualsToTemplateFromBackEndInternal(templateWithNetworkSetup.instanceTemplateFile, deviationFromExpected);
}

function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEndInternal(filePathOfExpected: string, deviationFromExpected: { path: PropertyPath; value: any }[]) {
  cy.getDrawingBoardDeployBtn().click();
  cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
    cy.readFile(filePathOfExpected).then((expectedResult) => {
      convertRollbackOnFailureValueFromStringToBoolean(expectedResult);

      let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
      setDeviationInExpected(expectedResult, deviationFromExpected);
      cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
    });
  });
}


function assertThatBodyFromDeployRequestEqualsToFile(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
  cy.getDrawingBoardDeployBtn().click();
  cy.wait('@expectedPostAsyncInstantiation').then(xhr => {

    cy.readFile(templateWithVnfSetup.instanceTemplateSetWithoutModifyFile).then((expectedResult) => {
      setDeviationInExpected(expectedResult, deviationFromExpected);
      cy.deepCompare(xhr.request.body, expectedResult);
    });

  });
}

function bodyOf(xhr: Cypress.WaitXHR) {
  return JSON.parse(JSON.stringify(xhr.request.body));
}

function setDeviationInExpected(expectedResult: any, deviations: { path: PropertyPath; value: any }[]) {
  for (const deviation of deviations) {
    _.set(expectedResult, deviation.path, deviation.value);
  }
}

function findPathOfLatestVfModule(serviceInstanceElementFromRedux: any, vfModulesContainerPath: string[]) {
  let latestVfModuleRandomlySelectedKey: string = _.last(_.keys(
    _.get(serviceInstanceElementFromRedux, vfModulesContainerPath)
  )) as string;

  return [...vfModulesContainerPath, latestVfModuleRandomlySelectedKey];
}

//We use this function because the deployService() on drawing-board-header.component class
// changes rollbackOnFailure value from string type to boolean.
function convertRollbackOnFailureValueFromStringToBoolean(expectedResult: any) {
  expectedResult.rollbackOnFailure = Boolean(expectedResult.rollbackOnFailure);
}

function removeIsDirtyFieldFromXhrRequestBody(xhr: any) {
  let xhrTempBody = bodyOf(xhr);
  delete xhrTempBody.isDirty;
  return xhrTempBody;
}

function mockAsyncBulkResponse() {
  cy.server().route({
    url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
    method: 'POST',
    status: 200,
    response: true,
  }).as("expectedPostAsyncInstantiation");
}