blob: 489b9829b55645e7756306b440992f0da407f952 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
svishnev57c5c4a2018-04-22 14:14:31 +03002 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
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.
15 */
16
17import deepFreeze from 'deep-freeze';
18import mockRest from 'test-utils/MockRest.js';
svishnev57c5c4a2018-04-22 14:14:31 +030019import { cloneAndSet } from 'test-utils/Util.js';
20import { storeCreator } from 'sdc-app/AppStore.js';
talig8e9c0652017-12-20 14:30:43 +020021
22import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
svishnev57c5c4a2018-04-22 14:14:31 +030023import { VSPEditorFactoryWithLicensingData } from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
talig8e9c0652017-12-20 14:30:43 +020024import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
svishnev57c5c4a2018-04-22 14:14:31 +030025import { default as CurrentScreenFactory } from 'test-utils/factories/common/CurrentScreenFactory.js';
26import { actionsEnum as VersionControllerActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
27import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
28import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
talig8e9c0652017-12-20 14:30:43 +020029
svishnev57c5c4a2018-04-22 14:14:31 +030030describe('Software Product Module Tests', function() {
31 it('Validating readonly screen after submit', () => {
32 const version = VersionFactory.build({}, { isCertified: false });
33 const itemPermissionAndProps = CurrentScreenFactory.build(
34 {},
35 { version }
36 );
37 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
38 deepFreeze(softwareProduct);
talig8e9c0652017-12-20 14:30:43 +020039
svishnev57c5c4a2018-04-22 14:14:31 +030040 const store = storeCreator({
41 currentScreen: { ...itemPermissionAndProps },
42 softwareProduct: {
43 softwareProductEditor: { data: softwareProduct },
44 softwareProductQuestionnaire: {
45 qdata: 'test',
46 qschema: { type: 'string' }
47 }
48 }
49 });
50 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +020051
svishnev57c5c4a2018-04-22 14:14:31 +030052 const certifiedVersion = {
53 ...itemPermissionAndProps.props.version,
54 status: 'Certified'
55 };
talig8e9c0652017-12-20 14:30:43 +020056
svishnev57c5c4a2018-04-22 14:14:31 +030057 const versionsList = {
58 itemType: itemTypes.SOFTWARE_PRODUCT,
59 itemId: softwareProduct.id,
60 versions: [{ ...certifiedVersion }]
61 };
62 const expectedCurrentScreenProps = {
63 itemPermission: {
64 ...itemPermissionAndProps.itemPermission,
65 isCertified: true
66 },
67 props: {
68 isReadOnlyMode: true,
69 version: certifiedVersion
70 }
71 };
72 const expectedSuccessModal = {
73 cancelButtonText: 'OK',
svishnev57c5c4a2018-04-22 14:14:31 +030074 msg: 'This software product successfully submitted',
75 timeout: 2000,
76 title: 'Submit Succeeded',
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030077 type: 'info'
svishnev57c5c4a2018-04-22 14:14:31 +030078 };
talig8e9c0652017-12-20 14:30:43 +020079
svishnev57c5c4a2018-04-22 14:14:31 +030080 let expectedStore = store.getState();
81 expectedStore = cloneAndSet(
82 expectedStore,
83 'currentScreen.itemPermission',
84 expectedCurrentScreenProps.itemPermission
85 );
86 expectedStore = cloneAndSet(
87 expectedStore,
88 'currentScreen.props',
89 expectedCurrentScreenProps.props
90 );
91 expectedStore = cloneAndSet(
92 expectedStore,
93 'modal',
94 expectedSuccessModal
95 );
96 expectedStore = cloneAndSet(
97 expectedStore,
98 'versionsPage.versionsList',
99 versionsList
100 );
talig8e9c0652017-12-20 14:30:43 +0200101
svishnev57c5c4a2018-04-22 14:14:31 +0300102 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
103 expect(baseUrl).toEqual(
104 `/onboarding-api/v1.0/vendor-software-products/${
105 softwareProduct.id
106 }/versions/${version.id}/actions`
107 );
108 expect(data).toEqual({
109 action: VersionControllerActionsEnum.SUBMIT
110 });
111 expect(options).toEqual(undefined);
112 return { returnCode: 'OK' };
113 });
talig8e9c0652017-12-20 14:30:43 +0200114
svishnev57c5c4a2018-04-22 14:14:31 +0300115 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
116 expect(baseUrl).toEqual(
117 `/onboarding-api/v1.0/vendor-software-products/${
118 softwareProduct.id
119 }/versions/${version.id}/actions`
120 );
121 expect(data).toEqual({
122 action: VersionControllerActionsEnum.CREATE_PACKAGE
123 });
124 expect(options).toEqual(undefined);
125 return { returnCode: 'OK' };
126 });
talig8e9c0652017-12-20 14:30:43 +0200127
svishnev57c5c4a2018-04-22 14:14:31 +0300128 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
129 expect(baseUrl).toEqual(
130 `/onboarding-api/v1.0/items/${softwareProduct.id}/versions/${
131 version.id
132 }`
133 );
134 expect(data).toEqual(undefined);
135 expect(options).toEqual(undefined);
136 return {
137 ...certifiedVersion,
138 state: {
139 synchronizationState: SyncStates.UP_TO_DATE,
140 dirty: false
141 }
142 };
143 });
talig8e9c0652017-12-20 14:30:43 +0200144
svishnev57c5c4a2018-04-22 14:14:31 +0300145 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
146 expect(baseUrl).toEqual(
147 `/onboarding-api/v1.0/items/${softwareProduct.id}`
148 );
149 expect(data).toEqual(undefined);
150 expect(options).toEqual(undefined);
151 return { ...certifiedVersion };
152 });
talig8e9c0652017-12-20 14:30:43 +0200153
svishnev57c5c4a2018-04-22 14:14:31 +0300154 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
155 expect(baseUrl).toEqual(
156 `/onboarding-api/v1.0/items/${softwareProduct.id}/versions`
157 );
158 expect(data).toEqual(undefined);
159 expect(options).toEqual(undefined);
160 return { results: [{ ...certifiedVersion }] };
161 });
162
163 return SoftwareProductActionHelper.performSubmitAction(store.dispatch, {
164 softwareProductId: softwareProduct.id,
165 version
166 }).then(() => {
167 expect(store.getState()).toEqual(expectedStore);
168 });
169 });
170});