AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [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'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 17 | import pickBy from 'lodash/pickBy'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import mockRest from 'test-utils/MockRest.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 20 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 21 | import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js'; |
| 22 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import { LicenseAgreementStoreFactory, LicenseAgreementDispatchFactory, LicenseAgreementPostFactory, LicenseAgreementPutFactory } from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 25 | import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js'; |
| 26 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | |
| 28 | describe('License Agreement Module Tests', () => { |
| 29 | |
| 30 | const LICENSE_MODEL_ID = '777'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 31 | const version = VersionFactory.build(); |
| 32 | const itemPermissionAndProps = CurrentScreenFactory.build({}, {version}); |
| 33 | const returnedVersionFields = {baseId: version.baseId, description: version.description, id: version.id, name: version.name, status: version.status}; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | |
| 35 | it('Load License Agreement List', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory); |
| 37 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 38 | const store = storeCreator(); |
| 39 | deepFreeze(store.getState()); |
| 40 | |
| 41 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', licenseAgreementList); |
| 42 | |
| 43 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 44 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 45 | expect(data).toEqual(undefined); |
| 46 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 47 | return {results: licenseAgreementList}; |
| 48 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | return LicenseAgreementActionHelper.fetchLicenseAgreementList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 50 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 51 | }); |
| 52 | }); |
| 53 | |
| 54 | it('Delete License Agreement', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 56 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 57 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 58 | licenseModel: { |
| 59 | licenseAgreement: { |
| 60 | licenseAgreementList |
| 61 | } |
| 62 | } |
| 63 | }); |
| 64 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 65 | const expectedCurrentScreenProps = { |
| 66 | ...itemPermissionAndProps, |
| 67 | itemPermission: { |
| 68 | ...itemPermissionAndProps.itemPermission, |
| 69 | isDirty: true |
| 70 | } |
| 71 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 72 | const toBeDeletedLicenseAgreementId = licenseAgreementList[0].id; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 73 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', []); |
| 74 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 75 | |
| 76 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeDeletedLicenseAgreementId}`); |
| 78 | expect(data).toEqual(undefined); |
| 79 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 81 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 82 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 83 | expect(data).toEqual(undefined); |
| 84 | expect(options).toEqual(undefined); |
| 85 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 86 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 87 | |
| 88 | return LicenseAgreementActionHelper.deleteLicenseAgreement(store.dispatch, { |
| 89 | licenseAgreementId: toBeDeletedLicenseAgreementId, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 90 | licenseModelId: LICENSE_MODEL_ID, |
| 91 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | }); |
| 95 | }); |
| 96 | |
| 97 | it('Add License Agreement', () => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 98 | const store = storeCreator({ |
| 99 | currentScreen: {...itemPermissionAndProps} |
| 100 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | const licenseAgreementToAdd = LicenseAgreementDispatchFactory.build(); |
| 104 | |
| 105 | const LicenseAgreementPostRequest = LicenseAgreementPostFactory.build( |
| 106 | pickBy(licenseAgreementToAdd, (val, key) => key !== 'featureGroupsIds') |
| 107 | ); |
| 108 | |
| 109 | deepFreeze(LicenseAgreementPostRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 110 | |
| 111 | const licenseAgreementIdFromResponse = 'ADDED_ID'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 112 | const licenseAgreementAfterAdd = LicenseAgreementStoreFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | ...licenseAgreementToAdd, |
| 114 | id: licenseAgreementIdFromResponse |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 116 | deepFreeze(licenseAgreementAfterAdd); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 117 | const licenseAgreementList = [licenseAgreementAfterAdd]; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 118 | const expectedCurrentScreenProps = { |
| 119 | ...itemPermissionAndProps, |
| 120 | itemPermission: { |
| 121 | ...itemPermissionAndProps.itemPermission, |
| 122 | isDirty: true |
| 123 | } |
| 124 | }; |
Einav Weiss Keidar | d2f5794 | 2018-02-14 14:00:07 +0200 | [diff] [blame] | 125 | const featureGroupsList = licenseAgreementList[0].featureGroupsIds; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 126 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementAfterAdd]); |
| 127 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 128 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 129 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 130 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 131 | expect(data).toEqual(LicenseAgreementPostRequest); |
| 132 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 133 | return { |
| 134 | value: licenseAgreementIdFromResponse |
| 135 | }; |
| 136 | }); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 137 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 138 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 139 | expect(data).toEqual(undefined); |
| 140 | expect(options).toEqual(undefined); |
| 141 | return {results: licenseAgreementList}; |
| 142 | }); |
| 143 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 144 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); |
| 145 | expect(data).toEqual(undefined); |
| 146 | expect(options).toEqual(undefined); |
| 147 | return {results: featureGroupsList}; |
| 148 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 149 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 150 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 151 | expect(data).toEqual(undefined); |
| 152 | expect(options).toEqual(undefined); |
| 153 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 154 | |
| 155 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 156 | return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, { |
| 157 | licenseAgreement: licenseAgreementToAdd, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | licenseModelId: LICENSE_MODEL_ID, |
| 159 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 160 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 161 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 162 | }); |
| 163 | }); |
| 164 | |
| 165 | it('Update License Agreement', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 166 | const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1, {featureGroupsIds: ['77']}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 167 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 168 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 169 | licenseModel: { |
| 170 | licenseAgreement: { |
| 171 | licenseAgreementList |
| 172 | } |
| 173 | } |
| 174 | }); |
| 175 | deepFreeze(store.getState()); |
| 176 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 177 | const previousLicenseAgreementData = licenseAgreementList[0]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | const toBeUpdatedLicenseAgreementId = previousLicenseAgreementData.id; |
| 179 | const oldFeatureGroupIds = previousLicenseAgreementData.featureGroupsIds; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 180 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 181 | const newFeatureGroupsIds = ['update_id_1', 'update_id_2']; |
| 182 | |
| 183 | const licenseAgreementUpdateData = LicenseAgreementStoreFactory.build({ |
| 184 | id: toBeUpdatedLicenseAgreementId, |
| 185 | featureGroupsIds: newFeatureGroupsIds |
| 186 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 187 | deepFreeze(licenseAgreementUpdateData); |
| 188 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 189 | const LicenseAgreementPutFactoryRequest = LicenseAgreementPutFactory.build({ |
| 190 | addedFeatureGroupsIds: newFeatureGroupsIds, |
| 191 | removedFeatureGroupsIds: oldFeatureGroupIds |
| 192 | }); |
| 193 | |
| 194 | deepFreeze(LicenseAgreementPutFactoryRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 195 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 196 | const expectedCurrentScreenProps = { |
| 197 | ...itemPermissionAndProps, |
| 198 | itemPermission: { |
| 199 | ...itemPermissionAndProps.itemPermission, |
| 200 | isDirty: true |
| 201 | } |
| 202 | }; |
| 203 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementUpdateData]); |
| 204 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 205 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 206 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 207 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeUpdatedLicenseAgreementId}`); |
| 208 | expect(data).toEqual(LicenseAgreementPutFactoryRequest); |
| 209 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 210 | }); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 211 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 212 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 213 | expect(data).toEqual(undefined); |
| 214 | expect(options).toEqual(undefined); |
| 215 | return {results: [licenseAgreementUpdateData]}; |
| 216 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 217 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 218 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 219 | expect(data).toEqual(undefined); |
| 220 | expect(options).toEqual(undefined); |
| 221 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 222 | }); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 223 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 224 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); |
| 225 | expect(data).toEqual(undefined); |
| 226 | expect(options).toEqual(undefined); |
| 227 | return {results: newFeatureGroupsIds}; |
| 228 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 229 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 230 | return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, { |
| 231 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 232 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 233 | previousLicenseAgreement: previousLicenseAgreementData, |
| 234 | licenseAgreement: licenseAgreementUpdateData |
| 235 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 236 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 237 | }); |
| 238 | }); |
| 239 | |
| 240 | }); |