blob: fd9dec6a8dee3d2f7a690c6449dcb0b611aa4a8d [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20
21import deepFreeze from 'deep-freeze';
22import expect from 'expect';
23import {cloneAndSet} from '../../test-utils/Util.js';
24import store from 'sdc-app/AppStore.js';
25import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js';
26
27describe('Error Response Handler Util', () => {
28
29 beforeEach(function () {
30 deepFreeze(store.getState());
31 });
32
33 it('validating error in policyException', done => {
34 let textStatus = '', errorThrown = '';
35 let xhr = {
36 responseJSON: {
37 requestError: {
38 policyException: {
39 messageId: 'SVC4122',
40 text: 'Error: Invalid data.'
41 }
42 }
43 }
44 };
45 deepFreeze(xhr);
46
47 const errorNotification = {
48 type: 'error', title: 'Error: SVC4122', msg: 'Error: Invalid data.', timeout: undefined,
49 validationResponse: undefined
50 };
51 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
52
53 errorResponseHandler(xhr, textStatus, errorThrown);
54
55 setTimeout(function () {
56 expect(store.getState()).toEqual(expectedStore);
57 done();
58 }, 100);
59 });
60
61 it('validating error in serviceException with variables', done => {
62 let textStatus = '', errorThrown = '';
63 let xhr = {
64 responseJSON: {
65 requestError: {
66 serviceException: {
67 messageId: 'SVC4122',
68 text: "Error: Invalid artifact type '%1'.",
69 variables: ['newType']
70 }
71 }
72 }
73 };
74 deepFreeze(xhr);
75
76 const errorNotification = {
77 type: 'error', title: 'Error: SVC4122', msg: 'Error: Invalid artifact type newType.', timeout: undefined,
78 validationResponse: undefined
79 };
80 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
81
82 errorResponseHandler(xhr, textStatus, errorThrown);
83
84 setTimeout(function () {
85 expect(store.getState()).toEqual(expectedStore);
86 done();
87 }, 100);
88 });
89
90 it('validating error in response', done => {
91 let textStatus = '', errorThrown = '';
92 let xhr = {
93 responseJSON: {
94 status: 'AA',
95 message: 'Error: Invalid data.'
96 }
97 };
98 deepFreeze(xhr);
99
100 const errorNotification = {
101 type: 'error', title: 'AA', msg: 'Error: Invalid data.', timeout: undefined,
102 validationResponse: undefined
103 };
104 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
105
106 errorResponseHandler(xhr, textStatus, errorThrown);
107
108 setTimeout(function () {
109 expect(store.getState()).toEqual(expectedStore);
110 done();
111 }, 100);
112 });
113
114 it('validating error in request', done => {
115 let textStatus = '', errorThrown = '';
116 let xhr = {
117 statusText: '500',
118 responseText: 'Internal server error.'
119 };
120 deepFreeze(xhr);
121
122 const errorNotification = {
123 type: 'error', title: '500', msg: 'Internal server error.', timeout: undefined,
124 validationResponse: undefined
125 };
126 const expectedStore = cloneAndSet(store.getState(), 'notification', errorNotification);
127
128 errorResponseHandler(xhr, textStatus, errorThrown);
129
130 setTimeout(function () {
131 expect(store.getState()).toEqual(expectedStore);
132 done();
133 }, 100);
134 });
135});