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 | 8f13330 | 2018-08-06 23:08:39 +0300 | [diff] [blame] | 156 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 157 | expect(baseUrl).toEqual( |
| 158 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 159 | version.id |
| 160 | }/license-key-groups` |
| 161 | ); |
| 162 | expect(data).toEqual(undefined); |
| 163 | expect(options).toEqual(undefined); |
| 164 | return { results: [] }; |
| 165 | }); |
| 166 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 167 | return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup( |
| 168 | store.dispatch, |
| 169 | { |
| 170 | licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, |
| 171 | licenseModelId: LICENSE_MODEL_ID, |
| 172 | version |
| 173 | } |
| 174 | ).then(() => { |
| 175 | expect(store.getState()).toEqual(expectedStore); |
| 176 | }); |
| 177 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 178 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 179 | it('Add License Key Group', () => { |
| 180 | const store = storeCreator({ |
| 181 | currentScreen: { ...itemPermissionAndProps } |
| 182 | }); |
| 183 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 184 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 185 | const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); |
| 186 | deepFreeze(LicenseKeyGroupPost); |
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 | const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); |
| 189 | deepFreeze(LicenseKeyGroupStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 190 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 191 | const expectedCurrentScreenProps = { |
| 192 | ...itemPermissionAndProps, |
| 193 | itemPermission: { |
| 194 | ...itemPermissionAndProps.itemPermission, |
| 195 | isDirty: true |
| 196 | } |
| 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 | let expectedStore = cloneAndSet( |
| 200 | store.getState(), |
| 201 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', |
| 202 | [LicenseKeyGroupStore] |
| 203 | ); |
| 204 | expectedStore = cloneAndSet( |
| 205 | expectedStore, |
| 206 | 'currentScreen.itemPermission', |
| 207 | expectedCurrentScreenProps.itemPermission |
| 208 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 209 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 210 | mockRest.addHandler('post', ({ options, data, baseUrl }) => { |
| 211 | expect(baseUrl).toEqual( |
| 212 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 213 | version.id |
| 214 | }/license-key-groups` |
| 215 | ); |
| 216 | expect(data).toEqual(LicenseKeyGroupPost); |
| 217 | expect(options).toEqual(undefined); |
| 218 | return { |
| 219 | value: LicenseKeyGroupStore.id |
| 220 | }; |
| 221 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 222 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 223 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 224 | expect(baseUrl).toEqual( |
| 225 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 226 | version.id |
| 227 | }` |
| 228 | ); |
| 229 | expect(data).toEqual(undefined); |
| 230 | expect(options).toEqual(undefined); |
| 231 | return { |
| 232 | ...returnedVersionFields, |
| 233 | state: { |
| 234 | synchronizationState: SyncStates.UP_TO_DATE, |
| 235 | dirty: true |
| 236 | } |
| 237 | }; |
| 238 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 239 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 240 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 241 | expect(baseUrl).toEqual( |
| 242 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 243 | ); |
| 244 | expect(data).toEqual(undefined); |
| 245 | expect(options).toEqual(undefined); |
| 246 | return { |
| 247 | ...returnedVersionFields |
| 248 | }; |
| 249 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 250 | |
svishnev | 8f13330 | 2018-08-06 23:08:39 +0300 | [diff] [blame] | 251 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 252 | expect(baseUrl).toEqual( |
| 253 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 254 | version.id |
| 255 | }/license-key-groups` |
| 256 | ); |
| 257 | expect(data).toEqual(undefined); |
| 258 | expect(options).toEqual(undefined); |
| 259 | return { results: [LicenseKeyGroupStore] }; |
| 260 | }); |
| 261 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 262 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup( |
| 263 | store.dispatch, |
| 264 | { |
| 265 | licenseKeyGroup: LicenseKeyGroupPost, |
| 266 | licenseModelId: LICENSE_MODEL_ID, |
| 267 | version |
| 268 | } |
| 269 | ).then(() => { |
| 270 | expect(store.getState()).toEqual(expectedStore); |
| 271 | }); |
| 272 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 273 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 274 | it('Update License Key Group', () => { |
| 275 | const licenseKeyGroupsList = buildListFromFactory( |
| 276 | LicenseKeyGroupStoreFactory, |
| 277 | 1 |
| 278 | ); |
| 279 | deepFreeze(licenseKeyGroupsList); |
| 280 | const store = storeCreator({ |
| 281 | currentScreen: { ...itemPermissionAndProps }, |
| 282 | licenseModel: { |
| 283 | licenseKeyGroup: { |
| 284 | licenseKeyGroupsList |
| 285 | } |
| 286 | } |
| 287 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 288 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 289 | const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
| 290 | const previousLicenseKeyGroupData = licenseKeyGroupsList[0]; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 291 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 292 | const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ |
| 293 | name: 'lsk1_UPDATE', |
| 294 | description: 'string_UPDATE', |
| 295 | id: toBeUpdatedLicenseKeyGroupId |
| 296 | }); |
| 297 | deepFreeze(licenseKeyGroupUpdatedData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 298 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 299 | const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ |
| 300 | name: 'lsk1_UPDATE', |
| 301 | description: 'string_UPDATE' |
| 302 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 303 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 304 | deepFreeze(licenseKeyGroupPutRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 305 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 306 | const expectedCurrentScreenProps = { |
| 307 | ...itemPermissionAndProps, |
| 308 | itemPermission: { |
| 309 | ...itemPermissionAndProps.itemPermission, |
| 310 | isDirty: true |
| 311 | } |
| 312 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 313 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 314 | let expectedStore = cloneAndSet( |
| 315 | store.getState(), |
| 316 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', |
| 317 | [licenseKeyGroupUpdatedData] |
| 318 | ); |
| 319 | expectedStore = cloneAndSet( |
| 320 | expectedStore, |
| 321 | 'currentScreen.itemPermission', |
| 322 | expectedCurrentScreenProps.itemPermission |
| 323 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 324 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 325 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 326 | expect(baseUrl).toEqual( |
| 327 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 328 | version.id |
| 329 | }/license-key-groups/${toBeUpdatedLicenseKeyGroupId}` |
| 330 | ); |
| 331 | expect(data).toEqual(licenseKeyGroupPutRequest); |
| 332 | expect(options).toEqual(undefined); |
| 333 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 334 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 335 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 336 | expect(baseUrl).toEqual( |
| 337 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 338 | version.id |
| 339 | }` |
| 340 | ); |
| 341 | expect(data).toEqual(undefined); |
| 342 | expect(options).toEqual(undefined); |
| 343 | return { |
| 344 | ...returnedVersionFields, |
| 345 | state: { |
| 346 | synchronizationState: SyncStates.UP_TO_DATE, |
| 347 | dirty: true |
| 348 | } |
| 349 | }; |
| 350 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 351 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 352 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 353 | expect(baseUrl).toEqual( |
| 354 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 355 | ); |
| 356 | expect(data).toEqual(undefined); |
| 357 | expect(options).toEqual(undefined); |
| 358 | return { |
| 359 | ...returnedVersionFields |
| 360 | }; |
| 361 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 362 | |
svishnev | 8f13330 | 2018-08-06 23:08:39 +0300 | [diff] [blame] | 363 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 364 | expect(baseUrl).toEqual( |
| 365 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 366 | version.id |
| 367 | }/license-key-groups` |
| 368 | ); |
| 369 | expect(data).toEqual(undefined); |
| 370 | expect(options).toEqual(undefined); |
| 371 | return { results: [licenseKeyGroupUpdatedData] }; |
| 372 | }); |
| 373 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 374 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup( |
| 375 | store.dispatch, |
| 376 | { |
| 377 | previousLicenseKeyGroup: previousLicenseKeyGroupData, |
| 378 | licenseKeyGroup: licenseKeyGroupUpdatedData, |
| 379 | licenseModelId: LICENSE_MODEL_ID, |
| 380 | version |
| 381 | } |
| 382 | ).then(() => { |
| 383 | expect(store.getState()).toEqual(expectedStore); |
| 384 | }); |
| 385 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 386 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 387 | it('Load Limits List', () => { |
| 388 | const limitsList = LimitItemFactory.buildList(3); |
| 389 | deepFreeze(limitsList); |
| 390 | const store = storeCreator(); |
| 391 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 392 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 393 | const expectedStore = cloneAndSet( |
| 394 | store.getState(), |
| 395 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 396 | limitsList |
| 397 | ); |
| 398 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 399 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 400 | expect(baseUrl).toEqual( |
| 401 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 402 | version.id |
| 403 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 404 | ); |
| 405 | expect(data).toEqual(undefined); |
| 406 | expect(options).toEqual(undefined); |
| 407 | return { results: limitsList }; |
| 408 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 409 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 410 | return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, { |
| 411 | licenseModelId: LICENSE_MODEL_ID, |
| 412 | version, |
| 413 | licenseKeyGroup |
| 414 | }).then(() => { |
| 415 | expect(store.getState()).toEqual(expectedStore); |
| 416 | }); |
| 417 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 418 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 419 | it('Add Limit', () => { |
| 420 | const store = storeCreator({ |
| 421 | currentScreen: { ...itemPermissionAndProps } |
| 422 | }); |
| 423 | deepFreeze(store.getState()); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 424 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 425 | const limitToAdd = LimitPostFactory.build(); |
| 426 | let limitFromBE = { ...limitToAdd }; |
| 427 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 428 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 429 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 430 | deepFreeze(limitToAdd); |
| 431 | deepFreeze(limitFromBE); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 432 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 433 | const LimitIdFromResponse = 'ADDED_ID'; |
| 434 | const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse }; |
| 435 | deepFreeze(limitAddedItem); |
| 436 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 437 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 438 | const expectedCurrentScreenProps = { |
| 439 | ...itemPermissionAndProps, |
| 440 | itemPermission: { |
| 441 | ...itemPermissionAndProps.itemPermission, |
| 442 | isDirty: true |
| 443 | } |
| 444 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 445 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 446 | let expectedStore = cloneAndSet( |
| 447 | store.getState(), |
| 448 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 449 | [limitAddedItem] |
| 450 | ); |
| 451 | expectedStore = cloneAndSet( |
| 452 | expectedStore, |
| 453 | 'currentScreen.itemPermission', |
| 454 | expectedCurrentScreenProps.itemPermission |
| 455 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 456 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 457 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 458 | expect(baseUrl).toEqual( |
| 459 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 460 | version.id |
| 461 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 462 | ); |
| 463 | expect(data).toEqual(limitFromBE); |
| 464 | expect(options).toEqual(undefined); |
| 465 | return { |
| 466 | returnCode: 'OK', |
| 467 | value: LimitIdFromResponse |
| 468 | }; |
| 469 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 470 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 471 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 472 | expect(baseUrl).toEqual( |
| 473 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 474 | version.id |
| 475 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 476 | ); |
| 477 | expect(data).toEqual(undefined); |
| 478 | expect(options).toEqual(undefined); |
| 479 | return { results: [limitAddedItem] }; |
| 480 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 481 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 482 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 483 | expect(baseUrl).toEqual( |
| 484 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 485 | version.id |
| 486 | }` |
| 487 | ); |
| 488 | expect(data).toEqual(undefined); |
| 489 | expect(options).toEqual(undefined); |
| 490 | return { |
| 491 | ...returnedVersionFields, |
| 492 | state: { |
| 493 | synchronizationState: SyncStates.UP_TO_DATE, |
| 494 | dirty: true |
| 495 | } |
| 496 | }; |
| 497 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 498 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 499 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 500 | expect(baseUrl).toEqual( |
| 501 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 502 | ); |
| 503 | expect(data).toEqual(undefined); |
| 504 | expect(options).toEqual(undefined); |
| 505 | return { |
| 506 | ...returnedVersionFields |
| 507 | }; |
| 508 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 509 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 510 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, { |
| 511 | licenseModelId: LICENSE_MODEL_ID, |
| 512 | version, |
| 513 | licenseKeyGroup, |
| 514 | limit: limitToAdd |
| 515 | }).then(() => { |
| 516 | expect(store.getState()).toEqual(expectedStore); |
| 517 | }); |
| 518 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 519 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 520 | it('Delete Limit', () => { |
| 521 | const limitsList = LimitItemFactory.buildList(1); |
| 522 | deepFreeze(limitsList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 523 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 524 | const store = storeCreator({ |
| 525 | currentScreen: { ...itemPermissionAndProps }, |
| 526 | licenseModel: { |
| 527 | entitlementPool: { |
| 528 | entitlementPoolEditor: { |
| 529 | limitsList |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | }); |
| 534 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 535 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 536 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 537 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 538 | const expectedCurrentScreenProps = { |
| 539 | ...itemPermissionAndProps, |
| 540 | itemPermission: { |
| 541 | ...itemPermissionAndProps.itemPermission, |
| 542 | isDirty: true |
| 543 | } |
| 544 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 545 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 546 | let expectedStore = cloneAndSet( |
| 547 | store.getState(), |
| 548 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 549 | [] |
| 550 | ); |
| 551 | expectedStore = cloneAndSet( |
| 552 | expectedStore, |
| 553 | 'currentScreen.itemPermission', |
| 554 | expectedCurrentScreenProps.itemPermission |
| 555 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 556 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 557 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 558 | expect(baseUrl).toEqual( |
| 559 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 560 | version.id |
| 561 | }/license-key-groups/${licenseKeyGroup.id}/limits/${ |
| 562 | limitsList[0].id |
| 563 | }` |
| 564 | ); |
| 565 | expect(data).toEqual(undefined); |
| 566 | expect(options).toEqual(undefined); |
| 567 | return { |
| 568 | results: { |
| 569 | returnCode: 'OK' |
| 570 | } |
| 571 | }; |
| 572 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 573 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 574 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 575 | expect(baseUrl).toEqual( |
| 576 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 577 | version.id |
| 578 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 579 | ); |
| 580 | expect(data).toEqual(undefined); |
| 581 | expect(options).toEqual(undefined); |
| 582 | return { results: [] }; |
| 583 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 584 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 585 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 586 | expect(baseUrl).toEqual( |
| 587 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 588 | version.id |
| 589 | }` |
| 590 | ); |
| 591 | expect(data).toEqual(undefined); |
| 592 | expect(options).toEqual(undefined); |
| 593 | return { |
| 594 | ...returnedVersionFields, |
| 595 | state: { |
| 596 | synchronizationState: SyncStates.UP_TO_DATE, |
| 597 | dirty: true |
| 598 | } |
| 599 | }; |
| 600 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 601 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 602 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 603 | expect(baseUrl).toEqual( |
| 604 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 605 | ); |
| 606 | expect(data).toEqual(undefined); |
| 607 | expect(options).toEqual(undefined); |
| 608 | return { |
| 609 | ...returnedVersionFields |
| 610 | }; |
| 611 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 612 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 613 | return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, { |
| 614 | licenseModelId: LICENSE_MODEL_ID, |
| 615 | version, |
| 616 | licenseKeyGroup, |
| 617 | limit: limitsList[0] |
| 618 | }).then(() => { |
| 619 | expect(store.getState()).toEqual(expectedStore); |
| 620 | }); |
| 621 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 622 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 623 | it('Update Limit', () => { |
| 624 | const limitsList = LimitItemFactory.buildList(1); |
| 625 | deepFreeze(limitsList); |
| 626 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 627 | const store = storeCreator({ |
| 628 | currentScreen: { ...itemPermissionAndProps }, |
| 629 | licenseModel: { |
| 630 | licenseKeyGroup: { |
| 631 | licenseKeyGroupsEditor: { |
| 632 | limitsList |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 637 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 638 | deepFreeze(store.getState()); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 639 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 640 | const previousData = limitsList[0]; |
| 641 | deepFreeze(previousData); |
| 642 | const limitId = limitsList[0].id; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 643 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 644 | let updatedLimit = { ...previousData, name: 'updatedLimit' }; |
| 645 | const updatedLimitForPut = { ...updatedLimit, id: undefined }; |
| 646 | updatedLimit.metric = { choice: updatedLimit.metric, other: '' }; |
| 647 | updatedLimit.unit = { choice: updatedLimit.unit, other: '' }; |
| 648 | deepFreeze(updatedLimit); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 649 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 650 | const expectedCurrentScreenProps = { |
| 651 | ...itemPermissionAndProps, |
| 652 | itemPermission: { |
| 653 | ...itemPermissionAndProps.itemPermission, |
| 654 | isDirty: true |
| 655 | } |
| 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 | let expectedStore = cloneAndSet( |
| 659 | store.getState(), |
| 660 | 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', |
| 661 | [updatedLimitForPut] |
| 662 | ); |
| 663 | expectedStore = cloneAndSet( |
| 664 | expectedStore, |
| 665 | 'currentScreen.itemPermission', |
| 666 | expectedCurrentScreenProps.itemPermission |
| 667 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 668 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 669 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 670 | expect(baseUrl).toEqual( |
| 671 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 672 | version.id |
| 673 | }/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}` |
| 674 | ); |
| 675 | expect(data).toEqual(updatedLimitForPut); |
| 676 | expect(options).toEqual(undefined); |
| 677 | return { returnCode: 'OK' }; |
| 678 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 679 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 680 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 681 | expect(baseUrl).toEqual( |
| 682 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 683 | version.id |
| 684 | }/license-key-groups/${licenseKeyGroup.id}/limits` |
| 685 | ); |
| 686 | expect(data).toEqual(undefined); |
| 687 | expect(options).toEqual(undefined); |
| 688 | return { results: [updatedLimitForPut] }; |
| 689 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 690 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 691 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 692 | expect(baseUrl).toEqual( |
| 693 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 694 | version.id |
| 695 | }` |
| 696 | ); |
| 697 | expect(data).toEqual(undefined); |
| 698 | expect(options).toEqual(undefined); |
| 699 | return { |
| 700 | ...returnedVersionFields, |
| 701 | state: { |
| 702 | synchronizationState: SyncStates.UP_TO_DATE, |
| 703 | dirty: true |
| 704 | } |
| 705 | }; |
| 706 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 707 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 708 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 709 | expect(baseUrl).toEqual( |
| 710 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 711 | ); |
| 712 | expect(data).toEqual(undefined); |
| 713 | expect(options).toEqual(undefined); |
| 714 | return { |
| 715 | ...returnedVersionFields |
| 716 | }; |
| 717 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 718 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 719 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, { |
| 720 | licenseModelId: LICENSE_MODEL_ID, |
| 721 | version, |
| 722 | licenseKeyGroup, |
| 723 | limit: updatedLimit |
| 724 | }).then(() => { |
| 725 | expect(store.getState()).toEqual(expectedStore); |
| 726 | }); |
| 727 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 728 | }); |