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 {expect} from 'chai';
22 import deepFreeze from 'deep-freeze';
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 FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
29 describe('Feature Groups Module Tests', function () {
31 const LICENSE_MODEL_ID = '555';
33 it('Load Feature Groups List', () => {
34 const featureGroupsList = [
39 licenseKeyGroupsIds: [1],
40 entitlementPoolsIds: [1],
44 deepFreeze(featureGroupsList);
45 const store = storeCreator();
46 deepFreeze(store.getState());
48 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
50 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
51 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups`);
52 expect(data).to.equal(undefined);
53 expect(options).to.equal(undefined);
54 return {results: featureGroupsList};
57 return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => {
58 expect(store.getState()).to.deep.equal(expectedStore);
62 it('Delete Feature Group', () => {
63 const featureGroupsList = [
68 licenseKeyGroupsIds: [1],
69 entitlementPoolsIds: [1],
73 deepFreeze(featureGroupsList);
74 const store = storeCreator({
81 deepFreeze(store.getState());
83 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
85 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
86 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups/${featureGroupsList[0].id}`);
87 expect(data).to.equal(undefined);
88 expect(options).to.equal(undefined);
96 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
97 licenseModelId: LICENSE_MODEL_ID,
98 featureGroupId: featureGroupsList[0].id
100 expect(store.getState()).to.deep.equal(expectedStore);
104 it('Add Feature Group', () => {
106 const store = storeCreator();
107 deepFreeze(store.getState());
109 const featureGroupPostRequest = {
111 description: 'fs1-d',
113 addedLicenseKeyGroupsIds: [1],
114 addedEntitlementPoolsIds: [1]
116 const featureGroupToAdd = {
118 description: 'fs1-d',
120 licenseKeyGroupsIds: [1],
121 entitlementPoolsIds: [1]
123 const featureGroupIdFromResponse = 'ADDED_ID';
124 const featureGroupAfterAdd = {
125 ...featureGroupToAdd,
126 id: featureGroupIdFromResponse
129 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
131 mockRest.addHandler('create', ({data, options, baseUrl}) => {
132 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups`);
133 expect(data).to.deep.equal(featureGroupPostRequest);
134 expect(options).to.equal(undefined);
137 value: featureGroupIdFromResponse
141 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
142 licenseModelId: LICENSE_MODEL_ID,
143 featureGroup: featureGroupToAdd
145 expect(store.getState()).to.deep.equal(expectedStore);
149 it('Update Feature Group', () => {
150 const featureGroupsList = [{
153 description: 'fs1-d',
155 licenseKeyGroupsIds: [1],
156 entitlementPoolsIds: [1],
159 deepFreeze(featureGroupsList);
161 const store = storeCreator({
168 deepFreeze(store.getState());
170 const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
171 const previousFeatureGroupData = featureGroupsList[0];
172 const featureGroupUpdateData = {
173 ...featureGroupsList[0],
175 description: 'description_UPDATED',
176 partNumber: '123_UPDATED',
177 licenseKeyGroupsIds: [7],
178 entitlementPoolsIds: [7]
180 deepFreeze(featureGroupUpdateData);
182 const featureGroupPutRequest = {
184 description: 'description_UPDATED',
185 partNumber: '123_UPDATED',
186 addedLicenseKeyGroupsIds: [7],
187 addedEntitlementPoolsIds: [7],
188 removedLicenseKeyGroupsIds: [1],
189 removedEntitlementPoolsIds: [1]
191 deepFreeze(featureGroupPutRequest);
193 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
196 mockRest.addHandler('save', ({data, options, baseUrl}) => {
197 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups/${toBeUpdatedFeatureGroupId}`);
198 expect(data).to.deep.equal(featureGroupPutRequest);
199 expect(options).to.equal(undefined);
200 return {returnCode: 'OK'};
203 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
204 licenseModelId: LICENSE_MODEL_ID,
205 previousFeatureGroup: previousFeatureGroupData,
206 featureGroup: featureGroupUpdateData
208 expect(store.getState()).to.deep.equal(expectedStore);