aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/components/vnf-popup/vnf-instance-details/vnf-instance-details.service.spec.ts
blob: 41ddb437278c60b548c32f6dd45502727ec57f3a (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
import { TestBed, getTestBed } from '@angular/core/testing';
import {
  HttpClientTestingModule,
  HttpTestingController
} from '@angular/common/http/testing';
import { VnfInstanceDetailsService } from './vnf-instance-details.service';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { NumbersLettersUnderscoreValidator } from '../../../shared/components/validators/numbersLettersUnderscore/numbersLettersUnderscore.validator';

describe('Vnf Instance Details Service', () => {
  let injector;
  let service: VnfInstanceDetailsService;
  let httpMock: HttpTestingController;

  let SERVICE_ID: string = '1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd';
  let serviceHierarchy;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [HttpClientTestingModule],
      providers: [VnfInstanceDetailsService]
    });

    injector = getTestBed();
    service = injector.get(VnfInstanceDetailsService);
    httpMock = injector.get(HttpTestingController);
    serviceHierarchy = getServiceServiceHierarchy();
  });


  describe('#hasInstanceNameError', ()=> {
    it('hasInstanceNameError should return true if instanceName is illegal and enabled', (done: DoneFn) => {
      let form = generateFormGroup();
      form.controls['instanceName'].setValue('----');
      form.controls['instanceName'].setErrors({
        pattern : true
      });
      form.controls['instanceName'].markAsTouched();
      let result = service.hasInstanceNameError(form);
      expect(result).toBeTruthy();
      done();
    });

    it('hasInstanceNameError should return false if instanceName is illegal and enabled and pattern is ok', (done: DoneFn) => {
      let form = generateFormGroup();
      form.controls['instanceName'].setValue('----');
      form.controls['instanceName'].setErrors({
        otherError : true
      });
      form.controls['instanceName'].markAsTouched();
      let result = service.hasInstanceNameError(form);
      expect(result).toBeFalsy();
      done();
    });
  });

  describe('#isUnique', () => {
    it('Create Mode: should return false if instanceName exist', (done: DoneFn) => {
      serviceHierarchy = getServiceServiceHierarchy();
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'uniqueInstanceName', false);
      expect(result).toBeFalsy();
      done();
    });

    it('Update Mode: should return true if instanceName exist once', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'uniqueInstanceName', true);
      expect(result).toBeTruthy()
      done();
    });

    it('Create Mode: should return true if instanceName not exist', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'uniqueInstanceNameNotExist', false);
      expect(result).toBeTruthy();
      done();
    });

    it('Create Mode: should return false if instanceName exist inside vf modules', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'uniqueInstanceNameVfModule', false);
      expect(result).toBeFalsy();
      done();
    });

    it('Update Mode: should return true if instanceName  exist once inside vf modules', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'uniqueInstanceNameVfModule', true);
      expect(result).toBeTruthy();
      done();
    });

    it('Create Mode: should return true if instanceName is not exist at vf modules and vnfs', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'uniqueInstanceNameVfModuleNotExist', false);
      expect(result).toBeTruthy();
      done();
    });

    it('Create Mode: should return false if instanceName exist service name', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'Instance-Name', false);
      expect(result).toBeFalsy();
      done();
    });

    it('Create Mode: should return false if volumeGroupName exist service name', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'volumeGroupNameExist', false);
      expect(result).toBeFalsy();
      done();
    });

    it('Create Mode: should return true if volumeGroupName not exist service name', (done: DoneFn) => {
      let result = service.isUnique(serviceHierarchy, SERVICE_ID, 'volumeGroupNameNotExist', false);
      expect(result).toBeTruthy();
      done();
    });
  });

  function getServiceServiceHierarchy() {
    return JSON.parse(JSON.stringify(
      {
        "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd": {
          "vnfs": {
            "2017-388_ADIOD-vPE 1": {
              "rollbackOnFailure": "true",
              "vfModules": {},
              "instanceParams": [
                {}
              ],
              "productFamilyId": "a4f6f2ae-9bf5-4ed7-b904-06b2099c4bd7",
              "lcpCloudRegionId": "AAIAIC25",
              "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
              "lineOfBusiness": "zzz1",
              "platformName": "platform",
              "instanceName": "uniqueInstanceName",
              "modelInfo": {
                "modelInvariantId": "00beb8f9-6d39-452f-816d-c709b9cbb87d",
                "modelVersionId": "0903e1c0-8e03-4936-b5c2-260653b96413",
                "modelName": "2017-388_ADIOD-vPE",
                "modelVersion": "1.0",
                "modelCustomizationId": "280dec31-f16d-488b-9668-4aae55d6648a",
                "modelCustomizationName": "2017-388_ADIOD-vPE 1"
              },
              "isUserProvidedNaming": true
            },
            "2017-388_ADIOD-vPE 0": {
              "rollbackOnFailure": "true",
              "vfModules": {},
              "instanceParams": [
                {}
              ],
              "productFamilyId": null,
              "lcpCloudRegionId": "mtn6",
              "tenantId": "1178612d2b394be4834ad77f567c0af2",
              "lineOfBusiness": "ECOMP",
              "platformName": "xxx1",
              "instanceName": "blaaa",
              "modelInfo": {
                "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
                "modelVersionId": "afacccf6-397d-45d6-b5ae-94c39734b168",
                "modelName": "2017-388_ADIOD-vPE",
                "modelVersion": "4.0",
                "modelCustomizationId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c",
                "modelCustomizationName": "2017-388_ADIOD-vPE 0"
              },
              "isUserProvidedNaming": true
            },
            "2017488_ADIODvPE 0": {
              "rollbackOnFailure": "true",
              "vfModules": {
                "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1": {
                  "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_vRE_BV..module-1": {
                    "rollbackOnFailure": "true",
                    "instanceName": "uniqueInstanceNameVfModule",
                    "volumeGroupName": "volumeGroupNameExist",
                    "modelInfo": {
                      "modelInvariantId": "7253ff5c-97f0-4b8b-937c-77aeb4d79aa1",
                      "modelVersionId": "25284168-24bb-4698-8cb4-3f509146eca5",
                      "modelName": "2017488AdiodVpe..ADIOD_vRE_BV..module-1",
                      "modelVersion": "6"
                    }
                  }
                }
              },
              "instanceParams": [
                {}
              ],
              "productFamilyId": "ebc3bc3d-62fd-4a3f-a037-f619df4ff034",
              "lcpCloudRegionId": "mtn6",
              "tenantId": "19c5ade915eb461e8af52fb2fd8cd1f2",
              "lineOfBusiness": "zzz1",
              "platformName": "platform",
              "instanceName": "2017488_ADIODvPE",
              "modelInfo": {
                "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
                "modelVersionId": "69e09f68-8b63-4cc9-b9ff-860960b5db09",
                "modelName": "2017488_ADIODvPE",
                "modelVersion": "5.0",
                "modelCustomizationId": "1da7b585-5e61-4993-b95e-8e6606c81e45",
                "modelCustomizationName": "2017488_ADIODvPE 0"
              },
              "isUserProvidedNaming": true
            }
          },
          "instanceParams": [
            {}
          ],
          "globalSubscriberId": "e433710f-9217-458d-a79d-1c7aff376d89",
          "productFamilyId": "17cc1042-527b-11e6-beb8-9e71128cae77",
          "subscriptionServiceType": "VIRTUAL USP",
          "lcpCloudRegionId": "AAIAIC25",
          "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
          "aicZoneId": "DKJ1",
          "projectName": "DFW",
          "owningEntityId": "aaa1",
          "instanceName": "Instance-Name",
          "bulkSize": 1,
          "modelInfo": {
            "modelInvariantId": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
            "modelVersionId": "1a80c596-27e5-4ca9-b5bb-e03a7fd4c0fd",
            "modelName": "action-data",
            "modelVersion": "1.0"
          },
          "tenantName": "USP-SIP-IC-24335-T-01",
          "aicZoneName": "DKJSJDKA-DKJ1",
          "isUserProvidedNaming": true
        }
      }
    ));
  }

  function generateFormGroup() {
    return new FormGroup({
      productFamilyId: new FormControl(),
      lcpCloudRegionId: new FormControl(Validators.required),
      tenantId: new FormControl({value: null, disabled: false}, Validators.required),
      legacyRegion: new FormControl(),
      lineOfBusiness: new FormControl(),
      platformName: new FormControl(Validators.required),
      rollbackOnFailure: new FormControl(Validators.required),
      instanceName: new FormControl({value: null}, Validators.compose([Validators.required, NumbersLettersUnderscoreValidator.valid]))

    });
  }

});