AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
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 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 12 | * 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 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 | |
| 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 | |
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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 56 | setTimeout(function () { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 57 | 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); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 76 | |
| 77 | const errorNotification = { |
| 78 | title: 'Error: SVC4122', |
| 79 | msg: 'Error: Invalid artifact type newType.', |
| 80 | modalClassName: 'notification-modal', |
| 81 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 83 | |
| 84 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 85 | |
| 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 104 | const errorNotification = { |
| 105 | title: 'AA', |
| 106 | msg: 'Error: Invalid data.', |
| 107 | modalClassName: 'notification-modal', |
| 108 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 109 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 110 | |
| 111 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | |
| 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); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 128 | |
| 129 | const errorNotification = { |
| 130 | title: '500', |
| 131 | msg: 'Internal server error.', |
| 132 | modalClassName: 'notification-modal', |
| 133 | type: modalType.ERROR |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 134 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 135 | |
| 136 | const expectedStore = cloneAndSet(store.getState(), 'modal', errorNotification); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 137 | |
| 138 | errorResponseHandler(xhr, textStatus, errorThrown); |
| 139 | |
| 140 | setTimeout(function () { |
| 141 | expect(store.getState()).toEqual(expectedStore); |
| 142 | done(); |
| 143 | }, 100); |
| 144 | }); |
| 145 | }); |