blob: de2b8b2d5ee6b32239acf307becae2c59c646d23 [file] [log] [blame]
ilanap1965d162018-01-04 11:34:59 +02001/*
Einav Weiss Keidar1801b242018-08-13 16:19:46 +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 *
ilanap1965d162018-01-04 11:34:59 +02008 * http://www.apache.org/licenses/LICENSE-2.0
AviZi280f8012017-06-09 02:39:56 +03009 *
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,
ilanap1965d162018-01-04 11:34:59 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
AviZi280f8012017-06-09 02:39:56 +030017
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030018import { cloneAndSet } from '../../test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import store from 'sdc-app/AppStore.js';
20import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js';
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030021import { typeEnum as modalType } from 'nfvo-components/modal/GlobalModalConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022
23describe('Error Response Handler Util', () => {
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030024 beforeEach(function() {
25 deepFreeze(store.getState());
26 });
Michael Landoefa037d2017-02-19 12:57:33 +020027
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030028 it('validating error in policyException', () => {
29 let textStatus = '',
30 errorThrown = '';
31 let xhr = {
32 data: {
33 requestError: {
34 policyException: {
35 messageId: 'SVC4122',
36 text: 'Error: Invalid data.'
37 }
38 }
39 }
40 };
41 deepFreeze(xhr);
Michael Landoefa037d2017-02-19 12:57:33 +020042
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030043 const errorNotification = {
44 title: 'Error: SVC4122',
45 msg: 'Error: Invalid data.',
46 type: modalType.ERROR
47 };
Michael Landoefa037d2017-02-19 12:57:33 +020048
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030049 const expectedStore = cloneAndSet(
50 store.getState(),
51 'modal',
52 errorNotification
53 );
AviZi280f8012017-06-09 02:39:56 +030054
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030055 errorResponseHandler(xhr, textStatus, errorThrown);
AviZi280f8012017-06-09 02:39:56 +030056
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030057 expect(store.getState()).toEqual(expectedStore);
58 });
AviZi280f8012017-06-09 02:39:56 +030059
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030060 it('validating error in serviceException with variables', () => {
61 let textStatus = '',
62 errorThrown = '';
63 let xhr = {
64 data: {
65 requestError: {
66 serviceException: {
67 messageId: 'SVC4122',
68 text: "Error: Invalid artifact type '%1'.",
69 variables: ['newType']
70 }
71 }
72 }
73 };
74 deepFreeze(xhr);
Michael Landoefa037d2017-02-19 12:57:33 +020075
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030076 const errorNotification = {
77 title: 'Error: SVC4122',
78 msg: 'Error: Invalid artifact type newType.',
79 type: modalType.ERROR
80 };
Michael Landoefa037d2017-02-19 12:57:33 +020081
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030082 const expectedStore = cloneAndSet(
83 store.getState(),
84 'modal',
85 errorNotification
86 );
Michael Landoefa037d2017-02-19 12:57:33 +020087
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030088 errorResponseHandler(xhr, textStatus, errorThrown);
AviZi280f8012017-06-09 02:39:56 +030089
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030090 expect(store.getState()).toEqual(expectedStore);
91 });
Michael Landoefa037d2017-02-19 12:57:33 +020092
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030093 it('validating error in response', () => {
94 let textStatus = '',
95 errorThrown = '';
96 let xhr = {
97 data: {
98 status: 'AA',
99 message: 'Error: Invalid data.'
100 }
101 };
102 deepFreeze(xhr);
Michael Landoefa037d2017-02-19 12:57:33 +0200103
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300104 const errorNotification = {
105 title: 'AA',
106 msg: 'Error: Invalid data.',
107 type: modalType.ERROR
108 };
Michael Landoefa037d2017-02-19 12:57:33 +0200109
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300110 const expectedStore = cloneAndSet(
111 store.getState(),
112 'modal',
113 errorNotification
114 );
Michael Landoefa037d2017-02-19 12:57:33 +0200115
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300116 errorResponseHandler(xhr, textStatus, errorThrown);
AviZi280f8012017-06-09 02:39:56 +0300117
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300118 expect(store.getState()).toEqual(expectedStore);
119 });
Michael Landoefa037d2017-02-19 12:57:33 +0200120
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300121 it('validating error in request', () => {
122 let textStatus = '',
123 errorThrown = '';
124 let xhr = {
125 statusText: '500',
126 responseText: 'Internal server error.'
127 };
128 deepFreeze(xhr);
Michael Landoefa037d2017-02-19 12:57:33 +0200129
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300130 const errorNotification = {
131 title: '500',
132 msg: 'Internal server error.',
133 type: modalType.ERROR
134 };
Michael Landoefa037d2017-02-19 12:57:33 +0200135
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300136 const expectedStore = cloneAndSet(
137 store.getState(),
138 'modal',
139 errorNotification
140 );
AviZi280f8012017-06-09 02:39:56 +0300141
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300142 errorResponseHandler(xhr, textStatus, errorThrown);
Michael Landoefa037d2017-02-19 12:57:33 +0200143
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300144 expect(store.getState()).toEqual(expectedStore);
145 });
Michael Landoefa037d2017-02-19 12:57:33 +0200146});