blob: bbebcaf079b47d484b6be363539822418603ed9b [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',
99 modalClassName: 'notification-modal',
100 msg: 'This license model successfully submitted',
101 timeout: 2000,
102 title: 'Submit Succeeded',
103 type: 'success'
104 };
talig8e9c0652017-12-20 14:30:43 +0200105
svishnev57c5c4a2018-04-22 14:14:31 +0300106 const versionsList = {
107 itemType: itemTypes.LICENSE_MODEL,
108 itemId: licenseModel.id,
109 versions: [{ ...certifiedVersion }]
110 };
talig8e9c0652017-12-20 14:30:43 +0200111
svishnev57c5c4a2018-04-22 14:14:31 +0300112 let expectedStore = store.getState();
113 expectedStore = cloneAndSet(
114 expectedStore,
115 'currentScreen.itemPermission',
116 expectedCurrentScreenProps.itemPermission
117 );
118 expectedStore = cloneAndSet(
119 expectedStore,
120 'currentScreen.props',
121 expectedCurrentScreenProps.props
122 );
123 expectedStore = cloneAndSet(
124 expectedStore,
125 'modal',
126 expectedSuccessModal
127 );
128 expectedStore = cloneAndSet(
129 expectedStore,
130 'versionsPage.versionsList',
131 versionsList
132 );
talig8e9c0652017-12-20 14:30:43 +0200133
svishnev57c5c4a2018-04-22 14:14:31 +0300134 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
135 expect(baseUrl).toEqual(
136 `/onboarding-api/v1.0/vendor-license-models/${
137 licenseModel.id
138 }/versions/${version.id}/actions`
139 );
140 expect(data).toEqual({
141 action: VersionControllerActionsEnum.SUBMIT
142 });
143 expect(options).toEqual(undefined);
144 return { returnCode: 'OK' };
145 });
talig8e9c0652017-12-20 14:30:43 +0200146
svishnev57c5c4a2018-04-22 14:14:31 +0300147 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
148 expect(baseUrl).toEqual(
149 `/onboarding-api/v1.0/vendor-license-models/${
150 licenseModel.id
151 }/versions/${version.id}/actions`
152 );
153 expect(data).toEqual({
154 action: VersionControllerActionsEnum.CREATE_PACKAGE
155 });
156 expect(options).toEqual(undefined);
157 return { returnCode: 'OK' };
158 });
talig8e9c0652017-12-20 14:30:43 +0200159
svishnev57c5c4a2018-04-22 14:14:31 +0300160 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
161 expect(baseUrl).toEqual(
162 `/onboarding-api/v1.0/items/${licenseModel.id}/versions/${
163 version.id
164 }`
165 );
166 expect(data).toEqual(undefined);
167 expect(options).toEqual(undefined);
168 return {
169 ...certifiedVersion,
170 state: {
171 synchronizationState: SyncStates.UP_TO_DATE,
172 dirty: false
173 }
174 };
175 });
talig8e9c0652017-12-20 14:30:43 +0200176
svishnev57c5c4a2018-04-22 14:14:31 +0300177 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
178 expect(baseUrl).toEqual(
179 `/onboarding-api/v1.0/items/${licenseModel.id}`
180 );
181 expect(data).toEqual(undefined);
182 expect(options).toEqual(undefined);
183 return { ...certifiedVersion };
184 });
185
186 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
187 expect(baseUrl).toEqual(
188 `/onboarding-api/v1.0/items/${licenseModel.id}/versions`
189 );
190 expect(data).toEqual(undefined);
191 expect(options).toEqual(undefined);
192 return { results: [{ ...certifiedVersion }] };
193 });
194
195 return LicenseModelActionHelper.performSubmitAction(store.dispatch, {
196 licenseModelId: licenseModel.id,
197 version
198 }).then(() => {
199 expect(store.getState()).toEqual(expectedStore);
200 });
201 });
Michael Landoefa037d2017-02-19 12:57:33 +0200202});