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'; |
| 17 | import mockRest from 'test-utils/MockRest.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import {storeCreator} from 'sdc-app/AppStore.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 19 | import {cloneAndSet} from 'test-utils/Util.js'; |
| 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'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import {LicenseModelPostFactory, LicenseModelDispatchFactory, LicenseModelStoreFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js'; |
| 23 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 24 | import {default as CurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js'; |
| 25 | import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js'; |
| 26 | import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js'; |
| 27 | import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | describe('License Model Module Tests', function () { |
| 30 | it('Add License Model', () => { |
| 31 | const store = storeCreator(); |
| 32 | deepFreeze(store.getState()); |
| 33 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | const licenseModelPostRequest = LicenseModelPostFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | const licenseModelToAdd = LicenseModelDispatchFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | |
| 38 | const licenseModelIdFromResponse = 'ADDED_ID'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 39 | |
| 40 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 41 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/'); |
| 42 | expect(data).toEqual(licenseModelPostRequest); |
| 43 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | return { |
| 45 | value: licenseModelIdFromResponse |
| 46 | }; |
| 47 | }); |
| 48 | |
| 49 | return LicenseModelCreationActionHelper.createLicenseModel(store.dispatch, { |
| 50 | licenseModel: licenseModelToAdd |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | }).then((response) => { |
| 52 | expect(response.value).toEqual(licenseModelIdFromResponse); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 53 | }); |
| 54 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 55 | |
| 56 | it('Validating readonly screen after submit', () => { |
| 57 | const version = VersionFactory.build({}, {isCertified: false}); |
| 58 | const itemPermissionAndProps = CurrentScreenFactory.build({}, {version}); |
| 59 | const licenseModel = LicenseModelStoreFactory.build(); |
| 60 | deepFreeze(licenseModel); |
| 61 | |
| 62 | const store = storeCreator({ |
| 63 | currentScreen: {...itemPermissionAndProps}, |
| 64 | licenseModel: { |
| 65 | licenseModelEditor: {data: licenseModel}, |
| 66 | } |
| 67 | }); |
| 68 | deepFreeze(store.getState()); |
| 69 | |
| 70 | const certifiedVersion = { |
| 71 | ...itemPermissionAndProps.props.version, |
| 72 | status: 'Certified' |
| 73 | }; |
| 74 | |
| 75 | const expectedCurrentScreenProps = { |
| 76 | itemPermission: { |
| 77 | ...itemPermissionAndProps.itemPermission, |
| 78 | isCertified: true |
| 79 | }, |
| 80 | props: { |
| 81 | isReadOnlyMode: true, |
| 82 | version: certifiedVersion |
| 83 | } |
| 84 | }; |
| 85 | const expectedSuccessModal = { |
| 86 | cancelButtonText: 'OK', |
| 87 | modalClassName: 'notification-modal', |
| 88 | msg: 'This license model successfully submitted', |
| 89 | timeout: 2000, |
| 90 | title: 'Submit Succeeded', |
| 91 | type: 'success' |
| 92 | }; |
| 93 | |
| 94 | const versionsList = { |
| 95 | itemType: itemTypes.LICENSE_MODEL, |
| 96 | itemId: licenseModel.id, |
| 97 | versions: [{...certifiedVersion}] |
| 98 | }; |
| 99 | |
| 100 | let expectedStore = store.getState(); |
| 101 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
| 102 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreenProps.props); |
| 103 | expectedStore = cloneAndSet(expectedStore, 'modal', expectedSuccessModal); |
| 104 | expectedStore = cloneAndSet(expectedStore, 'versionsPage.versionsList', versionsList ); |
| 105 | |
| 106 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 107 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModel.id}/versions/${version.id}/actions`); |
| 108 | expect(data).toEqual({action: VersionControllerActionsEnum.SUBMIT}); |
| 109 | expect(options).toEqual(undefined); |
| 110 | return {returnCode: 'OK'}; |
| 111 | }); |
| 112 | |
| 113 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 114 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModel.id}/versions/${version.id}/actions`); |
| 115 | expect(data).toEqual({action: VersionControllerActionsEnum.CREATE_PACKAGE}); |
| 116 | expect(options).toEqual(undefined); |
| 117 | return {returnCode: 'OK'}; |
| 118 | }); |
| 119 | |
| 120 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 121 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModel.id}/versions/${version.id}`); |
| 122 | expect(data).toEqual(undefined); |
| 123 | expect(options).toEqual(undefined); |
| 124 | return {...certifiedVersion, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: false}}; |
| 125 | }); |
| 126 | |
| 127 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 128 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModel.id}/versions`); |
| 129 | expect(data).toEqual(undefined); |
| 130 | expect(options).toEqual(undefined); |
| 131 | return {results: [{...certifiedVersion}]}; |
| 132 | }); |
| 133 | |
| 134 | return LicenseModelActionHelper.performSubmitAction(store.dispatch, { |
| 135 | licenseModelId: licenseModel.id, |
| 136 | version |
| 137 | }).then(() => { |
| 138 | expect(store.getState()).toEqual(expectedStore); |
| 139 | }); |
| 140 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 141 | }); |