308597ac6a75a5d486a61d4604d71c43298a8268
[vid.git] /
1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {InstantiationTemplatesModalService} from "./instantiation.templates.modal.service";
4 import {AaiService} from "../../../services/aaiService/aai.service";
5 import {ActivatedRoute, Router} from "@angular/router";
6 import {IframeService} from "../../../utils/iframe.service";
7 import {NgRedux} from "@angular-redux/store";
8 import {FeatureFlagsService} from "../../../services/featureFlag/feature-flags.service";
9 import {InstantiationTemplatesRowModel} from "./instantiation.templates.row.model";
10
11
12 class ActivatedRouteMock<T> {
13   queryParams() {
14     return {
15       serviceModelId: '6e59c5de-f052-46fa-aa7e-2fca9d674c44'
16     }
17   }
18 }
19
20 //
21
22
23 class MockAppStore {}
24
25 describe('instantiation templates modal service', () => {
26   const serviceModelId :string = 'serviceModelId';
27   let injector;
28   let service: InstantiationTemplatesModalService;
29   let httpMock: HttpTestingController;
30   let _aaiService: AaiService;
31   let _activatedRoute: ActivatedRoute;
32   let _router : Router;
33
34
35
36   let router = {
37     navigate: jasmine.createSpy('navigate')
38   };
39
40   beforeAll(done => (async () => {
41     TestBed.configureTestingModule({
42       imports: [HttpClientTestingModule],
43       providers: [InstantiationTemplatesModalService,
44         IframeService,
45         AaiService,
46         FeatureFlagsService,
47         { provide: Router, useValue: router },
48         {provide: ActivatedRoute, useClass: ActivatedRouteMock},
49         {provide: NgRedux, useClass: MockAppStore}
50       ]
51     });
52     await TestBed.compileComponents();
53
54     injector = getTestBed();
55     service = injector.get(InstantiationTemplatesModalService);
56     httpMock = injector.get(HttpTestingController);
57     _aaiService = injector.get(AaiService);
58     _activatedRoute = injector.get(ActivatedRoute);
59     _router = injector.get(Router);
60
61   })().then(done).catch(done.fail));
62
63
64   test('service should be defined', () => {
65     expect(service).toBeDefined();
66   });
67
68   test('convert map to json', () => {
69     let result:InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({
70       requestSummary: {
71         'vnf': 2,
72         'vfModule': 3,
73         'network': 1
74       }
75     });
76     expect(result.summary).toEqual( "vnf: 2, vfModule: 3, network: 1");
77   });
78
79
80   test('convertResponseToUI - should return table data', () => {
81     const jobs = [{
82       "id": 5,
83       "created": 1524995555000,
84       "modified": 1524995556000,
85       "action": "INSTANTIATE",
86       "createdId": null,
87       "modifiedId": null,
88       "rowNum": null,
89       "auditUserId": null,
90       "auditTrail": null,
91       "jobId": "9f88fdb5-bb47-4bf3-8c5f-98f1ad0ec87c",
92       "templateId": "ce4ec177-cfc8-483e-8a2c-b7aea53fd740",
93       "userId": "16807000",
94       "msoRequestId": "c0011670-0e1a-4b74-945d-8bf5aede1d91",
95       "requestId": null,
96       "jobStatus": "FAILED",
97       "statusModifiedDate": 1524995555000,
98       "hidden": false,
99       "pause": false,
100       "owningEntityId": "aaa1",
101       "owningEntityName": "aaa1",
102       "project": "WATKINS",
103       "aicZoneId": "BAN1",
104       "aicZoneName": "VSDKYUTP-BAN1",
105       "tenantId": "1178612d2b394be4834ad77f567c0af2",
106       "tenantName": "AIN Web Tool-15-D-SSPtestcustome",
107       "regionId": "hvf6",
108       "regionName": null,
109       "serviceType": "TYLER SILVIA",
110       "subscriberName": "e433710f-9217-458d-a79d-1c7aff376d89",
111       "serviceInstanceId": null,
112       "serviceInstanceName": 'serviceInstanceName',
113       "serviceModelId": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
114       "serviceModelName": "ComplexService",
115       "serviceModelVersion": "1.0",
116       "createdBulkDate": 1524995555000,
117     }];
118     const tableRows: InstantiationTemplatesRowModel[] = service.convertResponseToUI(jobs);
119     expect(tableRows).toHaveLength(1);
120     expect(tableRows[0].userId).toEqual('16807000');
121     expect((new Date(tableRows[0].createDate)).toISOString()).toEqual('2018-04-29T09:52:35.000Z');
122     expect(tableRows[0].instanceName).toEqual('serviceInstanceName');
123     expect(tableRows[0].instantiationStatus).toEqual('FAILED');
124     expect(tableRows[0].region).toEqual('hvf6 (AAA1)');
125     expect(tableRows[0].tenant).toEqual('AIN Web Tool-15-D-SSPtestcustome');
126     expect(tableRows[0].aicZone).toEqual('VSDKYUTP-BAN1');
127     expect(tableRows[0].jobId).toEqual('9f88fdb5-bb47-4bf3-8c5f-98f1ad0ec87c');
128   });
129
130
131   test('getCloudOwner should remove "-att" from owningEntityName : "att-owner', () => {
132     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({
133       owningEntityName: 'att-owner',
134       regionId: 'regionId'
135     });
136     expect(result.region).toEqual('regionId (OWNER)');
137   });
138
139   test('getCloudOwner should not return owningEntityName if not exist', () => {
140     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({owningEntityName: null, regionId: 'regionId'});
141     expect(result.region).toEqual('regionId');
142   });
143
144   test('getInstanceName should  return instance name id exist if not exist', () => {
145     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({serviceInstanceName: 'instanceName'});
146     expect(result.instanceName).toEqual('instanceName');
147   });
148
149   test('getInstanceName should return <Automatically generated> if instance name not exist', () => {
150     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({});
151     expect(result.instanceName).toEqual('<Automatically generated>');
152   });
153
154   test('filterByUserId should filter table data by userId: not empty list', () => {
155     const jobs : InstantiationTemplatesRowModel[] = [
156       new InstantiationTemplatesRowModel({userId : 'userId_1'}),
157       new InstantiationTemplatesRowModel({userId : 'userId'}),
158       new InstantiationTemplatesRowModel({userId : 'userId'}),
159       new InstantiationTemplatesRowModel({userId : 'userId_1'})
160     ];
161     let result: InstantiationTemplatesRowModel[] = service.filterByUserId('userId', jobs);
162     expect(result).toHaveLength(2);
163   });
164
165   test('filterByUserId should filter table data by userId:  empty list should return empty list', () => {
166     const jobs : InstantiationTemplatesRowModel[] = [];
167     let result: InstantiationTemplatesRowModel[] = service.filterByUserId('userId', jobs);
168     expect(result).toHaveLength(0);
169   });
170
171
172   test('navigateToNewServiceModal should navigate to new service modal', ()=>{
173
174     service.navigateToNewServiceModal(serviceModelId);
175
176     expect(_router.navigate).toBeCalledWith(["/servicePopup"], {"queryParams": {"isCreate": true, "serviceModelId": serviceModelId}, "queryParamsHandling": "merge"});
177   })
178
179 });