2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import deepFreeze from 'deep-freeze';
17 import mockRest from 'test-utils/MockRest.js';
18 import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
19 import {storeCreator} from 'sdc-app/AppStore.js';
20 import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
21 import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
22 import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
24 describe('Entitlement Pools Module Tests', function () {
26 const LICENSE_MODEL_ID = '555';
27 const version = VersionControllerUtilsFactory.build().version;
29 it('Load Entitlement Pools List', () => {
31 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory);
32 deepFreeze(entitlementPoolsList);
33 const store = storeCreator();
34 deepFreeze(store.getState());
36 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
38 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
39 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
40 expect(data).toEqual(undefined);
41 expect(options).toEqual(undefined);
42 return {results: entitlementPoolsList};
45 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
46 expect(store.getState()).toEqual(expectedStore);
50 it('Delete Entitlement Pool', () => {
52 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
53 deepFreeze(entitlementPoolsList);
54 const store = storeCreator({
61 deepFreeze(store.getState());
63 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
65 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
66 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`);
67 expect(data).toEqual(undefined);
68 expect(options).toEqual(undefined);
76 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
77 licenseModelId: LICENSE_MODEL_ID,
79 entitlementPoolId: entitlementPoolsList[0].id
81 expect(store.getState()).toEqual(expectedStore);
85 it('Add Entitlement Pool', () => {
87 const store = storeCreator();
88 deepFreeze(store.getState());
90 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
92 deepFreeze(EntitlementPoolPostRequest);
94 const entitlementPoolIdFromResponse = 'ADDED_ID';
95 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
96 deepFreeze(entitlementPoolAfterAdd);
98 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
100 mockRest.addHandler('post', ({data, options, baseUrl}) => {
101 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
102 expect(data).toEqual(EntitlementPoolPostRequest);
103 expect(options).toEqual(undefined);
106 value: entitlementPoolIdFromResponse
110 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
112 licenseModelId: LICENSE_MODEL_ID,
114 previousEntitlementPool: null,
115 entitlementPool: EntitlementPoolPostRequest
118 expect(store.getState()).toEqual(expectedStore);
122 it('Update Entitlement Pool', () => {
124 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
125 deepFreeze(entitlementPoolsList);
127 const store = storeCreator({
135 deepFreeze(store.getState());
137 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
138 const previousEntitlementPoolData = entitlementPoolsList[0];
139 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
140 deepFreeze(entitlementPoolUpdateData);
142 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
143 deepFreeze(entitlementPoolPutRequest);
145 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
148 mockRest.addHandler('put', ({data, options, baseUrl}) => {
149 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`);
150 expect(data).toEqual(entitlementPoolPutRequest);
151 expect(options).toEqual(undefined);
152 return {returnCode: 'OK'};
155 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
156 licenseModelId: LICENSE_MODEL_ID,
158 previousEntitlementPool: previousEntitlementPoolData,
159 entitlementPool: entitlementPoolUpdateData
161 expect(store.getState()).toEqual(expectedStore);