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 { storeCreator } from 'sdc-app/AppStore.js'; |
| 19 | import { cloneAndSet } from 'test-utils/Util.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 20 | import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 21 | import LicenseModelCreationActionHelper from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationActionHelper.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 22 | import { |
| 23 | LicenseModelPostFactory, |
| 24 | LicenseModelDispatchFactory, |
| 25 | LicenseModelStoreFactory |
| 26 | } from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 27 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 28 | import { default as CurrentScreenFactory } from 'test-utils/factories/common/CurrentScreenFactory.js'; |
| 29 | import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; |
| 30 | import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js'; |
| 31 | import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 32 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 33 | describe('License Model Module Tests', function() { |
| 34 | it('Add License Model', () => { |
| 35 | const store = storeCreator(); |
| 36 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 38 | const licenseModelPostRequest = LicenseModelPostFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 40 | const licenseModelToAdd = LicenseModelDispatchFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 41 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 42 | const licenseModelIdFromResponse = 'ADDED_ID'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 44 | mockRest.addHandler('post', ({ options, data, baseUrl }) => { |
| 45 | expect(baseUrl).toEqual( |
| 46 | '/onboarding-api/v1.0/vendor-license-models/' |
| 47 | ); |
| 48 | expect(data).toEqual(licenseModelPostRequest); |
| 49 | expect(options).toEqual(undefined); |
| 50 | return { |
| 51 | value: licenseModelIdFromResponse |
| 52 | }; |
| 53 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 54 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 55 | return LicenseModelCreationActionHelper.createLicenseModel( |
| 56 | store.dispatch, |
| 57 | { |
| 58 | licenseModel: licenseModelToAdd |
| 59 | } |
| 60 | ).then(response => { |
| 61 | expect(response.value).toEqual(licenseModelIdFromResponse); |
| 62 | }); |
| 63 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 64 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 65 | it('Validating readonly screen after submit', () => { |
| 66 | const version = VersionFactory.build({}, { isCertified: false }); |
| 67 | const itemPermissionAndProps = CurrentScreenFactory.build( |
| 68 | {}, |
| 69 | { version } |
| 70 | ); |
| 71 | const licenseModel = LicenseModelStoreFactory.build(); |
| 72 | deepFreeze(licenseModel); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 73 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 74 | const store = storeCreator({ |
| 75 | currentScreen: { ...itemPermissionAndProps }, |
| 76 | licenseModel: { |
| 77 | licenseModelEditor: { data: licenseModel } |
| 78 | } |
| 79 | }); |
| 80 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 81 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 82 | const certifiedVersion = { |
| 83 | ...itemPermissionAndProps.props.version, |
| 84 | status: 'Certified' |
| 85 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 86 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 87 | const expectedCurrentScreenProps = { |
| 88 | itemPermission: { |
| 89 | ...itemPermissionAndProps.itemPermission, |
| 90 | isCertified: true |
| 91 | }, |
| 92 | props: { |
| 93 | isReadOnlyMode: true, |
| 94 | version: certifiedVersion |
| 95 | } |
| 96 | }; |
| 97 | const expectedSuccessModal = { |
| 98 | cancelButtonText: 'OK', |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 99 | msg: 'This license model successfully submitted', |
| 100 | timeout: 2000, |
| 101 | title: 'Submit Succeeded', |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 102 | type: 'info' |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 103 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 104 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 105 | const versionsList = { |
| 106 | itemType: itemTypes.LICENSE_MODEL, |
| 107 | itemId: licenseModel.id, |
| 108 | versions: [{ ...certifiedVersion }] |
| 109 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 110 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 111 | let expectedStore = store.getState(); |
| 112 | expectedStore = cloneAndSet( |
| 113 | expectedStore, |
| 114 | 'currentScreen.itemPermission', |
| 115 | expectedCurrentScreenProps.itemPermission |
| 116 | ); |
| 117 | expectedStore = cloneAndSet( |
| 118 | expectedStore, |
| 119 | 'currentScreen.props', |
| 120 | expectedCurrentScreenProps.props |
| 121 | ); |
| 122 | expectedStore = cloneAndSet( |
| 123 | expectedStore, |
| 124 | 'modal', |
| 125 | expectedSuccessModal |
| 126 | ); |
| 127 | expectedStore = cloneAndSet( |
| 128 | expectedStore, |
| 129 | 'versionsPage.versionsList', |
| 130 | versionsList |
| 131 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 132 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 133 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 134 | expect(baseUrl).toEqual( |
| 135 | `/onboarding-api/v1.0/vendor-license-models/${ |
| 136 | licenseModel.id |
| 137 | }/versions/${version.id}/actions` |
| 138 | ); |
| 139 | expect(data).toEqual({ |
| 140 | action: VersionControllerActionsEnum.SUBMIT |
| 141 | }); |
| 142 | expect(options).toEqual(undefined); |
| 143 | return { returnCode: 'OK' }; |
| 144 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 145 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 146 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 147 | expect(baseUrl).toEqual( |
| 148 | `/onboarding-api/v1.0/vendor-license-models/${ |
| 149 | licenseModel.id |
| 150 | }/versions/${version.id}/actions` |
| 151 | ); |
| 152 | expect(data).toEqual({ |
| 153 | action: VersionControllerActionsEnum.CREATE_PACKAGE |
| 154 | }); |
| 155 | expect(options).toEqual(undefined); |
| 156 | return { returnCode: 'OK' }; |
| 157 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 158 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 159 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 160 | expect(baseUrl).toEqual( |
| 161 | `/onboarding-api/v1.0/items/${licenseModel.id}/versions/${ |
| 162 | version.id |
| 163 | }` |
| 164 | ); |
| 165 | expect(data).toEqual(undefined); |
| 166 | expect(options).toEqual(undefined); |
| 167 | return { |
| 168 | ...certifiedVersion, |
| 169 | state: { |
| 170 | synchronizationState: SyncStates.UP_TO_DATE, |
| 171 | dirty: false |
| 172 | } |
| 173 | }; |
| 174 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 175 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 176 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 177 | expect(baseUrl).toEqual( |
| 178 | `/onboarding-api/v1.0/items/${licenseModel.id}` |
| 179 | ); |
| 180 | expect(data).toEqual(undefined); |
| 181 | expect(options).toEqual(undefined); |
| 182 | return { ...certifiedVersion }; |
| 183 | }); |
| 184 | |
| 185 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 186 | expect(baseUrl).toEqual( |
| 187 | `/onboarding-api/v1.0/items/${licenseModel.id}/versions` |
| 188 | ); |
| 189 | expect(data).toEqual(undefined); |
| 190 | expect(options).toEqual(undefined); |
| 191 | return { results: [{ ...certifiedVersion }] }; |
| 192 | }); |
| 193 | |
| 194 | return LicenseModelActionHelper.performSubmitAction(store.dispatch, { |
| 195 | licenseModelId: licenseModel.id, |
| 196 | version |
| 197 | }).then(() => { |
| 198 | expect(store.getState()).toEqual(expectedStore); |
| 199 | }); |
| 200 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 201 | }); |