2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import deepFreeze from 'deep-freeze';
17 import mockRest from 'test-utils/MockRest.js';
18 import {storeCreator} from 'sdc-app/AppStore.js';
19 import {cloneAndSet} from 'test-utils/Util.js';
20 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
21 import LicenseModelCreationActionHelper from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationActionHelper.js';
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';
29 describe('License Model Module Tests', function () {
30 it('Add License Model', () => {
31 const store = storeCreator();
32 deepFreeze(store.getState());
34 const licenseModelPostRequest = LicenseModelPostFactory.build();
36 const licenseModelToAdd = LicenseModelDispatchFactory.build();
38 const licenseModelIdFromResponse = 'ADDED_ID';
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);
45 value: licenseModelIdFromResponse
49 return LicenseModelCreationActionHelper.createLicenseModel(store.dispatch, {
50 licenseModel: licenseModelToAdd
51 }).then((response) => {
52 expect(response.value).toEqual(licenseModelIdFromResponse);
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);
62 const store = storeCreator({
63 currentScreen: {...itemPermissionAndProps},
65 licenseModelEditor: {data: licenseModel},
68 deepFreeze(store.getState());
70 const certifiedVersion = {
71 ...itemPermissionAndProps.props.version,
75 const expectedCurrentScreenProps = {
77 ...itemPermissionAndProps.itemPermission,
82 version: certifiedVersion
85 const expectedSuccessModal = {
86 cancelButtonText: 'OK',
87 modalClassName: 'notification-modal',
88 msg: 'This license model successfully submitted',
90 title: 'Submit Succeeded',
94 const versionsList = {
95 itemType: itemTypes.LICENSE_MODEL,
96 itemId: licenseModel.id,
97 versions: [{...certifiedVersion}]
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 );
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'};
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'};
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}};
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}]};
134 return LicenseModelActionHelper.performSubmitAction(store.dispatch, {
135 licenseModelId: licenseModel.id,
138 expect(store.getState()).toEqual(expectedStore);