blob: 40836f728a86821d59d181680474ad7ed07be670 [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
29 it('validating error in policyException', done => {
30 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
AviZi280f8012017-06-09 02:39:56 +030056 setTimeout(function () {
Michael Landoefa037d2017-02-19 12:57:33 +020057 expect(store.getState()).toEqual(expectedStore);
58 done();
59 }, 100);
60 });
61
62 it('validating error in serviceException with variables', done => {
63 let textStatus = '', errorThrown = '';
64 let xhr = {
65 responseJSON: {
66 requestError: {
67 serviceException: {
68 messageId: 'SVC4122',
69 text: "Error: Invalid artifact type '%1'.",
70 variables: ['newType']
71 }
72 }
73 }
74 };
75 deepFreeze(xhr);
AviZi280f8012017-06-09 02:39:56 +030076
77 const errorNotification = {
78 title: 'Error: SVC4122',
79 msg: 'Error: Invalid artifact type newType.',
80 modalClassName: 'notification-modal',
81 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +020082 };
AviZi280f8012017-06-09 02:39:56 +030083
84 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +020085
86 errorResponseHandler(xhr, textStatus, errorThrown);
87
88 setTimeout(function () {
89 expect(store.getState()).toEqual(expectedStore);
90 done();
91 }, 100);
92 });
93
94 it('validating error in response', done => {
95 let textStatus = '', errorThrown = '';
96 let xhr = {
97 responseJSON: {
98 status: 'AA',
99 message: 'Error: Invalid data.'
100 }
101 };
102 deepFreeze(xhr);
103
AviZi280f8012017-06-09 02:39:56 +0300104 const errorNotification = {
105 title: 'AA',
106 msg: 'Error: Invalid data.',
107 modalClassName: 'notification-modal',
108 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +0200109 };
AviZi280f8012017-06-09 02:39:56 +0300110
111 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +0200112
113 errorResponseHandler(xhr, textStatus, errorThrown);
114
115 setTimeout(function () {
116 expect(store.getState()).toEqual(expectedStore);
117 done();
118 }, 100);
119 });
120
121 it('validating error in request', done => {
122 let textStatus = '', errorThrown = '';
123 let xhr = {
124 statusText: '500',
125 responseText: 'Internal server error.'
126 };
127 deepFreeze(xhr);
AviZi280f8012017-06-09 02:39:56 +0300128
129 const errorNotification = {
130 title: '500',
131 msg: 'Internal server error.',
132 modalClassName: 'notification-modal',
133 type: modalType.ERROR
Michael Landoefa037d2017-02-19 12:57:33 +0200134 };
AviZi280f8012017-06-09 02:39:56 +0300135
136 const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification);
Michael Landoefa037d2017-02-19 12:57:33 +0200137
138 errorResponseHandler(xhr, textStatus, errorThrown);
139
140 setTimeout(function () {
141 expect(store.getState()).toEqual(expectedStore);
142 done();
143 }, 100);
144 });
145});