AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import deepFreeze from 'deep-freeze'; |
| 17 | import mockRest from 'test-utils/MockRest.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 20 | import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 21 | import { FeatureGroupStoreFactory, FeatureGroupPostFactory, FeatureGroupDispatchFactory, FeatureGroupPutFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; |
| 22 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 23 | |
| 24 | |
| 25 | describe('Feature Groups Module Tests', function () { |
| 26 | |
| 27 | const LICENSE_MODEL_ID = '555'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | const version = VersionControllerUtilsFactory.build().version; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | |
| 30 | it('Load Feature Groups List', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | |
| 32 | const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | deepFreeze(featureGroupsList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | const store = storeCreator(); |
| 36 | deepFreeze(store.getState()); |
| 37 | |
| 38 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList); |
| 39 | |
| 40 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 41 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); |
| 42 | expect(data).toEqual(undefined); |
| 43 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | return {results: featureGroupsList}; |
| 45 | }); |
| 46 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 48 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | }); |
| 50 | }); |
| 51 | |
| 52 | it('Delete Feature Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 54 | deepFreeze(featureGroupsList); |
| 55 | const store = storeCreator({ |
| 56 | licenseModel: { |
| 57 | featureGroup: { |
| 58 | featureGroupsList |
| 59 | } |
| 60 | } |
| 61 | }); |
| 62 | deepFreeze(store.getState()); |
| 63 | |
| 64 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []); |
| 65 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 66 | const idToDelete = featureGroupsList[0].id; |
| 67 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 69 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${idToDelete}`); |
| 70 | expect(data).toEqual(undefined); |
| 71 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | return { |
| 73 | results: { |
| 74 | returnCode: 'OK' |
| 75 | } |
| 76 | }; |
| 77 | }); |
| 78 | |
| 79 | return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, { |
| 80 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | version, |
| 82 | featureGroupId: idToDelete |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 83 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 84 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 85 | }); |
| 86 | }); |
| 87 | |
| 88 | it('Add Feature Group', () => { |
| 89 | |
| 90 | const store = storeCreator(); |
| 91 | deepFreeze(store.getState()); |
| 92 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | const FeatureGroupPostRequest = FeatureGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | addedLicenseKeyGroupsIds: [1], |
| 95 | addedEntitlementPoolsIds: [1] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 96 | }); |
| 97 | const featureGroupToAdd = FeatureGroupDispatchFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | licenseKeyGroupsIds: [1], |
| 99 | entitlementPoolsIds: [1] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 100 | }); |
| 101 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | const featureGroupIdFromResponse = 'ADDED_ID'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | const featureGroupAfterAdd = FeatureGroupStoreFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | ...featureGroupToAdd, |
| 105 | id: featureGroupIdFromResponse |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 106 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 107 | |
| 108 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]); |
| 109 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 110 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 111 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); |
| 112 | expect(data).toEqual(FeatureGroupPostRequest); |
| 113 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 114 | return { |
| 115 | returnCode: 'OK', |
| 116 | value: featureGroupIdFromResponse |
| 117 | }; |
| 118 | }); |
| 119 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 120 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 121 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 122 | expect(data).toEqual(undefined); |
| 123 | expect(options).toEqual(undefined); |
| 124 | return {results: []}; |
| 125 | }); |
| 126 | |
| 127 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 128 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 129 | expect(data).toEqual(undefined); |
| 130 | expect(options).toEqual(undefined); |
| 131 | return {results: []}; |
| 132 | }); |
| 133 | |
| 134 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 135 | return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, { |
| 136 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 137 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 138 | featureGroup: featureGroupToAdd |
| 139 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 140 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 141 | }); |
| 142 | }); |
| 143 | |
| 144 | it('Update Feature Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 146 | licenseKeyGroupsIds: [1], |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 147 | entitlementPoolsIds: [1] |
| 148 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 149 | deepFreeze(featureGroupsList); |
| 150 | |
| 151 | const store = storeCreator({ |
| 152 | licenseModel: { |
| 153 | featureGroup: { |
| 154 | featureGroupsList |
| 155 | } |
| 156 | } |
| 157 | }); |
| 158 | deepFreeze(store.getState()); |
| 159 | |
| 160 | const toBeUpdatedFeatureGroupId = featureGroupsList[0].id; |
| 161 | const previousFeatureGroupData = featureGroupsList[0]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 162 | |
| 163 | const featureGroupUpdateData = FeatureGroupStoreFactory.build({ |
| 164 | ...previousFeatureGroupData, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 165 | licenseKeyGroupsIds: [7], |
| 166 | entitlementPoolsIds: [7] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 167 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 168 | deepFreeze(featureGroupUpdateData); |
| 169 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 170 | const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({ |
| 171 | name: featureGroupUpdateData.name, |
| 172 | description: featureGroupUpdateData.description, |
| 173 | partNumber: featureGroupUpdateData.partNumber, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 174 | addedLicenseKeyGroupsIds: [7], |
| 175 | addedEntitlementPoolsIds: [7], |
| 176 | removedLicenseKeyGroupsIds: [1], |
| 177 | removedEntitlementPoolsIds: [1] |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | }); |
| 179 | deepFreeze(FeatureGroupPutFactoryRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 180 | |
| 181 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]); |
| 182 | |
| 183 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 184 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 185 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${toBeUpdatedFeatureGroupId}`); |
| 186 | expect(data).toEqual(FeatureGroupPutFactoryRequest); |
| 187 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 188 | return {returnCode: 'OK'}; |
| 189 | }); |
| 190 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 191 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 192 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 193 | expect(data).toEqual(undefined); |
| 194 | expect(options).toEqual(undefined); |
| 195 | return {results: []}; |
| 196 | }); |
| 197 | |
| 198 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 199 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 200 | expect(data).toEqual(undefined); |
| 201 | expect(options).toEqual(undefined); |
| 202 | return {results: []}; |
| 203 | }); |
| 204 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 205 | return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, { |
| 206 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 207 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 208 | previousFeatureGroup: previousFeatureGroupData, |
| 209 | featureGroup: featureGroupUpdateData |
| 210 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 211 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 212 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 213 | |
| 214 | }); |
| 215 | |
| 216 | it('Open Editor', () => { |
| 217 | |
| 218 | const store = storeCreator(); |
| 219 | deepFreeze(store.getState()); |
| 220 | |
| 221 | const editorData = FeatureGroupStoreFactory.build(); |
| 222 | deepFreeze(editorData); |
| 223 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupEditor.data', editorData); |
| 224 | const LICENSE_MODEL_ID = '123'; |
| 225 | |
| 226 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 227 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 228 | expect(data).toEqual(undefined); |
| 229 | expect(options).toEqual(undefined); |
| 230 | return {results: []}; |
| 231 | }); |
| 232 | |
| 233 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 234 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 235 | expect(data).toEqual(undefined); |
| 236 | expect(options).toEqual(undefined); |
| 237 | return {results: []}; |
| 238 | }); |
| 239 | |
| 240 | |
| 241 | FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version}); |
| 242 | setTimeout(() =>{ |
| 243 | expect(store.getState()).toEqual(expectedStore); |
| 244 | }, 100); |
| 245 | |
| 246 | |
| 247 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 248 | }); |
| 249 | |
| 250 | }); |