2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import {expect} from 'chai';
22 import deepFreeze from 'deep-freeze';
23 import mockRest from 'test-utils/MockRest.js';
24 import {cloneAndSet} from 'test-utils/Util.js';
25 import {storeCreator} from 'sdc-app/AppStore.js';
27 import SoftwareProductCreationActionHelper from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationActionHelper.js';
28 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
29 import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js';
31 describe('Software Product Module Tests', function () {
32 it('Get Software Products List', () => {
33 const store = storeCreator();
34 deepFreeze(store.getState());
36 const softwareProductList = [
41 id: 'EBADF561B7FA4A788075E1840D0B5971',
42 subCategory: 'resourceNewCategory.network connectivity.virtual links',
43 category: 'resourceNewCategory.network connectivity',
44 vendorId: '5259EDE4CC814DC9897BA6F69E2C971B',
46 checkinStatus: 'CHECK_OUT',
53 description: 'dfdfdfd',
55 id: '2F47447D22DB4C53B020CA1E66201EF2',
56 subCategory: 'resourceNewCategory.network connectivity.virtual links',
57 category: 'resourceNewCategory.network connectivity',
58 vendorId: '5259EDE4CC814DC9897BA6F69E2C971B',
60 checkinStatus: 'CHECK_OUT',
67 deepFreeze(softwareProductList);
69 deepFreeze(store.getState());
71 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList);
73 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
74 expect(baseUrl).to.equal('/onboarding-api/v1.0/vendor-software-products/');
75 expect(data).to.deep.equal(undefined);
76 expect(options).to.equal(undefined);
77 return {results: softwareProductList};
80 return SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch).then(() => {
81 expect(store.getState()).to.deep.equal(expectedStore);
85 it('Add Software Product', () => {
86 const store = storeCreator();
87 deepFreeze(store.getState());
89 const softwareProductPostRequest = deepFreeze({
91 description: 'string',
95 subCategory: 'resourceNewCategory.network connectivity.virtual links',
96 category: 'resourceNewCategory.network connectivity',
100 const softwareProductToAdd = deepFreeze({
101 ...softwareProductPostRequest
104 const softwareProductIdFromResponse = 'ADDED_ID';
105 const softwareProductAfterAdd = deepFreeze({
106 ...softwareProductToAdd,
107 id: softwareProductIdFromResponse
110 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductAfterAdd]);
112 mockRest.addHandler('create', ({options, data, baseUrl}) => {
113 expect(baseUrl).to.equal('/onboarding-api/v1.0/vendor-software-products/');
114 expect(data).to.deep.equal(softwareProductPostRequest);
115 expect(options).to.equal(undefined);
117 vspId: softwareProductIdFromResponse
121 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
122 softwareProduct: softwareProductToAdd
124 expect(store.getState()).to.deep.equal(expectedStore);
127 it('Save Software product', () => {
128 const softwareProduct = {
130 id: '4730033D16C64E3CA556AB0AC4478218',
131 description: 'A software model for Fortigate.',
132 subCategory: 'resourceNewCategory.network connectivity.virtual links',
133 category: 'resourceNewCategory.network connectivity',
135 vendorName: 'Vendor',
136 licensingVersion: '1.0',
139 licenceAgreement: '123',
145 deepFreeze(softwareProduct);
147 const store = storeCreator({
149 softwareProductEditor: {data: softwareProduct},
150 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
153 deepFreeze(store.getState());
155 const toBeUpdatedSoftwareProductId = softwareProduct.id;
156 const softwareProductUpdateData = {
158 name: 'VSP5_UPDATED',
159 description: 'A software model for Fortigate._UPDATED'
161 deepFreeze(softwareProductUpdateData);
163 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductUpdateData]);
164 const questionnaireData = {
167 affinityGrouping: true,
168 antiAffinityGrouping: false
172 deepFreeze(questionnaireData);
174 mockRest.addHandler('save', ({data, options, baseUrl}) => {
175 const expectedData = {
176 name: 'VSP5_UPDATED',
177 description: 'A software model for Fortigate._UPDATED',
178 subCategory: 'resourceNewCategory.network connectivity.virtual links',
179 category: 'resourceNewCategory.network connectivity',
181 vendorName: 'Vendor',
182 licensingVersion: '1.0',
185 licenceAgreement: '123',
191 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}`);
192 expect(data).to.deep.equal(expectedData);
193 expect(options).to.equal(undefined);
194 return {returnCode: 'OK'};
196 mockRest.addHandler('save', ({data, options, baseUrl}) => {
197 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/questionnaire`);
198 expect(data).to.deep.equal(questionnaireData);
199 expect(options).to.equal(undefined);
200 return {returnCode: 'OK'};
203 return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, {
204 softwareProduct: softwareProductUpdateData,
205 qdata: questionnaireData
207 expect(store.getState()).to.deep.equal(expectedStore);
210 it('Save Software product data only', () => {
211 const softwareProduct = {
213 id: '4730033D16C64E3CA556AB0AC4478218',
214 description: 'A software model for Fortigate.',
215 subCategory: 'resourceNewCategory.network connectivity.virtual links',
216 category: 'resourceNewCategory.network connectivity',
218 vendorName: 'Vendor',
219 licensingVersion: '1.0',
222 licenceAgreement: '123',
228 deepFreeze(softwareProduct);
230 const store = storeCreator({
232 softwareProductEditor: {data: softwareProduct},
233 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
236 deepFreeze(store.getState());
237 const expectedStore = store.getState();
239 const toBeUpdatedSoftwareProductId = softwareProduct.id;
240 const softwareProductUpdateData = {
242 name: 'VSP5_UPDATED',
243 description: 'A software model for Fortigate._UPDATED'
245 deepFreeze(softwareProductUpdateData);
247 mockRest.addHandler('save', ({data, options, baseUrl}) => {
248 const expectedData = {
249 name: 'VSP5_UPDATED',
250 description: 'A software model for Fortigate._UPDATED',
251 subCategory: 'resourceNewCategory.network connectivity.virtual links',
252 category: 'resourceNewCategory.network connectivity',
254 vendorName: 'Vendor',
255 licensingVersion: '1.0',
258 licenceAgreement: '123',
264 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}`);
265 expect(data).to.deep.equal(expectedData);
266 expect(options).to.equal(undefined);
267 return {returnCode: 'OK'};
270 return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, {
271 softwareProduct: softwareProductUpdateData
273 expect(store.getState()).to.deep.equal(expectedStore);
277 it('Save Software product questionnaire only', () => {
278 const softwareProduct = {
280 id: '4730033D16C64E3CA556AB0AC4478218',
281 description: 'A software model for Fortigate.',
282 subCategory: 'resourceNewCategory.network connectivity.virtual links',
283 category: 'resourceNewCategory.network connectivity',
285 vendorName: 'Vendor',
288 licenceAgreement: '123',
294 deepFreeze(softwareProduct);
296 const store = storeCreator({
298 softwareProductEditor: {data: softwareProduct},
299 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
302 deepFreeze(store.getState());
303 const expectedStore = store.getState();
305 const toBeUpdatedSoftwareProductId = softwareProduct.id;
306 const questionnaireData = {
309 affinityGrouping: true,
310 antiAffinityGrouping: false
314 deepFreeze(questionnaireData);
316 mockRest.addHandler('save', ({data, options, baseUrl}) => {
317 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/questionnaire`);
318 expect(data).to.deep.equal(questionnaireData);
319 expect(options).to.equal(undefined);
320 return {returnCode: 'OK'};
323 return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, {
324 softwareProductId: softwareProduct.id,
325 qdata: questionnaireData
327 expect(store.getState()).to.deep.equal(expectedStore);
331 it('Handle category without subcategories', () => {
332 const categories = deepFreeze([
334 name: 'Resource Category 1',
335 normalizedName: 'resource category 1',
336 uniqueId: 'resourceNewCategory.resource category 1',
339 name: 'Sub Category for RC 1',
340 normalizedName: 'sub category for rc 1',
341 uniqueId: 'resourceNewCategory.resource category 1.sub category for rc 1'
345 normalizedName: 'sc4rc2',
346 uniqueId: 'resourceNewCategory.resource category 1.sc4rc2'
350 normalizedName: 'sc4rc1',
351 uniqueId: 'resourceNewCategory.resource category 1.sc4rc1'
357 normalizedName: 'eeeeee',
358 uniqueId: 'resourceNewCategory.eeeeee'
361 name: 'Some Recource',
362 normalizedName: 'some recource',
363 uniqueId: 'resourceNewCategory.some recource',
366 name: 'Second Sub Category for S',
367 normalizedName: 'second sub category for s',
368 uniqueId: 'resourceNewCategory.some recource.second sub category for s'
371 name: 'Sub Category for Some Rec',
372 normalizedName: 'sub category for some rec',
373 uniqueId: 'resourceNewCategory.some recource.sub category for some rec'
378 const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory('resourceNewCategory.some recource.sub category for some rec', categories);
379 expect(category).to.equal('resourceNewCategory.some recource');