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';
18 import {cloneAndSet} from '../../test-utils/Util.js';
19 import store from 'sdc-app/AppStore.js';
20 import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js';
21 import {typeEnum as modalType} from 'nfvo-components/modal/GlobalModalConstants.js';
23 describe('Error Response Handler Util', () => {
25 beforeEach(function () {
26 deepFreeze(store.getState());
29 it('validating error in policyException', () => {
30 let textStatus = '', errorThrown = '';
36 text: 'Error: Invalid data.'
43 const errorNotification = {
44 title: 'Error: SVC4122',
45 msg: 'Error: Invalid data.',
46 modalClassName: 'notification-modal',
52 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
54 errorResponseHandler(xhr, textStatus, errorThrown);
56 expect(store.getState()).toEqual(expectedStore);
59 it('validating error in serviceException with variables', () => {
60 let textStatus = '', errorThrown = '';
66 text: "Error: Invalid artifact type '%1'.",
67 variables: ['newType']
74 const errorNotification = {
75 title: 'Error: SVC4122',
76 msg: 'Error: Invalid artifact type newType.',
77 modalClassName: 'notification-modal',
81 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
83 errorResponseHandler(xhr, textStatus, errorThrown);
85 expect(store.getState()).toEqual(expectedStore);
88 it('validating error in response', () => {
89 let textStatus = '', errorThrown = '';
93 message: 'Error: Invalid data.'
98 const errorNotification = {
100 msg: 'Error: Invalid data.',
101 modalClassName: 'notification-modal',
102 type: modalType.ERROR
105 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
107 errorResponseHandler(xhr, textStatus, errorThrown);
109 expect(store.getState()).toEqual(expectedStore);
112 it('validating error in request', () => {
113 let textStatus = '', errorThrown = '';
116 responseText: 'Internal server error.'
120 const errorNotification = {
122 msg: 'Internal server error.',
123 modalClassName: 'notification-modal',
124 type: modalType.ERROR
127 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
129 errorResponseHandler(xhr, textStatus, errorThrown);
131 expect(store.getState()).toEqual(expectedStore);