ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2017 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 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import {cloneAndSet} from '../../test-utils/Util.js'; |
| 19 | import store from 'sdc-app/AppStore.js'; |
| 20 | import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +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', () => { |
| 24 | |
| 25 | beforeEach(function () { |
| 26 | deepFreeze(store.getState()); |
| 27 | }); |
| 28 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 29 | it('validating error in policyException', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | let textStatus = '', errorThrown = ''; |
| 31 | let xhr = { |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 32 | data: { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | requestError: { |
| 34 | policyException: { |
| 35 | messageId: 'SVC4122', |
| 36 | text: 'Error: Invalid data.' |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | }; |
| 41 | deepFreeze(xhr); |
| 42 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | const errorNotification = { |
| 44 | title: 'Error: SVC4122', |
| 45 | msg: 'Error: Invalid data.', |
| 46 | modalClassName: 'notification-modal', |
| 47 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 48 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | |
| 50 | |
| 51 | |
| 52 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 53 | |
| 54 | errorResponseHandler(xhr, textStatus, errorThrown); |
| 55 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 56 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 57 | }); |
| 58 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 59 | it('validating error in serviceException with variables', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 60 | let textStatus = '', errorThrown = ''; |
| 61 | let xhr = { |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 62 | data: { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 63 | requestError: { |
| 64 | serviceException: { |
| 65 | messageId: 'SVC4122', |
| 66 | text: "Error: Invalid artifact type '%1'.", |
| 67 | variables: ['newType'] |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | }; |
| 72 | deepFreeze(xhr); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 73 | |
| 74 | const errorNotification = { |
| 75 | title: 'Error: SVC4122', |
| 76 | msg: 'Error: Invalid artifact type newType.', |
| 77 | modalClassName: 'notification-modal', |
| 78 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 79 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 80 | |
| 81 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | |
| 83 | errorResponseHandler(xhr, textStatus, errorThrown); |
| 84 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 85 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 86 | }); |
| 87 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 88 | it('validating error in response', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 89 | let textStatus = '', errorThrown = ''; |
| 90 | let xhr = { |
ilanap | 1965d16 | 2018-01-04 11:34:59 +0200 | [diff] [blame^] | 91 | data: { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | status: 'AA', |
| 93 | message: 'Error: Invalid data.' |
| 94 | } |
| 95 | }; |
| 96 | deepFreeze(xhr); |
| 97 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 98 | const errorNotification = { |
| 99 | title: 'AA', |
| 100 | msg: 'Error: Invalid data.', |
| 101 | modalClassName: 'notification-modal', |
| 102 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 103 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 104 | |
| 105 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 106 | |
| 107 | errorResponseHandler(xhr, textStatus, errorThrown); |
| 108 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 109 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 110 | }); |
| 111 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 112 | it('validating error in request', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | let textStatus = '', errorThrown = ''; |
| 114 | let xhr = { |
| 115 | statusText: '500', |
| 116 | responseText: 'Internal server error.' |
| 117 | }; |
| 118 | deepFreeze(xhr); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 119 | |
| 120 | const errorNotification = { |
| 121 | title: '500', |
| 122 | msg: 'Internal server error.', |
| 123 | modalClassName: 'notification-modal', |
| 124 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 125 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 126 | |
| 127 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 128 | |
| 129 | errorResponseHandler(xhr, textStatus, errorThrown); |
| 130 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 131 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 132 | }); |
| 133 | }); |