blob: f734979acdf9a7ab0857b850248b0fe7d572f9b3 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import { LcpRegionsAndTenants } from './shared/models/lcpRegionsAndTenants';
2import { ServiceReducer, ServiceState } from './service.reducer';
3import { CategoryParams } from './shared/models/categoryParams';
4import {
5 DELETE_VNF_INSTANCE, DELETE_VNF_MODULE_INSTANCE, DeleteVfModuleInstanceAction,
6 DeleteVnfInstanceAction,
7 UPDATE_AIC_ZONES,
8 UPDATE_LCP_REGIONS_AND_TENANTS,
9 UPDATE_PRODUCT_FAMILIES,
10 UPDATE_SERVICE_INSTANCE,
11 UPDATE_SUBSCRIBERS,
12 UPDATE_USER_ID,
13 UPDATE_VNF_INSTANCE,
14 UpdateAicZonesAction,
15 UpdateProductFamiliesAction, UpdateServiceInstanceAction,
16 UpdateSubscribersAction, UpdateUserIdAction,
17 UpdateVnfInstanceAction
18} from './service.actions';
19import { VnfInstance } from './shared/models/vnfInstance';
20import { ServiceInstance } from './shared/models/serviceInstance';
21import { LcpRegion } from './shared/models/lcpRegion';
22import { Tenant } from './shared/models/tenant';
23import { SelectOption } from './shared/models/selectOption';
24
25
26const initialState: ServiceState = {
27 serviceHierarchy: {},
28 serviceInstance: {},
29 lcpRegionsAndTenants: new LcpRegionsAndTenants(),
30 subscribers: null,
31 productFamilies: null,
32 serviceTypes: {},
33 aicZones: null,
34 categoryParameters: new CategoryParams()
35};
36
37
38describe('service reducer', () => {
39 const userId: string = 'userId';
40 it('should handle initial state', () => {
41 expect(ServiceReducer(undefined, <any>{})).toEqual(initialState);
42 });
43
44 it('#UPDATE_USER_ID : should update userId ', (done: DoneFn) => {
45 expect(ServiceReducer(<any>{},
46 <UpdateUserIdAction>{
47 type: UPDATE_USER_ID,
48 userId: userId
49 }
50 )['userId']).toEqual(userId);
51 done();
52 });
53
54 it('#UPDATE_SERVICE_INSTANCE : should update service instance with service id ', (done: DoneFn) => {
55 const serviceUuid:string = 'serviceUuid';
56
57 let serviceInstanceObject : ServiceInstance = {
58 instanceName: 'instanceName',
59 isUserProvidedNaming: false,
60 globalSubscriberId: 'globalSubscriberId',
61 productFamilyId: 'productFamilyId',
62 subscriptionServiceType: 'subscriptionServiceType',
63 lcpCloudRegionId: 'lcpCloudRegionId',
64 tenantId: 'tenantId',
65 tenantName: 'tenantName',
66 aicZoneId: 'aicZoneId',
67 aicZoneName: 'aicZoneName',
68 projectName: 'projectName',
69 owningEntityId: 'owningEntityId',
70 owningEntityName: 'owningEntityName',
71 pause: false,
72 bulkSize: 1,
73 vnfs: {},
74 instanceParams : {},
75 rollbackOnFailure: false,
76 subscriberName: 'subscriberName'
77 };
78
79 let serviceState = ServiceReducer(<any>{serviceInstance : {}},
80 <UpdateServiceInstanceAction>{
81 type: UPDATE_SERVICE_INSTANCE,
82 serviceUuid: serviceUuid,
83 serviceInstance : serviceInstanceObject
84 }).serviceInstance['serviceUuid'];
85
86 expect(serviceState.instanceName).toEqual(serviceInstanceObject.instanceName);
87 expect(serviceState.isUserProvidedNaming).toEqual(serviceInstanceObject.isUserProvidedNaming);
88 expect(serviceState.globalSubscriberId).toEqual(serviceInstanceObject.globalSubscriberId);
89 expect(serviceState.productFamilyId).toEqual(serviceInstanceObject.productFamilyId);
90 expect(serviceState.subscriptionServiceType).toEqual(serviceInstanceObject.subscriptionServiceType);
91 expect(serviceState.lcpCloudRegionId).toEqual(serviceInstanceObject.lcpCloudRegionId);
92 expect(serviceState.tenantId).toEqual(serviceInstanceObject.tenantId);
93 expect(serviceState.tenantName).toEqual(serviceInstanceObject.tenantName);
94 expect(serviceState.aicZoneId).toEqual(serviceInstanceObject.aicZoneId);
95 expect(serviceState.aicZoneName).toEqual(serviceInstanceObject.aicZoneName);
96 expect(serviceState.projectName).toEqual(serviceInstanceObject.projectName);
97 expect(serviceState.owningEntityId).toEqual(serviceInstanceObject.owningEntityId);
98 expect(serviceState.owningEntityName).toEqual(serviceInstanceObject.owningEntityName);
99 expect(serviceState.pause).toEqual(serviceInstanceObject.pause);
100 expect(serviceState.bulkSize).toEqual(serviceInstanceObject.bulkSize);
101 expect(serviceState.vnfs).toEqual(serviceInstanceObject.vnfs);
102 expect(serviceState.instanceParams).toEqual(serviceInstanceObject.instanceParams);
103 expect(serviceState.rollbackOnFailure).toEqual(serviceInstanceObject.rollbackOnFailure);
104 expect(serviceState.subscriberName).toEqual(serviceInstanceObject.subscriberName);
105
106 done();
107 });
108
109 it('#UPDATE_VNF_INSTANCE : should update vnf instance with service id and vnfModelName ', (done: DoneFn) => {
110 let vnfInstanceObj : VnfInstance = {
111 instanceName: 'instanceName',
112 isUserProvidedNaming: false,
113 productFamilyId: 'productFamilyId',
114 lcpCloudRegionId: 'lcpCloudRegionId',
115 legacyRegion: 'legacyRegion',
116 tenantId: 'tenantId',
117 platformName: 'platformName',
118 lineOfBusiness: 'lineOfBusiness',
119 rollbackOnFailure: 'false',
120 vfModules: {}
121 };
122
123 let vnfState = ServiceReducer(<any>{serviceInstance : {
124 'serviceUuid' : {
125 vnfs : {}
126 }
127 }},
128 <UpdateVnfInstanceAction>{
129 type: UPDATE_VNF_INSTANCE,
130 serviceUuid : 'serviceUuid',
131 vnfInstance: vnfInstanceObj,
132 vnfModelName : 'vnfModelName'
133 }).serviceInstance['serviceUuid'].vnfs['vnfModelName'];
134
135 expect(vnfState.instanceName).toEqual(vnfInstanceObj.instanceName);
136 expect(vnfState.isUserProvidedNaming).toEqual(vnfInstanceObj.isUserProvidedNaming);
137 expect(vnfState.productFamilyId).toEqual(vnfInstanceObj.productFamilyId);
138 expect(vnfState.lcpCloudRegionId).toEqual(vnfInstanceObj.lcpCloudRegionId);
139 expect(vnfState.legacyRegion).toEqual(vnfInstanceObj.legacyRegion);
140 expect(vnfState.tenantId).toEqual(vnfInstanceObj.tenantId);
141 expect(vnfState.platformName).toEqual(vnfInstanceObj.platformName);
142 expect(vnfState.lineOfBusiness).toEqual(vnfInstanceObj.lineOfBusiness);
143 expect(vnfState.vfModules).toEqual(vnfInstanceObj.vfModules);
144 expect(vnfState.rollbackOnFailure).toEqual(vnfInstanceObj.rollbackOnFailure);
145
146 done();
147 });
148
149 it('#UPDATE_LCP_REGIONS_AND_TENANTS : should update lcp region and tenants', (done: DoneFn) => {
150 let lcpRegionsAndTenantsObj = [
151 {
152 lcpRegionList : [
153 new LcpRegion({
154 "cloudRegionID" : 'cloudRegionID',
155 "is-permitted" : "is-permitted"
156 })
157 ],
158 lcpRegionsTenantsMap : {
159 "lcpRegion" : [new Tenant({
160 "tenantID" : "tenantID",
161 "tenantName" : "tenantName",
162 "is-permitted" : true
163 })]
164 }
165 }
166 ];
167 let lcpRegionsAndTenantsState = ServiceReducer(<any>{serviceInstance : {}},
168 <any>{
169 type: UPDATE_LCP_REGIONS_AND_TENANTS,
170 lcpRegionsAndTenants : lcpRegionsAndTenantsObj
171 })['lcpRegionsAndTenants'];
172
173 expect(lcpRegionsAndTenantsState).toBeDefined();
174 done();
175 });
176
177 it('#UPDATE_SUBSCRIBERS : should update subscribers', (done: DoneFn) => {
178 let subscribersList = [
179 new SelectOption({
180 id : 'id',
181 name : 'name',
182 isPermitted : false
183 })
184 ];
185 let subscribersState = ServiceReducer(<any>{serviceInstance : {}},
186 <UpdateSubscribersAction>{
187 type: UPDATE_SUBSCRIBERS,
188 subscribers : subscribersList
189 })['subscribers'];
190
191 expect(subscribersState).toBeDefined();
192 expect(subscribersState[0].id).toEqual(subscribersList[0].id);
193 expect(subscribersState[0].isPermitted).toEqual(subscribersList[0].isPermitted);
194 expect(subscribersState[0].name).toEqual(subscribersList[0].name);
195
196 done();
197 });
198
199 it('#UpdateProductFamiliesAction : should update product families', (done: DoneFn) => {
200 let productFamiliesObj = [
201 new SelectOption({
202 id : 'id',
203 name : 'name',
204 isPermitted : false
205 })
206 ];
207 let productFamiliesState = ServiceReducer(<any>{serviceInstance : {}},
208 <UpdateProductFamiliesAction>{
209 type: UPDATE_PRODUCT_FAMILIES,
210 productFamilies : productFamiliesObj
211 })['productFamilies'];
212
213 expect(productFamiliesState).toBeDefined();
214 expect(productFamiliesState[0].id).toEqual(productFamiliesObj[0].id);
215 expect(productFamiliesState[0].isPermitted).toEqual(productFamiliesObj[0].isPermitted);
216 expect(productFamiliesState[0].name).toEqual(productFamiliesObj[0].name);
217
218 done();
219 });
220
221 it('#UPDATE_AIC_ZONES : should update aic zones', (done: DoneFn) => {
222 let aicZonesObj = [
223 new SelectOption({
224 id : 'id',
225 name : 'name',
226 isPermitted : false
227 })
228 ];
229 let aicZonesState = ServiceReducer(<any>{serviceInstance : {}},
230 <UpdateAicZonesAction>{
231 type: UPDATE_AIC_ZONES,
232 aicZones : aicZonesObj
233 })['aicZones'];
234
235 expect(aicZonesState).toBeDefined();
236 expect(aicZonesState[0].id).toEqual(aicZonesObj[0].id);
237 expect(aicZonesState[0].isPermitted).toEqual(aicZonesObj[0].isPermitted);
238 expect(aicZonesState[0].name).toEqual(aicZonesObj[0].name);
239
240 done();
241 });
242
243 it('#DELETE_VNF_INSTANCE : should delete existing vnf', (done: DoneFn) => {
244 let state = ServiceReducer(<any>{serviceInstance : {
245 'serviceModelId' : {
246 vnfs : {
247 'modelName' : {}
248 }
249 }
250 }},
251 <DeleteVnfInstanceAction>{
252 type: DELETE_VNF_INSTANCE,
253 modelName : 'modelName',
254 serviceModelId : 'serviceModelId'
255 });
256
257 expect(state).toBeDefined();
258 expect(state.serviceInstance[ 'serviceModelId'].vnfs['modelName']).not.toBeDefined();
259 done();
260 });
261
262 it('#DELETE_VNF_MODULE_INSTANCE : should delete existing vnf module', (done: DoneFn) => {
263 let state = ServiceReducer(<any>{serviceInstance : {
264 'serviceModelId' : {
265 vnfs : {
266 'vfName' : {
267 vfModules : {
268 'modelName' : {}
269 }
270 }
271 }
272 }
273 }},
274 <DeleteVfModuleInstanceAction>{
275 type: DELETE_VNF_MODULE_INSTANCE,
276 modelName : 'modelName',
277 vfName : 'vfName',
278 serviceModelId : 'serviceModelId'
279 });
280
281 expect(state).toBeDefined();
282 expect(state.serviceInstance['serviceModelId'].vnfs['vfName'].vfModules['modelName']).not.toBeDefined();
283 done();
284 });
285
286});