2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import deepFreeze from 'deep-freeze';
22 import {expect} from 'chai';
23 import mockRest from 'test-utils/MockRest.js';
24 import {cloneAndSet} from 'test-utils/Util.js';
25 import {storeCreator} from 'sdc-app/AppStore.js';
26 import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
28 describe('Entitlement Pools Module Tests', function () {
30 const LICENSE_MODEL_ID = '555';
32 it('Load Entitlement Pools List', () => {
33 const entitlementPoolsList = [
36 description: 'string',
39 entitlementMetric: {'choice': 'User', 'other': ''},
41 aggregationFunction: {'choice': 'Average', 'other': ''},
42 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
43 time: {'choice': 'Hour', 'other': ''},
44 sku: 'DEF2-385A-4521-AAAA',
46 referencingFeatureGroups: [],
50 deepFreeze(entitlementPoolsList);
51 const store = storeCreator();
52 deepFreeze(store.getState());
54 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
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};
63 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => {
64 expect(store.getState()).to.deep.equal(expectedStore);
68 it('Delete Entitlement Pool', () => {
69 const entitlementPoolsList = [
72 description: 'string',
75 entitlementMetric: {'choice': 'User', 'other': ''},
77 aggregationFunction: {'choice': 'Average', 'other': ''},
78 operationalScope: {'choices': ['Other'], 'other': 'blabla'},
79 time: {'choice': 'Hour', 'other': ''},
80 sku: 'DEF2-385A-4521-AAAA',
82 referencingFeatureGroups: [],
87 deepFreeze(entitlementPoolsList);
88 const store = storeCreator({
95 deepFreeze(store.getState());
97 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
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);
110 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
111 licenseModelId: LICENSE_MODEL_ID,
112 entitlementPoolId: entitlementPoolsList[0].id
114 expect(store.getState()).to.deep.equal(expectedStore);
118 it('Add Entitlement Pool', () => {
120 const store = storeCreator();
121 deepFreeze(store.getState());
123 const entitlementPoolPostRequest = {
125 description: 'string',
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',
135 const entitlementPoolToAdd = {
137 description: 'string',
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: []
148 const entitlementPoolIdFromResponse = 'ADDED_ID';
149 const entitlementPoolAfterAdd = {
150 ...entitlementPoolToAdd,
151 id: entitlementPoolIdFromResponse
154 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
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);
162 value: entitlementPoolIdFromResponse
166 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
168 licenseModelId: LICENSE_MODEL_ID,
169 previousEntitlementPool: null,
170 entitlementPool: entitlementPoolToAdd
173 expect(store.getState()).to.deep.equal(expectedStore);
177 it('Update Entitlement Pool', () => {
178 const entitlementPoolsList = [{
181 description: 'string',
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'
191 deepFreeze(entitlementPoolsList);
193 const store = storeCreator({
200 deepFreeze(store.getState());
202 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
203 const previousEntitlementPoolData = entitlementPoolsList[0];
204 const entitlementPoolUpdateData = {
205 ...entitlementPoolsList[0],
207 description: 'string_UPDATED'
209 deepFreeze(entitlementPoolUpdateData);
211 const entitlementPoolPutRequest = {
213 description: 'string_UPDATED',
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'
223 deepFreeze(entitlementPoolPutRequest);
225 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
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'};
235 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
236 licenseModelId: LICENSE_MODEL_ID,
237 previousEntitlementPool: previousEntitlementPoolData,
238 entitlementPool: entitlementPoolUpdateData
240 expect(store.getState()).to.deep.equal(expectedStore);