ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame] | 1 | /* |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import deepFreeze from 'deep-freeze'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 17 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 18 | import { cloneAndSet } from '../../test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import store from 'sdc-app/AppStore.js'; |
| 20 | import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js'; |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 21 | import { typeEnum as modalType } from 'nfvo-components/modal/GlobalModalConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
| 23 | describe('Error Response Handler Util', () => { |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 24 | beforeEach(function() { |
| 25 | deepFreeze(store.getState()); |
| 26 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 28 | it('validating error in policyException', () => { |
| 29 | let textStatus = '', |
| 30 | errorThrown = ''; |
| 31 | let xhr = { |
| 32 | data: { |
| 33 | requestError: { |
| 34 | policyException: { |
| 35 | messageId: 'SVC4122', |
| 36 | text: 'Error: Invalid data.' |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | }; |
| 41 | deepFreeze(xhr); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 43 | const errorNotification = { |
| 44 | title: 'Error: SVC4122', |
| 45 | msg: 'Error: Invalid data.', |
| 46 | type: modalType.ERROR |
| 47 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 48 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 49 | const expectedStore = cloneAndSet( |
| 50 | store.getState(), |
| 51 | 'modal', |
| 52 | errorNotification |
| 53 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 55 | errorResponseHandler(xhr, textStatus, errorThrown); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 56 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 57 | expect(store.getState()).toEqual(expectedStore); |
| 58 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 60 | it('validating error in serviceException with variables', () => { |
| 61 | let textStatus = '', |
| 62 | errorThrown = ''; |
| 63 | let xhr = { |
| 64 | data: { |
| 65 | requestError: { |
| 66 | serviceException: { |
| 67 | messageId: 'SVC4122', |
| 68 | text: "Error: Invalid artifact type '%1'.", |
| 69 | variables: ['newType'] |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | deepFreeze(xhr); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 75 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 76 | const errorNotification = { |
| 77 | title: 'Error: SVC4122', |
| 78 | msg: 'Error: Invalid artifact type newType.', |
| 79 | type: modalType.ERROR |
| 80 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 82 | const expectedStore = cloneAndSet( |
| 83 | store.getState(), |
| 84 | 'modal', |
| 85 | errorNotification |
| 86 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 87 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 88 | errorResponseHandler(xhr, textStatus, errorThrown); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 90 | expect(store.getState()).toEqual(expectedStore); |
| 91 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 93 | it('validating error in response', () => { |
| 94 | let textStatus = '', |
| 95 | errorThrown = ''; |
| 96 | let xhr = { |
| 97 | data: { |
| 98 | status: 'AA', |
| 99 | message: 'Error: Invalid data.' |
| 100 | } |
| 101 | }; |
| 102 | deepFreeze(xhr); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 103 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 104 | const errorNotification = { |
| 105 | title: 'AA', |
| 106 | msg: 'Error: Invalid data.', |
| 107 | type: modalType.ERROR |
| 108 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 109 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 110 | const expectedStore = cloneAndSet( |
| 111 | store.getState(), |
| 112 | 'modal', |
| 113 | errorNotification |
| 114 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 115 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 116 | errorResponseHandler(xhr, textStatus, errorThrown); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 117 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 118 | expect(store.getState()).toEqual(expectedStore); |
| 119 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 120 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 121 | it('validating error in request', () => { |
| 122 | let textStatus = '', |
| 123 | errorThrown = ''; |
| 124 | let xhr = { |
| 125 | statusText: '500', |
| 126 | responseText: 'Internal server error.' |
| 127 | }; |
| 128 | deepFreeze(xhr); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 129 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 130 | const errorNotification = { |
| 131 | title: '500', |
| 132 | msg: 'Internal server error.', |
| 133 | type: modalType.ERROR |
| 134 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 135 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 136 | const expectedStore = cloneAndSet( |
| 137 | store.getState(), |
| 138 | 'modal', |
| 139 | errorNotification |
| 140 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 141 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 142 | errorResponseHandler(xhr, textStatus, errorThrown); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 143 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 144 | expect(store.getState()).toEqual(expectedStore); |
| 145 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 146 | }); |