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'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 23 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 24 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 25 | import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js'; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 26 | import {getStrValue} from 'nfvo-utils/getValue.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 27 | import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 28 | |
| 29 | describe('License Key Groups Module Tests', function () { |
| 30 | |
| 31 | const LICENSE_MODEL_ID = '555'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 32 | const version = VersionFactory.build(); |
| 33 | const itemPermissionAndProps = CurrentScreenFactory.build({}, {version}); |
| 34 | const returnedVersionFields = {baseId: version.baseId, description: version.description, id: version.id, name: version.name, status: version.status}; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 35 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | it('Load License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 37 | |
| 38 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory); |
| 39 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | deepFreeze(licenseKeyGroupsList); |
| 41 | const store = storeCreator(); |
| 42 | deepFreeze(store.getState()); |
| 43 | |
| 44 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList); |
| 45 | |
| 46 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 48 | expect(data).toEqual(undefined); |
| 49 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 50 | return {results: licenseKeyGroupsList}; |
| 51 | }); |
| 52 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 54 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 55 | }); |
| 56 | }); |
| 57 | |
| 58 | it('Delete License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | |
| 60 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
| 61 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 62 | deepFreeze(licenseKeyGroupsList); |
| 63 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 64 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 65 | licenseModel: { |
| 66 | licenseKeyGroup: { |
| 67 | licenseKeyGroupsList |
| 68 | } |
| 69 | } |
| 70 | }); |
| 71 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 72 | const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 73 | |
| 74 | const expectedCurrentScreenProps = { |
| 75 | ...itemPermissionAndProps, |
| 76 | itemPermission: { |
| 77 | ...itemPermissionAndProps.itemPermission, |
| 78 | isDirty: true |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []); |
| 83 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 84 | |
| 85 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 86 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`); |
| 87 | expect(data).toEqual(undefined); |
| 88 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 89 | }); |
| 90 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 91 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 92 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 93 | expect(data).toEqual(undefined); |
| 94 | expect(options).toEqual(undefined); |
| 95 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 96 | }); |
| 97 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, { |
| 99 | licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 100 | licenseModelId: LICENSE_MODEL_ID, |
| 101 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | }); |
| 105 | }); |
| 106 | |
| 107 | it('Add License Key Group', () => { |
| 108 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 109 | const store = storeCreator({ |
| 110 | currentScreen: {...itemPermissionAndProps} |
| 111 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | deepFreeze(store.getState()); |
| 113 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 114 | const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); |
| 115 | deepFreeze(LicenseKeyGroupPost); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 116 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 117 | const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); |
| 118 | deepFreeze(LicenseKeyGroupStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 119 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 120 | const expectedCurrentScreenProps = { |
| 121 | ...itemPermissionAndProps, |
| 122 | itemPermission: { |
| 123 | ...itemPermissionAndProps.itemPermission, |
| 124 | isDirty: true |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]); |
| 129 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 130 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 132 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 133 | expect(data).toEqual(LicenseKeyGroupPost); |
| 134 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 135 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 136 | value: LicenseKeyGroupStore.id |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 137 | }; |
| 138 | }); |
| 139 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 140 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 141 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 142 | expect(data).toEqual(undefined); |
| 143 | expect(options).toEqual(undefined); |
| 144 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 145 | }); |
| 146 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 147 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 148 | licenseKeyGroup: LicenseKeyGroupPost, |
| 149 | licenseModelId: LICENSE_MODEL_ID, |
| 150 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 151 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 152 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 153 | }); |
| 154 | }); |
| 155 | |
| 156 | it('Update License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 157 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 158 | deepFreeze(licenseKeyGroupsList); |
| 159 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 160 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 161 | licenseModel: { |
| 162 | licenseKeyGroup: { |
| 163 | licenseKeyGroupsList |
| 164 | } |
| 165 | } |
| 166 | }); |
| 167 | |
| 168 | const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
| 169 | const previousLicenseKeyGroupData = licenseKeyGroupsList[0]; |
| 170 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 171 | const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 172 | name: 'lsk1_UPDATE', |
| 173 | description: 'string_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 174 | id: toBeUpdatedLicenseKeyGroupId |
| 175 | }); |
| 176 | deepFreeze(licenseKeyGroupUpdatedData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 177 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 179 | name: 'lsk1_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 180 | description: 'string_UPDATE' |
| 181 | }); |
| 182 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 183 | deepFreeze(licenseKeyGroupPutRequest); |
| 184 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 185 | const expectedCurrentScreenProps = { |
| 186 | ...itemPermissionAndProps, |
| 187 | itemPermission: { |
| 188 | ...itemPermissionAndProps.itemPermission, |
| 189 | isDirty: true |
| 190 | } |
| 191 | }; |
| 192 | |
| 193 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]); |
| 194 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 195 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 196 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 197 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`); |
| 198 | expect(data).toEqual(licenseKeyGroupPutRequest); |
| 199 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 200 | }); |
| 201 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 202 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 203 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 204 | expect(data).toEqual(undefined); |
| 205 | expect(options).toEqual(undefined); |
| 206 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 207 | }); |
| 208 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 209 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
| 210 | previousLicenseKeyGroup: previousLicenseKeyGroupData, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 211 | licenseKeyGroup: licenseKeyGroupUpdatedData, |
| 212 | licenseModelId: LICENSE_MODEL_ID, |
| 213 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 214 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 215 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 216 | }); |
| 217 | }); |
| 218 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 219 | it('Load Limits List', () => { |
| 220 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 221 | const limitsList = LimitItemFactory.buildList(3); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 222 | deepFreeze(limitsList); |
| 223 | const store = storeCreator(); |
| 224 | deepFreeze(store.getState()); |
| 225 | |
| 226 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList); |
| 227 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 228 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 229 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 230 | expect(data).toEqual(undefined); |
| 231 | expect(options).toEqual(undefined); |
| 232 | return {results: limitsList}; |
| 233 | }); |
| 234 | |
| 235 | return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => { |
| 236 | expect(store.getState()).toEqual(expectedStore); |
| 237 | }); |
| 238 | }); |
| 239 | |
| 240 | it('Add Limit', () => { |
| 241 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 242 | const store = storeCreator({ |
| 243 | currentScreen: {...itemPermissionAndProps} |
| 244 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 245 | deepFreeze(store.getState()); |
| 246 | |
| 247 | const limitToAdd = LimitPostFactory.build(); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 248 | let limitFromBE = {...limitToAdd}; |
| 249 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 250 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 251 | |
| 252 | deepFreeze(limitToAdd); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 253 | deepFreeze(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 254 | |
| 255 | const LimitIdFromResponse = 'ADDED_ID'; |
| 256 | const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse}; |
| 257 | deepFreeze(limitAddedItem); |
| 258 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 259 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 260 | const expectedCurrentScreenProps = { |
| 261 | ...itemPermissionAndProps, |
| 262 | itemPermission: { |
| 263 | ...itemPermissionAndProps.itemPermission, |
| 264 | isDirty: true |
| 265 | } |
| 266 | }; |
| 267 | |
| 268 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]); |
| 269 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 270 | |
| 271 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 272 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 273 | expect(data).toEqual(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 274 | expect(options).toEqual(undefined); |
| 275 | return { |
| 276 | returnCode: 'OK', |
| 277 | value: LimitIdFromResponse |
| 278 | }; |
| 279 | }); |
| 280 | |
| 281 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 282 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 283 | expect(data).toEqual(undefined); |
| 284 | expect(options).toEqual(undefined); |
| 285 | return {results: [limitAddedItem]}; |
| 286 | }); |
| 287 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 288 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 289 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 290 | expect(data).toEqual(undefined); |
| 291 | expect(options).toEqual(undefined); |
| 292 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 293 | }); |
| 294 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 295 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, |
| 296 | { |
| 297 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 298 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 299 | licenseKeyGroup, |
| 300 | limit: limitToAdd |
| 301 | } |
| 302 | ).then(() => { |
| 303 | expect(store.getState()).toEqual(expectedStore); |
| 304 | }); |
| 305 | }); |
| 306 | |
| 307 | it('Delete Limit', () => { |
| 308 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 309 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 310 | deepFreeze(limitsList); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 311 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 312 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 313 | currentScreen: {...itemPermissionAndProps}, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 314 | licenseModel: { |
| 315 | entitlementPool: { |
| 316 | entitlementPoolEditor: { |
| 317 | limitsList |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | }); |
| 322 | deepFreeze(store.getState()); |
| 323 | |
| 324 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 325 | |
| 326 | const expectedCurrentScreenProps = { |
| 327 | ...itemPermissionAndProps, |
| 328 | itemPermission: { |
| 329 | ...itemPermissionAndProps.itemPermission, |
| 330 | isDirty: true |
| 331 | } |
| 332 | }; |
| 333 | |
| 334 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []); |
| 335 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 336 | |
| 337 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 338 | 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}`); |
| 339 | expect(data).toEqual(undefined); |
| 340 | expect(options).toEqual(undefined); |
| 341 | return { |
| 342 | results: { |
| 343 | returnCode: 'OK' |
| 344 | } |
| 345 | }; |
| 346 | }); |
| 347 | |
| 348 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 349 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 350 | expect(data).toEqual(undefined); |
| 351 | expect(options).toEqual(undefined); |
| 352 | return {results: []}; |
| 353 | }); |
| 354 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 355 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 356 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 357 | expect(data).toEqual(undefined); |
| 358 | expect(options).toEqual(undefined); |
| 359 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 360 | }); |
| 361 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 362 | return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, { |
| 363 | licenseModelId: LICENSE_MODEL_ID, |
| 364 | version, |
| 365 | licenseKeyGroup, |
| 366 | limit: limitsList[0] |
| 367 | }).then(() => { |
| 368 | expect(store.getState()).toEqual(expectedStore); |
| 369 | }); |
| 370 | }); |
| 371 | |
| 372 | it('Update Limit', () => { |
| 373 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 374 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 375 | deepFreeze(limitsList); |
| 376 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 377 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 378 | currentScreen: {...itemPermissionAndProps}, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 379 | licenseModel: { |
| 380 | licenseKeyGroup: { |
| 381 | licenseKeyGroupsEditor: { |
| 382 | limitsList |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | }); |
| 387 | |
| 388 | deepFreeze(store.getState()); |
| 389 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 390 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 391 | const previousData = limitsList[0]; |
| 392 | deepFreeze(previousData); |
| 393 | const limitId = limitsList[0].id; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 394 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 395 | let updatedLimit = {...previousData, name: 'updatedLimit'}; |
| 396 | const updatedLimitForPut = {...updatedLimit, id: undefined}; |
| 397 | updatedLimit.metric = {choice: updatedLimit.metric, other: ''}; |
| 398 | updatedLimit.unit = {choice: updatedLimit.unit, other: ''}; |
| 399 | deepFreeze(updatedLimit); |
| 400 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 401 | const expectedCurrentScreenProps = { |
| 402 | ...itemPermissionAndProps, |
| 403 | itemPermission: { |
| 404 | ...itemPermissionAndProps.itemPermission, |
| 405 | isDirty: true |
| 406 | } |
| 407 | }; |
| 408 | |
| 409 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimitForPut]); |
| 410 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 411 | |
| 412 | |
| 413 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 414 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`); |
| 415 | expect(data).toEqual(updatedLimitForPut); |
| 416 | expect(options).toEqual(undefined); |
| 417 | return {returnCode: 'OK'}; |
| 418 | }); |
| 419 | |
| 420 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 421 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 422 | expect(data).toEqual(undefined); |
| 423 | expect(options).toEqual(undefined); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 424 | return {results: [updatedLimitForPut]}; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 425 | }); |
| 426 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 427 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 428 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 429 | expect(data).toEqual(undefined); |
| 430 | expect(options).toEqual(undefined); |
| 431 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 432 | }); |
| 433 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 434 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, |
| 435 | { |
| 436 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 437 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 438 | licenseKeyGroup, |
| 439 | limit: updatedLimit |
| 440 | } |
| 441 | ).then(() => { |
| 442 | expect(store.getState()).toEqual(expectedStore); |
| 443 | }); |
| 444 | }); |
| 445 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 446 | }); |