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'; |
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'; |
| 24 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 25 | |
| 26 | describe('License Agreement Module Tests', () => { |
| 27 | |
| 28 | const LICENSE_MODEL_ID = '777'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 29 | const version = VersionControllerUtilsFactory.build().version; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | |
| 31 | it('Load License Agreement List', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 32 | const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory); |
| 33 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | const store = storeCreator(); |
| 35 | deepFreeze(store.getState()); |
| 36 | |
| 37 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', licenseAgreementList); |
| 38 | |
| 39 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 40 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 41 | expect(data).toEqual(undefined); |
| 42 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | return {results: licenseAgreementList}; |
| 44 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | return LicenseAgreementActionHelper.fetchLicenseAgreementList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 46 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 47 | }); |
| 48 | }); |
| 49 | |
| 50 | it('Delete License Agreement', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 52 | const store = storeCreator({ |
| 53 | licenseModel: { |
| 54 | licenseAgreement: { |
| 55 | licenseAgreementList |
| 56 | } |
| 57 | } |
| 58 | }); |
| 59 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 60 | const toBeDeletedLicenseAgreementId = licenseAgreementList[0].id; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 61 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', []); |
| 62 | |
| 63 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 64 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeDeletedLicenseAgreementId}`); |
| 65 | expect(data).toEqual(undefined); |
| 66 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 67 | }); |
| 68 | |
| 69 | return LicenseAgreementActionHelper.deleteLicenseAgreement(store.dispatch, { |
| 70 | licenseAgreementId: toBeDeletedLicenseAgreementId, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 71 | licenseModelId: LICENSE_MODEL_ID, |
| 72 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 73 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 74 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 75 | }); |
| 76 | }); |
| 77 | |
| 78 | it('Add License Agreement', () => { |
| 79 | const store = storeCreator(); |
| 80 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | const licenseAgreementToAdd = LicenseAgreementDispatchFactory.build(); |
| 83 | |
| 84 | const LicenseAgreementPostRequest = LicenseAgreementPostFactory.build( |
| 85 | pickBy(licenseAgreementToAdd, (val, key) => key !== 'featureGroupsIds') |
| 86 | ); |
| 87 | |
| 88 | deepFreeze(LicenseAgreementPostRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 89 | |
| 90 | const licenseAgreementIdFromResponse = 'ADDED_ID'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | const licenseAgreementAfterAdd = LicenseAgreementStoreFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | ...licenseAgreementToAdd, |
| 93 | id: licenseAgreementIdFromResponse |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 94 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 95 | deepFreeze(licenseAgreementAfterAdd); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 96 | const licenseAgreementList = [licenseAgreementAfterAdd]; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 97 | |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 98 | const featureGroupsList = licenseAgreementList.featureGroupsIds; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 99 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementAfterAdd]); |
| 100 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 101 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 102 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 103 | expect(data).toEqual(LicenseAgreementPostRequest); |
| 104 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 105 | return { |
| 106 | value: licenseAgreementIdFromResponse |
| 107 | }; |
| 108 | }); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 109 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 110 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 111 | expect(data).toEqual(undefined); |
| 112 | expect(options).toEqual(undefined); |
| 113 | return {results: licenseAgreementList}; |
| 114 | }); |
| 115 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 116 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); |
| 117 | expect(data).toEqual(undefined); |
| 118 | expect(options).toEqual(undefined); |
| 119 | return {results: featureGroupsList}; |
| 120 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 121 | return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, { |
| 122 | licenseAgreement: licenseAgreementToAdd, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 123 | licenseModelId: LICENSE_MODEL_ID, |
| 124 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 125 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 126 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 127 | }); |
| 128 | }); |
| 129 | |
| 130 | it('Update License Agreement', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1, {featureGroupsIds: ['77']}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 132 | const store = storeCreator({ |
| 133 | licenseModel: { |
| 134 | licenseAgreement: { |
| 135 | licenseAgreementList |
| 136 | } |
| 137 | } |
| 138 | }); |
| 139 | deepFreeze(store.getState()); |
| 140 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 141 | const previousLicenseAgreementData = licenseAgreementList[0]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 142 | const toBeUpdatedLicenseAgreementId = previousLicenseAgreementData.id; |
| 143 | const oldFeatureGroupIds = previousLicenseAgreementData.featureGroupsIds; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 144 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | const newFeatureGroupsIds = ['update_id_1', 'update_id_2']; |
| 146 | |
| 147 | const licenseAgreementUpdateData = LicenseAgreementStoreFactory.build({ |
| 148 | id: toBeUpdatedLicenseAgreementId, |
| 149 | featureGroupsIds: newFeatureGroupsIds |
| 150 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 151 | deepFreeze(licenseAgreementUpdateData); |
| 152 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 153 | const LicenseAgreementPutFactoryRequest = LicenseAgreementPutFactory.build({ |
| 154 | addedFeatureGroupsIds: newFeatureGroupsIds, |
| 155 | removedFeatureGroupsIds: oldFeatureGroupIds |
| 156 | }); |
| 157 | |
| 158 | deepFreeze(LicenseAgreementPutFactoryRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 159 | |
| 160 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementUpdateData]); |
| 161 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 162 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 163 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeUpdatedLicenseAgreementId}`); |
| 164 | expect(data).toEqual(LicenseAgreementPutFactoryRequest); |
| 165 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 166 | }); |
ilanap | cb1d483 | 2017-09-27 11:41:19 +0300 | [diff] [blame] | 167 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 168 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`); |
| 169 | expect(data).toEqual(undefined); |
| 170 | expect(options).toEqual(undefined); |
| 171 | return {results: [licenseAgreementUpdateData]}; |
| 172 | }); |
| 173 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 174 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`); |
| 175 | expect(data).toEqual(undefined); |
| 176 | expect(options).toEqual(undefined); |
| 177 | return {results: newFeatureGroupsIds}; |
| 178 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 179 | return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, { |
| 180 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 181 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 182 | previousLicenseAgreement: previousLicenseAgreementData, |
| 183 | licenseAgreement: licenseAgreementUpdateData |
| 184 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 185 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 186 | }); |
| 187 | }); |
| 188 | |
| 189 | }); |