blob: 0d72d5d36916da1ed31bfd9be12c6be2caaf909d [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
svishnev57c5c4a2018-04-22 14:14:31 +03002 * Copyright © 2016-2018 European Support Limited
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';
svishnev57c5c4a2018-04-22 14:14:31 +030018import { storeCreator } from 'sdc-app/AppStore.js';
19import { cloneAndSet } from 'test-utils/Util.js';
talig8e9c0652017-12-20 14:30:43 +020020import 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';
svishnev57c5c4a2018-04-22 14:14:31 +030022import {
23 LicenseModelPostFactory,
24 LicenseModelDispatchFactory,
25 LicenseModelStoreFactory
26} from 'test-utils/factories/licenseModel/LicenseModelFactories.js';
talig8e9c0652017-12-20 14:30:43 +020027import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
svishnev57c5c4a2018-04-22 14:14:31 +030028import { default as CurrentScreenFactory } from 'test-utils/factories/common/CurrentScreenFactory.js';
29import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
30import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
31import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
AviZi280f8012017-06-09 02:39:56 +030032
svishnev57c5c4a2018-04-22 14:14:31 +030033describe('License Model Module Tests', function() {
34 it('Add License Model', () => {
35 const store = storeCreator();
36 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020037
svishnev57c5c4a2018-04-22 14:14:31 +030038 const licenseModelPostRequest = LicenseModelPostFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020039
svishnev57c5c4a2018-04-22 14:14:31 +030040 const licenseModelToAdd = LicenseModelDispatchFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020041
svishnev57c5c4a2018-04-22 14:14:31 +030042 const licenseModelIdFromResponse = 'ADDED_ID';
Michael Landoefa037d2017-02-19 12:57:33 +020043
svishnev57c5c4a2018-04-22 14:14:31 +030044 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 });
talig8e9c0652017-12-20 14:30:43 +020054
svishnev57c5c4a2018-04-22 14:14:31 +030055 return LicenseModelCreationActionHelper.createLicenseModel(
56 store.dispatch,
57 {
58 licenseModel: licenseModelToAdd
59 }
60 ).then(response => {
61 expect(response.value).toEqual(licenseModelIdFromResponse);
62 });
63 });
talig8e9c0652017-12-20 14:30:43 +020064
svishnev57c5c4a2018-04-22 14:14:31 +030065 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);
talig8e9c0652017-12-20 14:30:43 +020073
svishnev57c5c4a2018-04-22 14:14:31 +030074 const store = storeCreator({
75 currentScreen: { ...itemPermissionAndProps },
76 licenseModel: {
77 licenseModelEditor: { data: licenseModel }
78 }
79 });
80 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +020081
svishnev57c5c4a2018-04-22 14:14:31 +030082 const certifiedVersion = {
83 ...itemPermissionAndProps.props.version,
84 status: 'Certified'
85 };
talig8e9c0652017-12-20 14:30:43 +020086
svishnev57c5c4a2018-04-22 14:14:31 +030087 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',
svishnev57c5c4a2018-04-22 14:14:31 +030099 msg: 'This license model successfully submitted',
100 timeout: 2000,
101 title: 'Submit Succeeded',
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300102 type: 'info'
svishnev57c5c4a2018-04-22 14:14:31 +0300103 };
talig8e9c0652017-12-20 14:30:43 +0200104
svishnev57c5c4a2018-04-22 14:14:31 +0300105 const versionsList = {
106 itemType: itemTypes.LICENSE_MODEL,
107 itemId: licenseModel.id,
108 versions: [{ ...certifiedVersion }]
109 };
talig8e9c0652017-12-20 14:30:43 +0200110
svishnev57c5c4a2018-04-22 14:14:31 +0300111 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 );
talig8e9c0652017-12-20 14:30:43 +0200132
svishnev57c5c4a2018-04-22 14:14:31 +0300133 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 });
talig8e9c0652017-12-20 14:30:43 +0200145
svishnev57c5c4a2018-04-22 14:14:31 +0300146 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 });
talig8e9c0652017-12-20 14:30:43 +0200158
svishnev57c5c4a2018-04-22 14:14:31 +0300159 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 });
talig8e9c0652017-12-20 14:30:43 +0200175
svishnev57c5c4a2018-04-22 14:14:31 +0300176 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 Landoefa037d2017-02-19 12:57:33 +0200201});