AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
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'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 18 | import { cloneAndSet, buildListFromFactory } from 'test-utils/Util.js'; |
| 19 | import { storeCreator } from 'sdc-app/AppStore.js'; |
| 20 | import { |
| 21 | LicenseKeyGroupStoreFactory, |
| 22 | LicenseKeyGroupPostFactory |
| 23 | } from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | |
| 25 | import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 27 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 28 | import { |
| 29 | LimitItemFactory, |
| 30 | LimitPostFactory |
| 31 | } from 'test-utils/factories/licenseModel/LimitFactories.js'; |
| 32 | import { getStrValue } from 'nfvo-utils/getValue.js'; |
| 33 | import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 35 | describe('License Key Groups Module Tests', function() { |
| 36 | const LICENSE_MODEL_ID = '555'; |
| 37 | const version = VersionFactory.build(); |
| 38 | const itemPermissionAndProps = CurrentScreenFactory.build({}, { version }); |
| 39 | const returnedVersionFields = { |
| 40 | baseId: version.baseId, |
| 41 | description: version.description, |
| 42 | id: version.id, |
| 43 | name: version.name, |
| 44 | status: version.status |
| 45 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 46 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 47 | it('Load License Key Group', () => { |
| 48 | const licenseKeyGroupsList = buildListFromFactory( |
| 49 | LicenseKeyGroupStoreFactory |
| 50 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 52 | deepFreeze(licenseKeyGroupsList); |
| 53 | const store = storeCreator(); |
| 54 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 56 | const expectedStore = cloneAndSet( |
| 57 | store.getState(), |
| 58 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', |
| 59 | licenseKeyGroupsList |
| 60 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 61 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 62 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 63 | expect(baseUrl).toEqual( |
| 64 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 65 | version.id |
| 66 | }/license-key-groups` |
| 67 | ); |
| 68 | expect(data).toEqual(undefined); |
| 69 | expect(options).toEqual(undefined); |
| 70 | return { results: licenseKeyGroupsList }; |
| 71 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 73 | return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList( |
| 74 | store.dispatch, |
| 75 | { licenseModelId: LICENSE_MODEL_ID, version } |
| 76 | ).then(() => { |
| 77 | expect(store.getState()).toEqual(expectedStore); |
| 78 | }); |
| 79 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 81 | it('Delete License Key Group', () => { |
| 82 | const licenseKeyGroupsList = buildListFromFactory( |
| 83 | LicenseKeyGroupStoreFactory, |
| 84 | 1 |
| 85 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 86 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 87 | deepFreeze(licenseKeyGroupsList); |
| 88 | const store = storeCreator({ |
| 89 | currentScreen: { ...itemPermissionAndProps }, |
| 90 | licenseModel: { |
| 91 | licenseKeyGroup: { |
| 92 | licenseKeyGroupsList |
| 93 | } |
| 94 | } |
| 95 | }); |
| 96 | deepFreeze(store.getState()); |
| 97 | const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 99 | const expectedCurrentScreenProps = { |
| 100 | ...itemPermissionAndProps, |
| 101 | itemPermission: { |
| 102 | ...itemPermissionAndProps.itemPermission, |
| 103 | isDirty: true |
| 104 | } |
| 105 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 106 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 107 | let expectedStore = cloneAndSet( |
| 108 | store.getState(), |
| 109 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', |
| 110 | [] |
| 111 | ); |
| 112 | expectedStore = cloneAndSet( |
| 113 | expectedStore, |
| 114 | 'currentScreen.itemPermission', |
| 115 | expectedCurrentScreenProps.itemPermission |
| 116 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 117 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 118 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 119 | expect(baseUrl).toEqual( |
| 120 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 121 | version.id |
| 122 | }/license-key-groups/${toBeDeletedLicenseKeyGroupId}` |
| 123 | ); |
| 124 | expect(data).toEqual(undefined); |
| 125 | expect(options).toEqual(undefined); |
| 126 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 127 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 128 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 129 | expect(baseUrl).toEqual( |
| 130 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 131 | version.id |
| 132 | }` |
| 133 | ); |
| 134 | expect(data).toEqual(undefined); |
| 135 | expect(options).toEqual(undefined); |
| 136 | return { |
| 137 | ...returnedVersionFields, |
| 138 | state: { |
| 139 | synchronizationState: SyncStates.UP_TO_DATE, |
| 140 | dirty: true |
| 141 | } |
| 142 | }; |
| 143 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 144 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 145 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 146 | expect(baseUrl).toEqual( |
| 147 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 148 | ); |
| 149 | expect(data).toEqual(undefined); |
| 150 | expect(options).toEqual(undefined); |
| 151 | return { |
| 152 | ...returnedVersionFields |
| 153 | }; |
| 154 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 155 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 156 | return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup( |
| 157 | store.dispatch, |
| 158 | { |
| 159 | licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, |
| 160 | licenseModelId: LICENSE_MODEL_ID, |
| 161 | version |
| 162 | } |
| 163 | ).then(() => { |
| 164 | expect(store.getState()).toEqual(expectedStore); |
| 165 | }); |
| 166 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 167 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 168 | it('Add License Key Group', () => { |
| 169 | const store = storeCreator({ |
| 170 | currentScreen: { ...itemPermissionAndProps } |
| 171 | }); |
| 172 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 173 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 174 | const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); |
| 175 | deepFreeze(LicenseKeyGroupPost); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 176 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 177 | const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); |
| 178 | deepFreeze(LicenseKeyGroupStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 179 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 180 | const expectedCurrentScreenProps = { |
| 181 | ...itemPermissionAndProps, |
| 182 | itemPermission: { |
| 183 | ...itemPermissionAndProps.itemPermission, |
| 184 | isDirty: true |
| 185 | } |
| 186 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 187 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 188 | let expectedStore = cloneAndSet( |
| 189 | store.getState(), |
| 190 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', |
| 191 | [LicenseKeyGroupStore] |
| 192 | ); |
| 193 | expectedStore = cloneAndSet( |
| 194 | expectedStore, |
| 195 | 'currentScreen.itemPermission', |
| 196 | expectedCurrentScreenProps.itemPermission |
| 197 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 198 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 199 | mockRest.addHandler('post', ({ options, data, baseUrl }) => { |
| 200 | expect(baseUrl).toEqual( |
| 201 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 202 | version.id |
| 203 | }/license-key-groups` |
| 204 | ); |
| 205 | expect(data).toEqual(LicenseKeyGroupPost); |
| 206 | expect(options).toEqual(undefined); |
| 207 | return { |
| 208 | value: LicenseKeyGroupStore.id |
| 209 | }; |
| 210 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 211 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 212 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 213 | expect(baseUrl).toEqual( |
| 214 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 215 | version.id |
| 216 | }` |
| 217 | ); |
| 218 | expect(data).toEqual(undefined); |
| 219 | expect(options).toEqual(undefined); |
| 220 | return { |
| 221 | ...returnedVersionFields, |
| 222 | state: { |
| 223 | synchronizationState: SyncStates.UP_TO_DATE, |
| 224 | dirty: true |
| 225 | } |
| 226 | }; |
| 227 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 228 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 229 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 230 | expect(baseUrl).toEqual( |
| 231 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 232 | ); |
| 233 | expect(data).toEqual(undefined); |
| 234 | expect(options).toEqual(undefined); |
| 235 | return { |
| 236 | ...returnedVersionFields |
| 237 | }; |
| 238 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 239 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 240 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup( |
| 241 | store.dispatch, |
| 242 | { |
| 243 | licenseKeyGroup: LicenseKeyGroupPost, |
| 244 | licenseModelId: LICENSE_MODEL_ID, |
| 245 | version |
| 246 | } |
| 247 | ).then(() => { |
| 248 | expect(store.getState()).toEqual(expectedStore); |
| 249 | }); |
| 250 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 251 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 252 | it('Update License Key Group', () => { |
| 253 | const licenseKeyGroupsList = buildListFromFactory( |
| 254 | LicenseKeyGroupStoreFactory, |
| 255 | 1 |
| 256 | ); |
| 257 | deepFreeze(licenseKeyGroupsList); |
| 258 | const store = storeCreator({ |
| 259 | currentScreen: { ...itemPermissionAndProps }, |
| 260 | licenseModel: { |
| 261 | licenseKeyGroup: { |
| 262 | licenseKeyGroupsList |
| 263 | } |
| 264 | } |
| 265 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 266 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 267 | const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
| 268 | const previousLicenseKeyGroupData = licenseKeyGroupsList[0]; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 269 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 270 | const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ |
| 271 | name: 'lsk1_UPDATE', |
| 272 | description: 'string_UPDATE', |
| 273 | id: toBeUpdatedLicenseKeyGroupId |
| 274 | }); |
| 275 | deepFreeze(licenseKeyGroupUpdatedData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 276 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 277 | const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ |
| 278 | name: 'lsk1_UPDATE', |
| 279 | description: 'string_UPDATE' |
| 280 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 281 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 282 | deepFreeze(licenseKeyGroupPutRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 283 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 284 | const expectedCurrentScreenProps = { |
| 285 | ...itemPermissionAndProps, |
| 286 | itemPermission: { |
| 287 | ...itemPermissionAndProps.itemPermission, |
| 288 | isDirty: true |
| 289 | } |
| 290 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 291 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 292 | let expectedStore = cloneAndSet( |
| 293 | store.getState(), |
| 294 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', |
| 295 | [licenseKeyGroupUpdatedData] |
| 296 | ); |
| 297 | expectedStore = cloneAndSet( |
| 298 | expectedStore, |
| 299 | 'currentScreen.itemPermission', |
| 300 | expectedCurrentScreenProps.itemPermission |
| 301 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 302 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 303 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 304 | expect(baseUrl).toEqual( |
| 305 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 306 | version.id |
| 307 | }/license-key-groups/${toBeUpdatedLicenseKeyGroupId}` |
| 308 | ); |
| 309 | expect(data).toEqual(licenseKeyGroupPutRequest); |
| 310 | expect(options).toEqual(undefined); |
| 311 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 312 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 313 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 314 | expect(baseUrl).toEqual( |
| 315 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 316 | version.id |
| 317 | }` |
| 318 | ); |
| 319 | expect(data).toEqual(undefined); |
| 320 | expect(options).toEqual(undefined); |
| 321 | return { |
| 322 | ...returnedVersionFields, |
| 323 | state: { |
| 324 | synchronizationState: SyncStates.UP_TO_DATE, |
| 325 | dirty: true |
| 326 | } |
| 327 | }; |
| 328 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 329 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 330 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 331 | expect(baseUrl).toEqual( |
| 332 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 333 | ); |
| 334 | expect(data).toEqual(undefined); |
| 335 | expect(options).toEqual(undefined); |
| 336 | return { |
| 337 | ...returnedVersionFields |
| 338 | }; |
| 339 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 340 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 341 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup( |
| 342 | store.dispatch, |
| 343 | { |
| 344 | previousLicenseKeyGroup: previousLicenseKeyGroupData, |
| 345 | licenseKeyGroup: licenseKeyGroupUpdatedData, |
| 346 | licenseModelId: LICENSE_MODEL_ID, |
| 347 | version |
| 348 | } |
| 349 | ).then(() => { |
| 350 | expect(store.getState()).toEqual(expectedStore); |
| 351 | }); |
| 352 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 353 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 354 | it('Load Limits List', () => { |
| 355 | const limitsList = LimitItemFactory.buildList(3); |
| 356 | deepFreeze(limitsList); |
| 357 | const store = storeCreator(); |
| 358 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 359 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 360 | const expectedStore = cloneAndSet( |
| 361 | store.getState(), |
| 362 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 363 | limitsList |
| 364 | ); |
| 365 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 366 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 367 | expect(baseUrl).toEqual( |
| 368 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 369 | version.id |
| 370 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 371 | ); |
| 372 | expect(data).toEqual(undefined); |
| 373 | expect(options).toEqual(undefined); |
| 374 | return { results: limitsList }; |
| 375 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 376 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 377 | return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, { |
| 378 | licenseModelId: LICENSE_MODEL_ID, |
| 379 | version, |
| 380 | licenseKeyGroup |
| 381 | }).then(() => { |
| 382 | expect(store.getState()).toEqual(expectedStore); |
| 383 | }); |
| 384 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 385 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 386 | it('Add Limit', () => { |
| 387 | const store = storeCreator({ |
| 388 | currentScreen: { ...itemPermissionAndProps } |
| 389 | }); |
| 390 | deepFreeze(store.getState()); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 391 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 392 | const limitToAdd = LimitPostFactory.build(); |
| 393 | let limitFromBE = { ...limitToAdd }; |
| 394 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 395 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 396 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 397 | deepFreeze(limitToAdd); |
| 398 | deepFreeze(limitFromBE); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 399 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 400 | const LimitIdFromResponse = 'ADDED_ID'; |
| 401 | const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse }; |
| 402 | deepFreeze(limitAddedItem); |
| 403 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 404 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 405 | const expectedCurrentScreenProps = { |
| 406 | ...itemPermissionAndProps, |
| 407 | itemPermission: { |
| 408 | ...itemPermissionAndProps.itemPermission, |
| 409 | isDirty: true |
| 410 | } |
| 411 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 412 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 413 | let expectedStore = cloneAndSet( |
| 414 | store.getState(), |
| 415 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 416 | [limitAddedItem] |
| 417 | ); |
| 418 | expectedStore = cloneAndSet( |
| 419 | expectedStore, |
| 420 | 'currentScreen.itemPermission', |
| 421 | expectedCurrentScreenProps.itemPermission |
| 422 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 423 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 424 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 425 | expect(baseUrl).toEqual( |
| 426 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 427 | version.id |
| 428 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 429 | ); |
| 430 | expect(data).toEqual(limitFromBE); |
| 431 | expect(options).toEqual(undefined); |
| 432 | return { |
| 433 | returnCode: 'OK', |
| 434 | value: LimitIdFromResponse |
| 435 | }; |
| 436 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 437 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 438 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 439 | expect(baseUrl).toEqual( |
| 440 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 441 | version.id |
| 442 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 443 | ); |
| 444 | expect(data).toEqual(undefined); |
| 445 | expect(options).toEqual(undefined); |
| 446 | return { results: [limitAddedItem] }; |
| 447 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 448 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 449 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 450 | expect(baseUrl).toEqual( |
| 451 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 452 | version.id |
| 453 | }` |
| 454 | ); |
| 455 | expect(data).toEqual(undefined); |
| 456 | expect(options).toEqual(undefined); |
| 457 | return { |
| 458 | ...returnedVersionFields, |
| 459 | state: { |
| 460 | synchronizationState: SyncStates.UP_TO_DATE, |
| 461 | dirty: true |
| 462 | } |
| 463 | }; |
| 464 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 465 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 466 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 467 | expect(baseUrl).toEqual( |
| 468 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 469 | ); |
| 470 | expect(data).toEqual(undefined); |
| 471 | expect(options).toEqual(undefined); |
| 472 | return { |
| 473 | ...returnedVersionFields |
| 474 | }; |
| 475 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 476 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 477 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, { |
| 478 | licenseModelId: LICENSE_MODEL_ID, |
| 479 | version, |
| 480 | licenseKeyGroup, |
| 481 | limit: limitToAdd |
| 482 | }).then(() => { |
| 483 | expect(store.getState()).toEqual(expectedStore); |
| 484 | }); |
| 485 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 486 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 487 | it('Delete Limit', () => { |
| 488 | const limitsList = LimitItemFactory.buildList(1); |
| 489 | deepFreeze(limitsList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 490 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 491 | const store = storeCreator({ |
| 492 | currentScreen: { ...itemPermissionAndProps }, |
| 493 | licenseModel: { |
| 494 | entitlementPool: { |
| 495 | entitlementPoolEditor: { |
| 496 | limitsList |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | }); |
| 501 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 502 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 503 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 504 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 505 | const expectedCurrentScreenProps = { |
| 506 | ...itemPermissionAndProps, |
| 507 | itemPermission: { |
| 508 | ...itemPermissionAndProps.itemPermission, |
| 509 | isDirty: true |
| 510 | } |
| 511 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 512 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 513 | let expectedStore = cloneAndSet( |
| 514 | store.getState(), |
| 515 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 516 | [] |
| 517 | ); |
| 518 | expectedStore = cloneAndSet( |
| 519 | expectedStore, |
| 520 | 'currentScreen.itemPermission', |
| 521 | expectedCurrentScreenProps.itemPermission |
| 522 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 523 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 524 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 525 | expect(baseUrl).toEqual( |
| 526 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 527 | version.id |
| 528 | }/license-key-groups/${licenseKeyGroup.id}/limits/${ |
| 529 | limitsList[0].id |
| 530 | }` |
| 531 | ); |
| 532 | expect(data).toEqual(undefined); |
| 533 | expect(options).toEqual(undefined); |
| 534 | return { |
| 535 | results: { |
| 536 | returnCode: 'OK' |
| 537 | } |
| 538 | }; |
| 539 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 540 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 541 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 542 | expect(baseUrl).toEqual( |
| 543 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 544 | version.id |
| 545 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 546 | ); |
| 547 | expect(data).toEqual(undefined); |
| 548 | expect(options).toEqual(undefined); |
| 549 | return { results: [] }; |
| 550 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 551 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 552 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 553 | expect(baseUrl).toEqual( |
| 554 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 555 | version.id |
| 556 | }` |
| 557 | ); |
| 558 | expect(data).toEqual(undefined); |
| 559 | expect(options).toEqual(undefined); |
| 560 | return { |
| 561 | ...returnedVersionFields, |
| 562 | state: { |
| 563 | synchronizationState: SyncStates.UP_TO_DATE, |
| 564 | dirty: true |
| 565 | } |
| 566 | }; |
| 567 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 568 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 569 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 570 | expect(baseUrl).toEqual( |
| 571 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 572 | ); |
| 573 | expect(data).toEqual(undefined); |
| 574 | expect(options).toEqual(undefined); |
| 575 | return { |
| 576 | ...returnedVersionFields |
| 577 | }; |
| 578 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 579 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 580 | return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, { |
| 581 | licenseModelId: LICENSE_MODEL_ID, |
| 582 | version, |
| 583 | licenseKeyGroup, |
| 584 | limit: limitsList[0] |
| 585 | }).then(() => { |
| 586 | expect(store.getState()).toEqual(expectedStore); |
| 587 | }); |
| 588 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 589 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 590 | it('Update Limit', () => { |
| 591 | const limitsList = LimitItemFactory.buildList(1); |
| 592 | deepFreeze(limitsList); |
| 593 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 594 | const store = storeCreator({ |
| 595 | currentScreen: { ...itemPermissionAndProps }, |
| 596 | licenseModel: { |
| 597 | licenseKeyGroup: { |
| 598 | licenseKeyGroupsEditor: { |
| 599 | limitsList |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 604 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 605 | deepFreeze(store.getState()); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 606 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 607 | const previousData = limitsList[0]; |
| 608 | deepFreeze(previousData); |
| 609 | const limitId = limitsList[0].id; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 610 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 611 | let updatedLimit = { ...previousData, name: 'updatedLimit' }; |
| 612 | const updatedLimitForPut = { ...updatedLimit, id: undefined }; |
| 613 | updatedLimit.metric = { choice: updatedLimit.metric, other: '' }; |
| 614 | updatedLimit.unit = { choice: updatedLimit.unit, other: '' }; |
| 615 | deepFreeze(updatedLimit); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 616 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 617 | const expectedCurrentScreenProps = { |
| 618 | ...itemPermissionAndProps, |
| 619 | itemPermission: { |
| 620 | ...itemPermissionAndProps.itemPermission, |
| 621 | isDirty: true |
| 622 | } |
| 623 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 624 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 625 | let expectedStore = cloneAndSet( |
| 626 | store.getState(), |
| 627 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 628 | [updatedLimitForPut] |
| 629 | ); |
| 630 | expectedStore = cloneAndSet( |
| 631 | expectedStore, |
| 632 | 'currentScreen.itemPermission', |
| 633 | expectedCurrentScreenProps.itemPermission |
| 634 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 635 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 636 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 637 | expect(baseUrl).toEqual( |
| 638 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 639 | version.id |
| 640 | }/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}` |
| 641 | ); |
| 642 | expect(data).toEqual(updatedLimitForPut); |
| 643 | expect(options).toEqual(undefined); |
| 644 | return { returnCode: 'OK' }; |
| 645 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 646 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 647 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 648 | expect(baseUrl).toEqual( |
| 649 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 650 | version.id |
| 651 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 652 | ); |
| 653 | expect(data).toEqual(undefined); |
| 654 | expect(options).toEqual(undefined); |
| 655 | return { results: [updatedLimitForPut] }; |
| 656 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 657 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 658 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 659 | expect(baseUrl).toEqual( |
| 660 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 661 | version.id |
| 662 | }` |
| 663 | ); |
| 664 | expect(data).toEqual(undefined); |
| 665 | expect(options).toEqual(undefined); |
| 666 | return { |
| 667 | ...returnedVersionFields, |
| 668 | state: { |
| 669 | synchronizationState: SyncStates.UP_TO_DATE, |
| 670 | dirty: true |
| 671 | } |
| 672 | }; |
| 673 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 674 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 675 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 676 | expect(baseUrl).toEqual( |
| 677 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 678 | ); |
| 679 | expect(data).toEqual(undefined); |
| 680 | expect(options).toEqual(undefined); |
| 681 | return { |
| 682 | ...returnedVersionFields |
| 683 | }; |
| 684 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 685 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 686 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, { |
| 687 | licenseModelId: LICENSE_MODEL_ID, |
| 688 | version, |
| 689 | licenseKeyGroup, |
| 690 | limit: updatedLimit |
| 691 | }).then(() => { |
| 692 | expect(store.getState()).toEqual(expectedStore); |
| 693 | }); |
| 694 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 695 | }); |