UT convertResponseToUI - use ISOString to compare dates
[vid.git] / vid-webpack-master / src / app / shared / components / genericFormPopup / instantiationTemplatesModal / instantiation.templates.modal.service.spec.ts
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} 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 class MockAppStore {
21
22 }
23
24 describe('instantiation templates modal service', () => {
25   let injector;
26   let service: InstantiationTemplatesModalService;
27   let httpMock: HttpTestingController;
28   let _aaiService: AaiService;
29   let _activatedRoute: ActivatedRoute;
30
31   beforeAll(done => (async () => {
32     TestBed.configureTestingModule({
33       imports: [HttpClientTestingModule],
34       providers: [InstantiationTemplatesModalService,
35         IframeService,
36         AaiService,
37         FeatureFlagsService,
38         {provide: ActivatedRoute, useClass: ActivatedRouteMock},
39         {provide: NgRedux, useClass: MockAppStore}
40       ]
41     });
42     await TestBed.compileComponents();
43
44     injector = getTestBed();
45     service = injector.get(InstantiationTemplatesModalService);
46     httpMock = injector.get(HttpTestingController);
47     _aaiService = injector.get(AaiService);
48     _activatedRoute = injector.get(ActivatedRoute);
49
50   })().then(done).catch(done.fail));
51
52
53   test('service should be defined', () => {
54     expect(service).toBeDefined();
55   });
56
57
58   test('convertResponseToUI - should return table data', () => {
59     const jobs = [{
60       "id": 5,
61       "created": 1524995555000,
62       "modified": 1524995556000,
63       "action": "INSTANTIATE",
64       "createdId": null,
65       "modifiedId": null,
66       "rowNum": null,
67       "auditUserId": null,
68       "auditTrail": null,
69       "jobId": "9f88fdb5-bb47-4bf3-8c5f-98f1ad0ec87c",
70       "templateId": "ce4ec177-cfc8-483e-8a2c-b7aea53fd740",
71       "userId": "16807000",
72       "msoRequestId": "c0011670-0e1a-4b74-945d-8bf5aede1d91",
73       "requestId": null,
74       "jobStatus": "FAILED",
75       "statusModifiedDate": 1524995555000,
76       "hidden": false,
77       "pause": false,
78       "owningEntityId": "aaa1",
79       "owningEntityName": "aaa1",
80       "project": "WATKINS",
81       "aicZoneId": "BAN1",
82       "aicZoneName": "VSDKYUTP-BAN1",
83       "tenantId": "1178612d2b394be4834ad77f567c0af2",
84       "tenantName": "AIN Web Tool-15-D-SSPtestcustome",
85       "regionId": "hvf6",
86       "regionName": null,
87       "serviceType": "TYLER SILVIA",
88       "subscriberName": "e433710f-9217-458d-a79d-1c7aff376d89",
89       "serviceInstanceId": null,
90       "serviceInstanceName": 'serviceInstanceName',
91       "serviceModelId": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
92       "serviceModelName": "ComplexService",
93       "serviceModelVersion": "1.0",
94       "createdBulkDate": 1524995555000,
95       "isRetryEnabled": false
96     }];
97     const tableRows: InstantiationTemplatesRowModel[] = service.convertResponseToUI(jobs);
98     expect(tableRows).toHaveLength(1);
99     expect(tableRows[0].userId).toEqual('16807000');
100     expect((new Date(tableRows[0].createDate)).toISOString()).toEqual('2018-04-29T09:52:35.000Z');
101     expect(tableRows[0].instanceName).toEqual('serviceInstanceName');
102     expect(tableRows[0].instantiationStatus).toEqual('FAILED');
103     expect(tableRows[0].region).toEqual('hvf6 (AAA1)');
104     expect(tableRows[0].tenant).toEqual('AIN Web Tool-15-D-SSPtestcustome');
105     expect(tableRows[0].aicZone).toEqual('VSDKYUTP-BAN1');
106     expect(tableRows[0].jobId).toEqual('9f88fdb5-bb47-4bf3-8c5f-98f1ad0ec87c');
107   });
108
109
110   test('getCloudOwner should remove "-att" from owningEntityName : "att-owner', () => {
111     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({
112       owningEntityName: 'att-owner',
113       regionId: 'regionId'
114     });
115     expect(result.region).toEqual('regionId (OWNER)');
116   });
117
118   test('getCloudOwner should not return owningEntityName if not exist', () => {
119     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({owningEntityName: null, regionId: 'regionId'});
120     expect(result.region).toEqual('regionId');
121   });
122
123   test('getInstanceName should  return instance name id exist if not exist', () => {
124     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({serviceInstanceName: 'instanceName'});
125     expect(result.instanceName).toEqual('instanceName');
126   });
127
128   test('getInstanceName should return <Automatically generated> if instance name not exist', () => {
129     let result: InstantiationTemplatesRowModel = new InstantiationTemplatesRowModel({});
130     expect(result.instanceName).toEqual('<Automatically generated>');
131   });
132
133 });