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', done => {
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 setTimeout(function () {
57 expect(store.getState()).toEqual(expectedStore);
62 it('validating error in serviceException with variables', done => {
63 let textStatus = '', errorThrown = '';
69 text: "Error: Invalid artifact type '%1'.",
70 variables: ['newType']
77 const errorNotification = {
78 title: 'Error: SVC4122',
79 msg: 'Error: Invalid artifact type newType.',
80 modalClassName: 'notification-modal',
84 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
86 errorResponseHandler(xhr, textStatus, errorThrown);
88 setTimeout(function () {
89 expect(store.getState()).toEqual(expectedStore);
94 it('validating error in response', done => {
95 let textStatus = '', errorThrown = '';
99 message: 'Error: Invalid data.'
104 const errorNotification = {
106 msg: 'Error: Invalid data.',
107 modalClassName: 'notification-modal',
108 type: modalType.ERROR
111 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
113 errorResponseHandler(xhr, textStatus, errorThrown);
115 setTimeout(function () {
116 expect(store.getState()).toEqual(expectedStore);
121 it('validating error in request', done => {
122 let textStatus = '', errorThrown = '';
125 responseText: 'Internal server error.'
129 const errorNotification = {
131 msg: 'Internal server error.',
132 modalClassName: 'notification-modal',
133 type: modalType.ERROR
136 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
138 errorResponseHandler(xhr, textStatus, errorThrown);
140 setTimeout(function () {
141 expect(store.getState()).toEqual(expectedStore);