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'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 20 | import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 21 | |
| 22 | import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame^] | 24 | import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 25 | |
| 26 | describe('License Key Groups Module Tests', function () { |
| 27 | |
| 28 | const LICENSE_MODEL_ID = '555'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 29 | const version = VersionControllerUtilsFactory.build().version; |
| 30 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 31 | it('Load License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 32 | |
| 33 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory); |
| 34 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | deepFreeze(licenseKeyGroupsList); |
| 36 | const store = storeCreator(); |
| 37 | deepFreeze(store.getState()); |
| 38 | |
| 39 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList); |
| 40 | |
| 41 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 43 | expect(data).toEqual(undefined); |
| 44 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | return {results: licenseKeyGroupsList}; |
| 46 | }); |
| 47 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 48 | return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 49 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 50 | }); |
| 51 | }); |
| 52 | |
| 53 | it('Delete License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | |
| 55 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
| 56 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 57 | deepFreeze(licenseKeyGroupsList); |
| 58 | const store = storeCreator({ |
| 59 | licenseModel: { |
| 60 | licenseKeyGroup: { |
| 61 | licenseKeyGroupsList |
| 62 | } |
| 63 | } |
| 64 | }); |
| 65 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 66 | const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 67 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []); |
| 68 | |
| 69 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 70 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`); |
| 71 | expect(data).toEqual(undefined); |
| 72 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 73 | }); |
| 74 | |
| 75 | return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, { |
| 76 | licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | licenseModelId: LICENSE_MODEL_ID, |
| 78 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 79 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 80 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | }); |
| 82 | }); |
| 83 | |
| 84 | it('Add License Key Group', () => { |
| 85 | |
| 86 | const store = storeCreator(); |
| 87 | deepFreeze(store.getState()); |
| 88 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); |
| 90 | deepFreeze(LicenseKeyGroupPost); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 91 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 92 | const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); |
| 93 | deepFreeze(LicenseKeyGroupStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 95 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 96 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 97 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 98 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 99 | expect(data).toEqual(LicenseKeyGroupPost); |
| 100 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 102 | value: LicenseKeyGroupStore.id |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 103 | }; |
| 104 | }); |
| 105 | |
| 106 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 107 | licenseKeyGroup: LicenseKeyGroupPost, |
| 108 | licenseModelId: LICENSE_MODEL_ID, |
| 109 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 110 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 111 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | }); |
| 113 | }); |
| 114 | |
| 115 | it('Update License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 116 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 117 | deepFreeze(licenseKeyGroupsList); |
| 118 | const store = storeCreator({ |
| 119 | licenseModel: { |
| 120 | licenseKeyGroup: { |
| 121 | licenseKeyGroupsList |
| 122 | } |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
| 127 | const previousLicenseKeyGroupData = licenseKeyGroupsList[0]; |
| 128 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 129 | const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 130 | name: 'lsk1_UPDATE', |
| 131 | description: 'string_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 132 | id: toBeUpdatedLicenseKeyGroupId |
| 133 | }); |
| 134 | deepFreeze(licenseKeyGroupUpdatedData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 135 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 136 | const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 137 | name: 'lsk1_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 138 | description: 'string_UPDATE' |
| 139 | }); |
| 140 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 141 | deepFreeze(licenseKeyGroupPutRequest); |
| 142 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 143 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 144 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 146 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`); |
| 147 | expect(data).toEqual(licenseKeyGroupPutRequest); |
| 148 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 149 | }); |
| 150 | |
| 151 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
| 152 | previousLicenseKeyGroup: previousLicenseKeyGroupData, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 153 | licenseKeyGroup: licenseKeyGroupUpdatedData, |
| 154 | licenseModelId: LICENSE_MODEL_ID, |
| 155 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 156 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 157 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 158 | }); |
| 159 | }); |
| 160 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame^] | 161 | it('Load Limits List', () => { |
| 162 | |
| 163 | const limitsList = LimitItemFactory.buildList(3); |
| 164 | deepFreeze(limitsList); |
| 165 | const store = storeCreator(); |
| 166 | deepFreeze(store.getState()); |
| 167 | |
| 168 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList); |
| 169 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 170 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 171 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 172 | expect(data).toEqual(undefined); |
| 173 | expect(options).toEqual(undefined); |
| 174 | return {results: limitsList}; |
| 175 | }); |
| 176 | |
| 177 | return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => { |
| 178 | expect(store.getState()).toEqual(expectedStore); |
| 179 | }); |
| 180 | }); |
| 181 | |
| 182 | it('Add Limit', () => { |
| 183 | |
| 184 | const store = storeCreator(); |
| 185 | deepFreeze(store.getState()); |
| 186 | |
| 187 | const limitToAdd = LimitPostFactory.build(); |
| 188 | |
| 189 | deepFreeze(limitToAdd); |
| 190 | |
| 191 | const LimitIdFromResponse = 'ADDED_ID'; |
| 192 | const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse}; |
| 193 | deepFreeze(limitAddedItem); |
| 194 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 195 | |
| 196 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]); |
| 197 | |
| 198 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 199 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 200 | expect(data).toEqual(limitToAdd); |
| 201 | expect(options).toEqual(undefined); |
| 202 | return { |
| 203 | returnCode: 'OK', |
| 204 | value: LimitIdFromResponse |
| 205 | }; |
| 206 | }); |
| 207 | |
| 208 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 209 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 210 | expect(data).toEqual(undefined); |
| 211 | expect(options).toEqual(undefined); |
| 212 | return {results: [limitAddedItem]}; |
| 213 | }); |
| 214 | |
| 215 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, |
| 216 | { |
| 217 | licenseModelId: LICENSE_MODEL_ID, |
| 218 | version, |
| 219 | licenseKeyGroup, |
| 220 | limit: limitToAdd |
| 221 | } |
| 222 | ).then(() => { |
| 223 | expect(store.getState()).toEqual(expectedStore); |
| 224 | }); |
| 225 | }); |
| 226 | |
| 227 | it('Delete Limit', () => { |
| 228 | |
| 229 | const limitsList = LimitItemFactory.buildList(1); |
| 230 | deepFreeze(limitsList); |
| 231 | |
| 232 | const store = storeCreator({ |
| 233 | licenseModel: { |
| 234 | entitlementPool: { |
| 235 | entitlementPoolEditor: { |
| 236 | limitsList |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | }); |
| 241 | deepFreeze(store.getState()); |
| 242 | |
| 243 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 244 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []); |
| 245 | |
| 246 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 247 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitsList[0].id}`); |
| 248 | expect(data).toEqual(undefined); |
| 249 | expect(options).toEqual(undefined); |
| 250 | return { |
| 251 | results: { |
| 252 | returnCode: 'OK' |
| 253 | } |
| 254 | }; |
| 255 | }); |
| 256 | |
| 257 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 258 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 259 | expect(data).toEqual(undefined); |
| 260 | expect(options).toEqual(undefined); |
| 261 | return {results: []}; |
| 262 | }); |
| 263 | |
| 264 | return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, { |
| 265 | licenseModelId: LICENSE_MODEL_ID, |
| 266 | version, |
| 267 | licenseKeyGroup, |
| 268 | limit: limitsList[0] |
| 269 | }).then(() => { |
| 270 | expect(store.getState()).toEqual(expectedStore); |
| 271 | }); |
| 272 | }); |
| 273 | |
| 274 | it('Update Limit', () => { |
| 275 | |
| 276 | const limitsList = LimitItemFactory.buildList(1); |
| 277 | deepFreeze(limitsList); |
| 278 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 279 | const store = storeCreator({ |
| 280 | licenseModel: { |
| 281 | licenseKeyGroup: { |
| 282 | licenseKeyGroupsEditor: { |
| 283 | limitsList |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | }); |
| 288 | |
| 289 | deepFreeze(store.getState()); |
| 290 | |
| 291 | |
| 292 | const previousData = limitsList[0]; |
| 293 | deepFreeze(previousData); |
| 294 | const limitId = limitsList[0].id; |
| 295 | |
| 296 | const updatedLimit = {...previousData, name: 'updatedLimit'}; |
| 297 | deepFreeze(updatedLimit); |
| 298 | const updatedLimitForPut = {...updatedLimit, id: undefined}; |
| 299 | |
| 300 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimit]); |
| 301 | |
| 302 | |
| 303 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 304 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`); |
| 305 | expect(data).toEqual(updatedLimitForPut); |
| 306 | expect(options).toEqual(undefined); |
| 307 | return {returnCode: 'OK'}; |
| 308 | }); |
| 309 | |
| 310 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 311 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 312 | expect(data).toEqual(undefined); |
| 313 | expect(options).toEqual(undefined); |
| 314 | return {results: [updatedLimit]}; |
| 315 | }); |
| 316 | |
| 317 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, |
| 318 | { |
| 319 | licenseModelId: LICENSE_MODEL_ID, |
| 320 | version, |
| 321 | licenseKeyGroup, |
| 322 | limit: updatedLimit |
| 323 | } |
| 324 | ).then(() => { |
| 325 | expect(store.getState()).toEqual(expectedStore); |
| 326 | }); |
| 327 | }); |
| 328 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 329 | }); |