Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | /*- |
| 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 | |
| 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'; |
| 27 | |
| 28 | |
| 29 | describe('Feature Groups Module Tests', function () { |
| 30 | |
| 31 | const LICENSE_MODEL_ID = '555'; |
| 32 | |
| 33 | it('Load Feature Groups List', () => { |
| 34 | const featureGroupsList = [ |
| 35 | { |
| 36 | name: 'fs1', |
| 37 | id: 0, |
| 38 | description: 'fs1-d', |
| 39 | licenseKeyGroupsIds: [1], |
| 40 | entitlementPoolsIds: [1], |
| 41 | refCount: 0 |
| 42 | } |
| 43 | ]; |
| 44 | deepFreeze(featureGroupsList); |
| 45 | const store = storeCreator(); |
| 46 | deepFreeze(store.getState()); |
| 47 | |
| 48 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList); |
| 49 | |
| 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}; |
| 55 | }); |
| 56 | |
| 57 | return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => { |
| 58 | expect(store.getState()).to.deep.equal(expectedStore); |
| 59 | }); |
| 60 | }); |
| 61 | |
| 62 | it('Delete Feature Group', () => { |
| 63 | const featureGroupsList = [ |
| 64 | { |
| 65 | name: 'fs1', |
| 66 | id: 0, |
| 67 | description: 'fs1-d', |
| 68 | licenseKeyGroupsIds: [1], |
| 69 | entitlementPoolsIds: [1], |
| 70 | refCount: 0 |
| 71 | } |
| 72 | ]; |
| 73 | deepFreeze(featureGroupsList); |
| 74 | const store = storeCreator({ |
| 75 | licenseModel: { |
| 76 | featureGroup: { |
| 77 | featureGroupsList |
| 78 | } |
| 79 | } |
| 80 | }); |
| 81 | deepFreeze(store.getState()); |
| 82 | |
| 83 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []); |
| 84 | |
| 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); |
| 89 | return { |
| 90 | results: { |
| 91 | returnCode: 'OK' |
| 92 | } |
| 93 | }; |
| 94 | }); |
| 95 | |
| 96 | return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, { |
| 97 | licenseModelId: LICENSE_MODEL_ID, |
| 98 | featureGroupId: featureGroupsList[0].id |
| 99 | }).then(() => { |
| 100 | expect(store.getState()).to.deep.equal(expectedStore); |
| 101 | }); |
| 102 | }); |
| 103 | |
| 104 | it('Add Feature Group', () => { |
| 105 | |
| 106 | const store = storeCreator(); |
| 107 | deepFreeze(store.getState()); |
| 108 | |
| 109 | const featureGroupPostRequest = { |
| 110 | name: 'fs1', |
| 111 | description: 'fs1-d', |
| 112 | partNumber: '123', |
| 113 | addedLicenseKeyGroupsIds: [1], |
| 114 | addedEntitlementPoolsIds: [1] |
| 115 | }; |
| 116 | const featureGroupToAdd = { |
| 117 | name: 'fs1', |
| 118 | description: 'fs1-d', |
| 119 | partNumber: '123', |
| 120 | licenseKeyGroupsIds: [1], |
| 121 | entitlementPoolsIds: [1] |
| 122 | }; |
| 123 | const featureGroupIdFromResponse = 'ADDED_ID'; |
| 124 | const featureGroupAfterAdd = { |
| 125 | ...featureGroupToAdd, |
| 126 | id: featureGroupIdFromResponse |
| 127 | }; |
| 128 | |
| 129 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]); |
| 130 | |
| 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); |
| 135 | return { |
| 136 | returnCode: 'OK', |
| 137 | value: featureGroupIdFromResponse |
| 138 | }; |
| 139 | }); |
| 140 | |
| 141 | return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, { |
| 142 | licenseModelId: LICENSE_MODEL_ID, |
| 143 | featureGroup: featureGroupToAdd |
| 144 | }).then(() => { |
| 145 | expect(store.getState()).to.deep.equal(expectedStore); |
| 146 | }); |
| 147 | }); |
| 148 | |
| 149 | it('Update Feature Group', () => { |
| 150 | const featureGroupsList = [{ |
| 151 | name: 'fs1', |
| 152 | id: 0, |
| 153 | description: 'fs1-d', |
| 154 | partNumber: '123', |
| 155 | licenseKeyGroupsIds: [1], |
| 156 | entitlementPoolsIds: [1], |
| 157 | refCount: 0 |
| 158 | }]; |
| 159 | deepFreeze(featureGroupsList); |
| 160 | |
| 161 | const store = storeCreator({ |
| 162 | licenseModel: { |
| 163 | featureGroup: { |
| 164 | featureGroupsList |
| 165 | } |
| 166 | } |
| 167 | }); |
| 168 | deepFreeze(store.getState()); |
| 169 | |
| 170 | const toBeUpdatedFeatureGroupId = featureGroupsList[0].id; |
| 171 | const previousFeatureGroupData = featureGroupsList[0]; |
| 172 | const featureGroupUpdateData = { |
| 173 | ...featureGroupsList[0], |
| 174 | name: 'fs_UPDATED', |
| 175 | description: 'description_UPDATED', |
| 176 | partNumber: '123_UPDATED', |
| 177 | licenseKeyGroupsIds: [7], |
| 178 | entitlementPoolsIds: [7] |
| 179 | }; |
| 180 | deepFreeze(featureGroupUpdateData); |
| 181 | |
| 182 | const featureGroupPutRequest = { |
| 183 | name: 'fs_UPDATED', |
| 184 | description: 'description_UPDATED', |
| 185 | partNumber: '123_UPDATED', |
| 186 | addedLicenseKeyGroupsIds: [7], |
| 187 | addedEntitlementPoolsIds: [7], |
| 188 | removedLicenseKeyGroupsIds: [1], |
| 189 | removedEntitlementPoolsIds: [1] |
| 190 | }; |
| 191 | deepFreeze(featureGroupPutRequest); |
| 192 | |
| 193 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]); |
| 194 | |
| 195 | |
| 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'}; |
| 201 | }); |
| 202 | |
| 203 | return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, { |
| 204 | licenseModelId: LICENSE_MODEL_ID, |
| 205 | previousFeatureGroup: previousFeatureGroupData, |
| 206 | featureGroup: featureGroupUpdateData |
| 207 | }).then(() => { |
| 208 | expect(store.getState()).to.deep.equal(expectedStore); |
| 209 | }); |
| 210 | }); |
| 211 | |
| 212 | }); |