blob: 07f7ff72ac659c5f7a358365fc14a195f54e613b [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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,
AviZi280f8012017-06-09 02:39:56 +030012 * 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.
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
Michael Landoefa037d2017-02-19 12:57:33 +020018import {cloneAndSet} from '../../test-utils/Util.js';
19import store from 'sdc-app/AppStore.js';
20import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js';
AviZi280f8012017-06-09 02:39:56 +030021import {typeEnum as modalType} from 'nfvo-components/modal/GlobalModalConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022
23describe('Error Response Handler Util', () => {
24
25 beforeEach(function () {
26 deepFreeze(store.getState());
27 });
28
talig8e9c0652017-12-20 14:30:43 +020029 it('validating error in policyException', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020030 let textStatus = '', errorThrown = '';
31 let xhr = {
32 responseJSON: {
33 requestError: {
34 policyException: {
35 messageId: 'SVC4122',
36 text: 'Error: Invalid data.'
37 }
38 }
39 }
40 };
41 deepFreeze(xhr);
42
AviZi280f8012017-06-09 02:39:56 +030043 const errorNotification = {
44 title: 'Error: SVC4122',
45 msg: 'Error: Invalid data.',
46 modalClassName: 'notification-modal',
47 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +020048 };
AviZi280f8012017-06-09 02:39:56 +030049
50
51
52 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +020053
54 errorResponseHandler(xhr, textStatus, errorThrown);
55
talig8e9c0652017-12-20 14:30:43 +020056 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020057 });
58
talig8e9c0652017-12-20 14:30:43 +020059 it('validating error in serviceException with variables', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020060 let textStatus = '', errorThrown = '';
61 let xhr = {
62 responseJSON: {
63 requestError: {
64 serviceException: {
65 messageId: 'SVC4122',
66 text: "Error: Invalid artifact type '%1'.",
67 variables: ['newType']
68 }
69 }
70 }
71 };
72 deepFreeze(xhr);
AviZi280f8012017-06-09 02:39:56 +030073
74 const errorNotification = {
75 title: 'Error: SVC4122',
76 msg: 'Error: Invalid artifact type newType.',
77 modalClassName: 'notification-modal',
78 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +020079 };
AviZi280f8012017-06-09 02:39:56 +030080
81 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +020082
83 errorResponseHandler(xhr, textStatus, errorThrown);
84
talig8e9c0652017-12-20 14:30:43 +020085 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020086 });
87
talig8e9c0652017-12-20 14:30:43 +020088 it('validating error in response', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020089 let textStatus = '', errorThrown = '';
90 let xhr = {
91 responseJSON: {
92 status: 'AA',
93 message: 'Error: Invalid data.'
94 }
95 };
96 deepFreeze(xhr);
97
AviZi280f8012017-06-09 02:39:56 +030098 const errorNotification = {
99 title: 'AA',
100 msg: 'Error: Invalid data.',
101 modalClassName: 'notification-modal',
102 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +0200103 };
AviZi280f8012017-06-09 02:39:56 +0300104
105 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +0200106
107 errorResponseHandler(xhr, textStatus, errorThrown);
108
talig8e9c0652017-12-20 14:30:43 +0200109 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200110 });
111
talig8e9c0652017-12-20 14:30:43 +0200112 it('validating error in request', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200113 let textStatus = '', errorThrown = '';
114 let xhr = {
115 statusText: '500',
116 responseText: 'Internal server error.'
117 };
118 deepFreeze(xhr);
AviZi280f8012017-06-09 02:39:56 +0300119
120 const errorNotification = {
121 title: '500',
122 msg: 'Internal server error.',
123 modalClassName: 'notification-modal',
124 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +0200125 };
AviZi280f8012017-06-09 02:39:56 +0300126
127 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +0200128
129 errorResponseHandler(xhr, textStatus, errorThrown);
130
talig8e9c0652017-12-20 14:30:43 +0200131 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200132 });
133});