blob: 6cb2168cbb95337b4c966610c6f75bab26a1c979 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
17import mockRest from 'test-utils/MockRest.js';
Michael Landoefa037d2017-02-19 12:57:33 +020018import {storeCreator} from 'sdc-app/AppStore.js';
talig8e9c0652017-12-20 14:30:43 +020019import {cloneAndSet} from 'test-utils/Util.js';
20import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
Michael Landoefa037d2017-02-19 12:57:33 +020021import LicenseModelCreationActionHelper from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020022import {LicenseModelPostFactory, LicenseModelDispatchFactory, LicenseModelStoreFactory} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
23import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
24import {default as CurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js';
25import {actionsEnum as VersionControllerActionsEnum} from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
26import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
27import {itemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
AviZi280f8012017-06-09 02:39:56 +030028
Michael Landoefa037d2017-02-19 12:57:33 +020029describe('License Model Module Tests', function () {
30 it('Add License Model', () => {
31 const store = storeCreator();
32 deepFreeze(store.getState());
33
AviZi280f8012017-06-09 02:39:56 +030034 const licenseModelPostRequest = LicenseModelPostFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020035
AviZi280f8012017-06-09 02:39:56 +030036 const licenseModelToAdd = LicenseModelDispatchFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020037
38 const licenseModelIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +030039
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 Landoefa037d2017-02-19 12:57:33 +020044 return {
45 value: licenseModelIdFromResponse
46 };
47 });
48
49 return LicenseModelCreationActionHelper.createLicenseModel(store.dispatch, {
50 licenseModel: licenseModelToAdd
AviZi280f8012017-06-09 02:39:56 +030051 }).then((response) => {
52 expect(response.value).toEqual(licenseModelIdFromResponse);
Michael Landoefa037d2017-02-19 12:57:33 +020053 });
54 });
talig8e9c0652017-12-20 14:30:43 +020055
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 Landoefa037d2017-02-19 12:57:33 +0200141});