2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import deepFreeze from 'deep-freeze';
22 import expect from 'expect';
23 import {cloneAndSet} from '../../test-utils/Util.js';
24 import store from 'sdc-app/AppStore.js';
25 import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js';
27 describe('Error Response Handler Util', () => {
29 beforeEach(function () {
30 deepFreeze(store.getState());
33 it('validating error in policyException', done => {
34 let textStatus = '', errorThrown = '';
40 text: 'Error: Invalid data.'
47 const errorNotification = {
48 type: 'error', title: 'Error: SVC4122', msg: 'Error: Invalid data.', timeout: undefined,
49 validationResponse: undefined
51 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
53 errorResponseHandler(xhr, textStatus, errorThrown);
55 setTimeout(function () {
56 expect(store.getState()).toEqual(expectedStore);
61 it('validating error in serviceException with variables', done => {
62 let textStatus = '', errorThrown = '';
68 text: "Error: Invalid artifact type '%1'.",
69 variables: ['newType']
76 const errorNotification = {
77 type: 'error', title: 'Error: SVC4122', msg: 'Error: Invalid artifact type newType.', timeout: undefined,
78 validationResponse: undefined
80 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
82 errorResponseHandler(xhr, textStatus, errorThrown);
84 setTimeout(function () {
85 expect(store.getState()).toEqual(expectedStore);
90 it('validating error in response', done => {
91 let textStatus = '', errorThrown = '';
95 message: 'Error: Invalid data.'
100 const errorNotification = {
101 type: 'error', title: 'AA', msg: 'Error: Invalid data.', timeout: undefined,
102 validationResponse: undefined
104 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
106 errorResponseHandler(xhr, textStatus, errorThrown);
108 setTimeout(function () {
109 expect(store.getState()).toEqual(expectedStore);
114 it('validating error in request', done => {
115 let textStatus = '', errorThrown = '';
118 responseText: 'Internal server error.'
122 const errorNotification = {
123 type: 'error', title: '500', msg: 'Internal server error.', timeout: undefined,
124 validationResponse: undefined
126 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
128 errorResponseHandler(xhr, textStatus, errorThrown);
130 setTimeout(function () {
131 expect(store.getState()).toEqual(expectedStore);