Add new code new version
[sdc.git] / openecomp-ui / test / softwareProduct / components / network / SoftwareProductComponentsNetworkActionHelper.test.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
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';
26 import SoftwareProductComponentsNetworkActionHelper from 'sdc-app/onboarding/softwareProduct/components/network/SoftwareProductComponentsNetworkActionHelper.js';
27
28 const softwareProductId = '123';
29 const componentId = '321';
30 const nicId = '111';
31
32 describe('Software Product Components Network Action Helper Tests', function () {
33
34         it('Fetch NICs List', () => {
35                 const store = storeCreator();
36                 deepFreeze(store.getState());
37
38                 const NICList = [
39                         {
40                                 name:'oam01_port_0',
41                                 description:'bbbbbbb',
42                                 networkId:'A0E578751B284D518ED764D5378EA97C',
43                                 id:'96D3648338F94DAA9889E9FBB8E59895',
44                                 networkName:'csb_net'
45                         },
46                         {
47                                 name:'oam01_port_1',
48                                 description:'bbbbbbb',
49                                 networkId:'378EA97CA0E578751B284D518ED764D5',
50                                 id:'8E5989596D3648338F94DAA9889E9FBB',
51                                 networkName:'csb_net_2'
52                         }
53
54                 ];
55
56                 deepFreeze(NICList);
57
58                 deepFreeze(store.getState());
59
60                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network.nicList', NICList);
61
62                 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
63                         expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/nics`);
64                         expect(data).to.deep.equal(undefined);
65                         expect(options).to.equal(undefined);
66                         return {results: NICList};
67                 });
68
69                 return SoftwareProductComponentsNetworkActionHelper.fetchNICsList(store.dispatch, {softwareProductId, componentId}).then(() => {
70                         expect(store.getState()).to.deep.equal(expectedStore);
71                 });
72
73         });
74
75         it('open NICE editor', () => {
76
77                 const store = storeCreator();
78                 deepFreeze(store.getState());
79                 const data = {
80                         name: 'oam01_port_0',
81                         description: 'bbbbbbb',
82                         networkId: 'A0E578751B284D518ED764D5378EA97C',
83                         networkName: 'csb_net'
84                 };
85
86                 const nic = {id: '444'};
87                 deepFreeze(data);
88                 deepFreeze(nic);
89
90                 const expectedData = {...data, id: nic.id};
91
92                 deepFreeze(expectedData);
93
94                 const network = {
95                         nicEditor: {
96                                 data: expectedData
97                         },
98                         nicList: []
99                 };
100
101                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network', network);
102
103                 SoftwareProductComponentsNetworkActionHelper.openNICEditor(store.dispatch, {nic, data});
104
105                 return setTimeout(() => {
106                         expect(store.getState()).to.deep.equal(expectedStore);
107                 }, 100);
108         });
109
110         it('close NICE editor', () => {
111
112                 const store = storeCreator();
113                 deepFreeze(store.getState());
114
115                 const network = {
116                         nicEditor: {},
117                         nicList: []
118                 };
119                 deepFreeze(network);
120
121                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network', network);
122
123                 SoftwareProductComponentsNetworkActionHelper.closeNICEditor(store.dispatch);
124
125                 return setTimeout(() => {
126                         expect(store.getState()).to.deep.equal(expectedStore);
127                 }, 100);
128         });
129
130         it('Load NIC data', () => {
131
132                 const expectedData = {
133                         description: 'bbbbbbb',
134                         name: 'oam01_port_0',
135                         networkId: 'A0E578751B284D518ED764D5378EA97C',
136                         networkName: 'csb_net'
137                 };
138
139                 deepFreeze(expectedData);
140
141                 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
142                         expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/nics/${nicId}`);
143                         expect(data).to.deep.equal(undefined);
144                         expect(options).to.equal(undefined);
145                         return (expectedData);
146                 });
147
148                 return SoftwareProductComponentsNetworkActionHelper.loadNICData({softwareProductId, componentId, nicId}).then((data) => {
149                         expect(data).to.deep.equal(expectedData);
150                 });
151         });
152
153
154         it('load NIC Questionnaire', () => {
155
156                 const store = storeCreator();
157                 deepFreeze(store.getState());
158
159                 const qdata = {
160                         protocols: {
161                                 protocolWithHighestTrafficProfile: 'UDP',
162                                 protocols: ['UDP']
163                         },
164                         ipConfiguration: {
165                                 ipv4Required: true
166                         }
167                 };
168
169                 const qschema = {
170                         $schema: 'http://json-schema.org/draft-04/schema#',
171                         type: 'object',
172                         properties: {
173                                 'protocols': {
174                                         type: 'object',
175                                         properties: {}
176                                 }
177                         }
178                 };
179
180                 deepFreeze(qdata);
181                 deepFreeze(qschema);
182
183
184                 const network = {
185                         nicEditor: {
186                                 qdata,
187                                 qschema
188                         },
189                         nicList: []
190                 };
191                 deepFreeze(network);
192
193                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network', network);
194
195                 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
196                         expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/nics/${nicId}/questionnaire`);
197                         expect(data).to.deep.equal(undefined);
198                         expect(options).to.equal(undefined);
199                         return ({data: JSON.stringify(qdata), schema: JSON.stringify(qschema)});
200                 });
201
202                 return SoftwareProductComponentsNetworkActionHelper.loadNICQuestionnaire(store.dispatch, {softwareProductId, componentId, nicId}).then(() => {
203                         expect(store.getState()).to.deep.equal(expectedStore);
204                 });
205         });
206
207         it('update NIC Data', () => {
208                 const store = storeCreator();
209                 deepFreeze(store.getState());
210
211                 const data = {test: '123'};
212                 deepFreeze(data);
213
214                 const network = {
215                         nicEditor: {
216                                 data
217                         },
218                         nicList: []
219                 };
220
221                 deepFreeze(network);
222
223                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network', network);
224
225                 SoftwareProductComponentsNetworkActionHelper.updateNICData(store.dispatch, {deltaData:data});
226
227                 return setTimeout(() => {
228                         expect(store.getState()).to.deep.equal(expectedStore);
229                 }, 100);
230
231         });
232
233         it('update NIC Questionnaire', () => {
234                 const store = storeCreator();
235                 deepFreeze(store.getState());
236
237                 const qdata = {
238                         test: '123'
239                 };
240                 const network = {
241                         nicEditor: {
242                                 qdata,
243                                 qschema: undefined
244                         },
245                         nicList: []
246                 };
247                 deepFreeze(network);
248
249                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network', network);
250
251                 SoftwareProductComponentsNetworkActionHelper.updateNICQuestionnaire(store.dispatch, {data:qdata});
252
253                 return setTimeout(() => {
254                         expect(store.getState()).to.deep.equal(expectedStore);
255                 }, 100);
256
257         });
258
259         it('save NIC Data And Questionnaire', () => {
260
261                 const store = storeCreator();
262                 deepFreeze(store.getState());
263
264                 const qdata = {
265                         qtest: '111'
266                 };
267                 const data = {
268                         name: '2222',
269                         description: 'blabla',
270                         networkId: '123445'
271                 };
272
273                 const expectedData = {...data, id: nicId};
274
275                 const network = {
276                         nicEditor: {},
277                         nicList: [
278                                 expectedData
279                         ]
280                 };
281
282                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.network', network);
283                 deepFreeze(expectedStore);
284
285                 mockRest.addHandler('save', ({options, data, baseUrl}) => {
286                         expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/nics/${nicId}/questionnaire`);
287                         expect(data).to.deep.equal(qdata);
288                         expect(options).to.equal(undefined);
289                         return {returnCode: 'OK'};
290                 });
291
292                 mockRest.addHandler('save', ({options, data, baseUrl}) => {
293                         expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${componentId}/nics/${nicId}`);
294                         expect(data).to.deep.equal(data);
295                         expect(options).to.equal(undefined);
296                         return {returnCode: 'OK'};
297                 });
298
299                 return SoftwareProductComponentsNetworkActionHelper.saveNICDataAndQuestionnaire(store.dispatch, {softwareProductId, componentId, qdata, data: expectedData}).then(() => {
300                         expect(store.getState()).to.deep.equal(expectedStore);
301                 });
302         });
303
304
305 });