blob: 32705385b424eae814c74228d0a3abe3b7fcb674 [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21import deepFreeze from 'deep-freeze';
22import {expect} from 'chai';
23import mockRest from 'test-utils/MockRest.js';
24import {cloneAndSet} from 'test-utils/Util.js';
25import {storeCreator} from 'sdc-app/AppStore.js';
26import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
27
28describe('Entitlement Pools Module Tests', function () {
29
30 const LICENSE_MODEL_ID = '555';
31
32 it('Load Entitlement Pools List', () => {
33 const entitlementPoolsList = [
34 {
35 name: 'ep1',
36 description: 'string',
37 thresholdValue: 75,
38 thresholdUnits: '%',
39 entitlementMetric: {'choice': 'User', 'other': ''},
40 increments: 'string',
41 aggregationFunction: {'choice': 'Average', 'other': ''},
42 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
43 time: {'choice': 'Hour', 'other': ''},
44 sku: 'DEF2-385A-4521-AAAA',
45 id: '1',
46 referencingFeatureGroups: [],
47 partNumber: '51529'
48 }
49 ];
50 deepFreeze(entitlementPoolsList);
51 const store = storeCreator();
52 deepFreeze(store.getState());
53
54 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
55
56 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
57 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools`);
58 expect(data).to.equal(undefined);
59 expect(options).to.equal(undefined);
60 return {results: entitlementPoolsList};
61 });
62
63 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => {
64 expect(store.getState()).to.deep.equal(expectedStore);
65 });
66 });
67
68 it('Delete Entitlement Pool', () => {
69 const entitlementPoolsList = [
70 {
71 name: 'ep1',
72 description: 'string',
73 thresholdValue: 75,
74 thresholdUnits: '%',
75 entitlementMetric: {'choice': 'User', 'other': ''},
76 increments: 'string',
77 aggregationFunction: {'choice': 'Average', 'other': ''},
78 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
79 time: {'choice': 'Hour', 'other': ''},
80 sku: 'DEF2-385A-4521-AAAA',
81 id: '1',
82 referencingFeatureGroups: [],
83 partNumber: '51529'
84 }
85 ];
86
87 deepFreeze(entitlementPoolsList);
88 const store = storeCreator({
89 licenseModel: {
90 entitlementPool: {
91 entitlementPoolsList
92 }
93 }
94 });
95 deepFreeze(store.getState());
96
97 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
98
99 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
100 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools/${entitlementPoolsList[0].id}`);
101 expect(data).to.equal(undefined);
102 expect(options).to.equal(undefined);
103 return {
104 results: {
105 returnCode: 'OK'
106 }
107 };
108 });
109
110 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
111 licenseModelId: LICENSE_MODEL_ID,
112 entitlementPoolId: entitlementPoolsList[0].id
113 }).then(() => {
114 expect(store.getState()).to.deep.equal(expectedStore);
115 });
116 });
117
118 it('Add Entitlement Pool', () => {
119
120 const store = storeCreator();
121 deepFreeze(store.getState());
122
123 const entitlementPoolPostRequest = {
124 name: 'ep1',
125 description: 'string',
126 thresholdValue: 75,
127 thresholdUnits: '%',
128 entitlementMetric: {'choice': 'User', 'other': ''},
129 increments: 'string',
130 aggregationFunction: {'choice': 'Average', 'other': ''},
131 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
132 time: {'choice': 'Hour', 'other': ''},
133 manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA',
134 };
135 const entitlementPoolToAdd = {
136 name: 'ep1',
137 description: 'string',
138 thresholdValue: 75,
139 thresholdUnits: '%',
140 entitlementMetric: {'choice': 'User', 'other': ''},
141 increments: 'string',
142 aggregationFunction: {'choice': 'Average', 'other': ''},
143 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
144 time: {'choice': 'Hour', 'other': ''},
145 manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA',
146 referencingFeatureGroups: []
147 };
148 const entitlementPoolIdFromResponse = 'ADDED_ID';
149 const entitlementPoolAfterAdd = {
150 ...entitlementPoolToAdd,
151 id: entitlementPoolIdFromResponse
152 };
153
154 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
155
156 mockRest.addHandler('create', ({data, options, baseUrl}) => {
157 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools`);
158 expect(data).to.deep.equal(entitlementPoolPostRequest);
159 expect(options).to.equal(undefined);
160 return {
161 returnCode: 'OK',
162 value: entitlementPoolIdFromResponse
163 };
164 });
165
166 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
167 {
168 licenseModelId: LICENSE_MODEL_ID,
169 previousEntitlementPool: null,
170 entitlementPool: entitlementPoolToAdd
171 }
172 ).then(() => {
173 expect(store.getState()).to.deep.equal(expectedStore);
174 });
175 });
176
177 it('Update Entitlement Pool', () => {
178 const entitlementPoolsList = [{
179 name: 'ep1',
180 id: '0',
181 description: 'string',
182 thresholdValue: 75,
183 thresholdUnits: '%',
184 entitlementMetric: {'choice': 'User', 'other': ''},
185 increments: 'string',
186 aggregationFunction: {'choice': 'Average', 'other': ''},
187 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
188 time: {'choice': 'Hour', 'other': ''},
189 manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA'
190 }];
191 deepFreeze(entitlementPoolsList);
192
193 const store = storeCreator({
194 licenseModel: {
195 entitlementPool: {
196 entitlementPoolsList
197 }
198 }
199 });
200 deepFreeze(store.getState());
201
202 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
203 const previousEntitlementPoolData = entitlementPoolsList[0];
204 const entitlementPoolUpdateData = {
205 ...entitlementPoolsList[0],
206 name: 'ep1_UPDATED',
207 description: 'string_UPDATED'
208 };
209 deepFreeze(entitlementPoolUpdateData);
210
211 const entitlementPoolPutRequest = {
212 name: 'ep1_UPDATED',
213 description: 'string_UPDATED',
214 thresholdValue: 75,
215 thresholdUnits: '%',
216 entitlementMetric: {'choice': 'User', 'other': ''},
217 increments: 'string',
218 aggregationFunction: {'choice': 'Average', 'other': ''},
219 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
220 time: {'choice': 'Hour', 'other': ''},
221 manufacturerReferenceNumber: 'DEF2-385A-4521-AAAA'
222 };
223 deepFreeze(entitlementPoolPutRequest);
224
225 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
226
227
228 mockRest.addHandler('save', ({data, options, baseUrl}) => {
229 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`);
230 expect(data).to.deep.equal(entitlementPoolPutRequest);
231 expect(options).to.equal(undefined);
232 return {returnCode: 'OK'};
233 });
234
235 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
236 licenseModelId: LICENSE_MODEL_ID,
237 previousEntitlementPool: previousEntitlementPoolData,
238 entitlementPool: entitlementPoolUpdateData
239 }).then(() => {
240 expect(store.getState()).to.deep.equal(expectedStore);
241 });
242 });
243
244});