orc-shared 1.6.0-dev.4 → 1.6.0-dev.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/globalErrorMessages.js +67 -0
- package/dist/actions/makeApiAction.js +1 -1
- package/dist/buildStore.js +3 -1
- package/dist/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js +133 -0
- package/dist/components/MaterialUI/DataDisplay/PredefinedElements/LookupDisplayValue.js +78 -0
- package/dist/components/Scope/useScopeConfirmationModalState.js +1 -1
- package/dist/hooks/useDispatchWithErrorHandling.js +106 -0
- package/dist/reducers/globalErrorMessages.js +79 -0
- package/dist/selectors/globalErrorMessages.js +58 -0
- package/dist/utils/responseProcessingHelper.js +86 -0
- package/package.json +6 -4
- package/src/actions/globalErrorMessages.js +12 -0
- package/src/actions/globalErrorMessages.test.js +21 -0
- package/src/buildStore.js +2 -0
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js +92 -0
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.test.js +444 -0
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/LookupDisplayValue.js +12 -0
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/LookupDisplayValue.test.js +85 -0
- package/src/hooks/useDispatchWithErrorHandling.js +57 -0
- package/src/hooks/useDispatchWithErrorHandling.test.js +230 -0
- package/src/reducers/globalErrorMessages.js +25 -0
- package/src/reducers/globalErrorMessages.test.js +66 -0
- package/src/selectors/globalErrorMessages.js +11 -0
- package/src/selectors/globalErrorMessages.test.js +25 -0
- package/src/utils/responseProcessingHelper.js +41 -0
- package/src/utils/responseProcessingHelper.test.js +182 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useDispatchWithErrorHandling } from "./useDispatchWithErrorHandling";
|
|
3
|
+
import sinon from "sinon";
|
|
4
|
+
import { mount } from "enzyme";
|
|
5
|
+
import { Provider } from "react-redux";
|
|
6
|
+
import Immutable from "immutable";
|
|
7
|
+
import { pushGlobalErrorMessage } from "../actions/globalErrorMessages";
|
|
8
|
+
|
|
9
|
+
const delay = () => new Promise(resolve => setTimeout(resolve, 10));
|
|
10
|
+
|
|
11
|
+
describe("useDispatchWithErrorHandling", () => {
|
|
12
|
+
let store, state, dispatchSpy;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
state = Immutable.fromJS({});
|
|
16
|
+
dispatchSpy = sinon.stub().named("dispatch");
|
|
17
|
+
|
|
18
|
+
store = {
|
|
19
|
+
subscribe: () => {},
|
|
20
|
+
dispatch: dispatchSpy,
|
|
21
|
+
getState: () => state,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("Dispatches action just with specified parameters", () => {
|
|
26
|
+
dispatchSpy.resolves({});
|
|
27
|
+
|
|
28
|
+
const TestComp = () => {
|
|
29
|
+
const dispatch = useDispatchWithErrorHandling();
|
|
30
|
+
dispatch({
|
|
31
|
+
action: { type: "testing" },
|
|
32
|
+
errorTitle: "title",
|
|
33
|
+
errorDescription: "desc",
|
|
34
|
+
validationLookupModule: "order",
|
|
35
|
+
validationLookupName: "ValidationsOrderReturns",
|
|
36
|
+
});
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const component = (
|
|
41
|
+
<Provider store={store}>
|
|
42
|
+
<TestComp />
|
|
43
|
+
</Provider>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
mount(component);
|
|
47
|
+
|
|
48
|
+
expect(dispatchSpy.callCount, "to be", 1);
|
|
49
|
+
expect(dispatchSpy, "to have a call satisfying", { args: [{ type: "testing" }] });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("does not push messages because data is null", () => {
|
|
53
|
+
dispatchSpy.resolves(null);
|
|
54
|
+
|
|
55
|
+
const TestComp = () => {
|
|
56
|
+
const dispatch = useDispatchWithErrorHandling();
|
|
57
|
+
dispatch({
|
|
58
|
+
action: { type: "testing" },
|
|
59
|
+
errorTitle: "title",
|
|
60
|
+
errorDescription: "desc",
|
|
61
|
+
validationLookupModule: "order",
|
|
62
|
+
validationLookupName: "ValidationsOrderReturns",
|
|
63
|
+
});
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const component = (
|
|
68
|
+
<Provider store={store}>
|
|
69
|
+
<TestComp />
|
|
70
|
+
</Provider>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
mount(component);
|
|
74
|
+
|
|
75
|
+
expect(dispatchSpy.callCount, "to be", 1);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("does not push messages because data is an empty object", () => {
|
|
79
|
+
dispatchSpy.resolves({});
|
|
80
|
+
|
|
81
|
+
const TestComp = () => {
|
|
82
|
+
const dispatch = useDispatchWithErrorHandling();
|
|
83
|
+
dispatch({
|
|
84
|
+
action: { type: "testing" },
|
|
85
|
+
errorTitle: "title",
|
|
86
|
+
errorDescription: "desc",
|
|
87
|
+
validationLookupModule: "order",
|
|
88
|
+
validationLookupName: "ValidationsOrderReturns",
|
|
89
|
+
});
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const component = (
|
|
94
|
+
<Provider store={store}>
|
|
95
|
+
<TestComp />
|
|
96
|
+
</Provider>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
mount(component);
|
|
100
|
+
|
|
101
|
+
expect(dispatchSpy.callCount, "to be", 1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("does not push messages because data is a response with error=false", () => {
|
|
105
|
+
dispatchSpy.resolves({ error: false });
|
|
106
|
+
|
|
107
|
+
const TestComp = () => {
|
|
108
|
+
const dispatch = useDispatchWithErrorHandling();
|
|
109
|
+
dispatch({
|
|
110
|
+
action: { type: "testing" },
|
|
111
|
+
errorTitle: "title",
|
|
112
|
+
errorDescription: "desc",
|
|
113
|
+
validationLookupModule: "order",
|
|
114
|
+
validationLookupName: "ValidationsOrderReturns",
|
|
115
|
+
});
|
|
116
|
+
return null;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const component = (
|
|
120
|
+
<Provider store={store}>
|
|
121
|
+
<TestComp />
|
|
122
|
+
</Provider>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
mount(component);
|
|
126
|
+
|
|
127
|
+
expect(dispatchSpy.callCount, "to be", 1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("dispatch new message with title and description because of empty msg list", () => {
|
|
131
|
+
dispatchSpy.resolves({
|
|
132
|
+
error: true,
|
|
133
|
+
payload: {
|
|
134
|
+
status: 500,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const TestComp = () => {
|
|
139
|
+
const dispatch = useDispatchWithErrorHandling();
|
|
140
|
+
dispatch({
|
|
141
|
+
action: { type: "testing" },
|
|
142
|
+
errorTitle: "title",
|
|
143
|
+
errorDescription: "desc",
|
|
144
|
+
validationLookupModule: "order",
|
|
145
|
+
validationLookupName: "ValidationsOrderReturns",
|
|
146
|
+
});
|
|
147
|
+
return null;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const component = (
|
|
151
|
+
<Provider store={store}>
|
|
152
|
+
<TestComp />
|
|
153
|
+
</Provider>
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
mount(component);
|
|
157
|
+
|
|
158
|
+
delay().then(() => {
|
|
159
|
+
expect(dispatchSpy.callCount, "to be", 2);
|
|
160
|
+
expect(dispatchSpy, "to have a call satisfying", {
|
|
161
|
+
args: [
|
|
162
|
+
pushGlobalErrorMessage({
|
|
163
|
+
title: "title",
|
|
164
|
+
description: "desc",
|
|
165
|
+
messages: [],
|
|
166
|
+
}),
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("dispatch new message with only title because msg list is filled", () => {
|
|
173
|
+
dispatchSpy.resolves({
|
|
174
|
+
error: true,
|
|
175
|
+
payload: {
|
|
176
|
+
status: 500,
|
|
177
|
+
response: {
|
|
178
|
+
errors: [
|
|
179
|
+
{
|
|
180
|
+
message: "msg",
|
|
181
|
+
lookupModule: "mod",
|
|
182
|
+
lookupName: "name",
|
|
183
|
+
lookupKey: "key",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const TestComp = () => {
|
|
191
|
+
const dispatch = useDispatchWithErrorHandling();
|
|
192
|
+
dispatch({
|
|
193
|
+
action: { type: "testing" },
|
|
194
|
+
errorTitle: "title",
|
|
195
|
+
errorDescription: "desc",
|
|
196
|
+
validationLookupModule: "order",
|
|
197
|
+
validationLookupName: "ValidationsOrderReturns",
|
|
198
|
+
});
|
|
199
|
+
return null;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const component = (
|
|
203
|
+
<Provider store={store}>
|
|
204
|
+
<TestComp />
|
|
205
|
+
</Provider>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
mount(component);
|
|
209
|
+
|
|
210
|
+
delay().then(() => {
|
|
211
|
+
expect(dispatchSpy.callCount, "to be", 2);
|
|
212
|
+
expect(dispatchSpy, "to have a call satisfying", {
|
|
213
|
+
args: [
|
|
214
|
+
pushGlobalErrorMessage({
|
|
215
|
+
title: "title",
|
|
216
|
+
description: null,
|
|
217
|
+
messages: [
|
|
218
|
+
{
|
|
219
|
+
message: "msg",
|
|
220
|
+
lookupModule: "mod",
|
|
221
|
+
lookupName: "name",
|
|
222
|
+
lookupKey: "key",
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
}),
|
|
226
|
+
],
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Immutable from "immutable";
|
|
2
|
+
import { POP_GLOBAL_ERROR_MESSAGE, PUSH_GLOBAL_ERROR_MESSAGE } from "../actions/globalErrorMessages";
|
|
3
|
+
|
|
4
|
+
const initialState = Immutable.fromJS({
|
|
5
|
+
dialog: {
|
|
6
|
+
errorMessages: [],
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const globalErrorMessages = (state = initialState, action) => {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case PUSH_GLOBAL_ERROR_MESSAGE: {
|
|
13
|
+
const newMsgs = state.getIn(["dialog", "errorMessages"]).push(Immutable.fromJS(action.payload));
|
|
14
|
+
return state.setIn(["dialog", "errorMessages"], newMsgs);
|
|
15
|
+
}
|
|
16
|
+
case POP_GLOBAL_ERROR_MESSAGE: {
|
|
17
|
+
const newMsgs = state.getIn(["dialog", "errorMessages"]).shift();
|
|
18
|
+
return state.setIn(["dialog", "errorMessages"], newMsgs);
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default globalErrorMessages;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Immutable from "immutable";
|
|
2
|
+
import reducer from "./globalErrorMessages";
|
|
3
|
+
import { popGlobalErrorMessage, pushGlobalErrorMessage } from "../actions/globalErrorMessages";
|
|
4
|
+
|
|
5
|
+
describe("Global error messages reducer", () => {
|
|
6
|
+
it("behaves as a reducer should", () =>
|
|
7
|
+
expect(reducer, "to be a reducer with initial state", {
|
|
8
|
+
dialog: {
|
|
9
|
+
errorMessages: [],
|
|
10
|
+
},
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
it("save new message to end of the list", () => {
|
|
14
|
+
const oldState = Immutable.fromJS({
|
|
15
|
+
dialog: {
|
|
16
|
+
errorMessages: [{ msg: "123" }],
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const action = pushGlobalErrorMessage({ msg: "456" });
|
|
20
|
+
const newState = reducer(oldState, action);
|
|
21
|
+
expect(newState, "not to be", oldState).and(
|
|
22
|
+
"to equal",
|
|
23
|
+
Immutable.fromJS({
|
|
24
|
+
dialog: {
|
|
25
|
+
errorMessages: [{ msg: "123" }, { msg: "456" }],
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("remove oldest message", () => {
|
|
32
|
+
const oldState = Immutable.fromJS({
|
|
33
|
+
dialog: {
|
|
34
|
+
errorMessages: [{ msg: "123" }, { msg: "456" }],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
const action = popGlobalErrorMessage();
|
|
38
|
+
const newState = reducer(oldState, action);
|
|
39
|
+
expect(newState, "not to be", oldState).and(
|
|
40
|
+
"to equal",
|
|
41
|
+
Immutable.fromJS({
|
|
42
|
+
dialog: {
|
|
43
|
+
errorMessages: [{ msg: "456" }],
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("remove oldest message on an empty list", () => {
|
|
50
|
+
const oldState = Immutable.fromJS({
|
|
51
|
+
dialog: {
|
|
52
|
+
errorMessages: [],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const action = popGlobalErrorMessage();
|
|
56
|
+
const newState = reducer(oldState, action);
|
|
57
|
+
expect(newState, "to be", oldState).and(
|
|
58
|
+
"to equal",
|
|
59
|
+
Immutable.fromJS({
|
|
60
|
+
dialog: {
|
|
61
|
+
errorMessages: [],
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createSelector } from "reselect";
|
|
2
|
+
|
|
3
|
+
const globalMsgData = state => state.get("globalErrorMessages");
|
|
4
|
+
|
|
5
|
+
export const firstDialogErrorMessageSelector = createSelector(globalMsgData, data => {
|
|
6
|
+
const msgs = data.getIn(["dialog", "errorMessages"]);
|
|
7
|
+
if (msgs.size === 0) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return msgs.first().toJS();
|
|
11
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Immutable from "immutable";
|
|
2
|
+
import { firstDialogErrorMessageSelector } from "./globalErrorMessages";
|
|
3
|
+
|
|
4
|
+
describe("firstDialogErrorMessageSelector", () => {
|
|
5
|
+
let state;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
state = Immutable.fromJS({
|
|
8
|
+
globalErrorMessages: {
|
|
9
|
+
dialog: {
|
|
10
|
+
errorMessages: [{ msg: "123" }, { msg: "456" }],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
view: {},
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("gets the first message", () => {
|
|
18
|
+
expect(firstDialogErrorMessageSelector, "called with", [state], "to satisfy", { msg: "123" });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("gets the first message on an empty list", () => {
|
|
22
|
+
state = state.setIn(["globalErrorMessages", "dialog", "errorMessages"], Immutable.fromJS([]));
|
|
23
|
+
expect(firstDialogErrorMessageSelector, "called with", [state], "to satisfy", null);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const extractStandardErrorMessagesFromResponse = (response, validationLookupModule, validationLookupName) => {
|
|
2
|
+
let hasErrors = false;
|
|
3
|
+
const messages = [];
|
|
4
|
+
|
|
5
|
+
if (response?.error) {
|
|
6
|
+
hasErrors = true;
|
|
7
|
+
|
|
8
|
+
if (response.payload?.status === 422) {
|
|
9
|
+
if (response.payload?.response?.failures) {
|
|
10
|
+
// uses structure from our .Net ValidationFailuresExceptionHandler
|
|
11
|
+
response.payload.response.failures.forEach(failure => {
|
|
12
|
+
if (failure.errorCode) {
|
|
13
|
+
messages.push({
|
|
14
|
+
message: failure.errorMessage,
|
|
15
|
+
lookupModule: validationLookupModule,
|
|
16
|
+
lookupName: validationLookupName,
|
|
17
|
+
lookupKey: failure.errorCode,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
} else if (response.payload?.status === 500) {
|
|
23
|
+
if (response.payload?.response?.errors) {
|
|
24
|
+
// uses structure from our .Net OrckestraExceptionErrorHandler
|
|
25
|
+
response.payload.response.errors.forEach(err => {
|
|
26
|
+
messages.push({
|
|
27
|
+
message: err.message,
|
|
28
|
+
lookupModule: err.lookupModule,
|
|
29
|
+
lookupName: err.lookupName,
|
|
30
|
+
lookupKey: err.lookupKey,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
hasErrors,
|
|
39
|
+
messages,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { extractStandardErrorMessagesFromResponse } from "./responseProcessingHelper";
|
|
2
|
+
|
|
3
|
+
describe("extractStandardErrorMessagesFromResponse", () => {
|
|
4
|
+
it("Returns success when response is null", () => {
|
|
5
|
+
const response = null;
|
|
6
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
7
|
+
expect(extractedMessages, "to equal", {
|
|
8
|
+
hasErrors: false,
|
|
9
|
+
messages: [],
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("Returns success when response is empty", () => {
|
|
14
|
+
const response = {};
|
|
15
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
16
|
+
|
|
17
|
+
expect(extractedMessages, "to equal", {
|
|
18
|
+
hasErrors: false,
|
|
19
|
+
messages: [],
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("Returns success when response is not on error", () => {
|
|
24
|
+
const response = {
|
|
25
|
+
error: false,
|
|
26
|
+
};
|
|
27
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
28
|
+
|
|
29
|
+
expect(extractedMessages, "to equal", {
|
|
30
|
+
hasErrors: false,
|
|
31
|
+
messages: [],
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("Returns error with empty messages with 422 error", () => {
|
|
36
|
+
const response = {
|
|
37
|
+
error: true,
|
|
38
|
+
payload: {
|
|
39
|
+
status: 422,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
43
|
+
|
|
44
|
+
expect(extractedMessages, "to equal", {
|
|
45
|
+
hasErrors: true,
|
|
46
|
+
messages: [],
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("Returns error with empty messages with 422 error because empty failures", () => {
|
|
51
|
+
const response = {
|
|
52
|
+
error: true,
|
|
53
|
+
payload: {
|
|
54
|
+
status: 422,
|
|
55
|
+
failures: [],
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
59
|
+
|
|
60
|
+
expect(extractedMessages, "to equal", {
|
|
61
|
+
hasErrors: true,
|
|
62
|
+
messages: [],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("Returns error with empty messages with 422 errors", () => {
|
|
67
|
+
const response = {
|
|
68
|
+
error: true,
|
|
69
|
+
payload: {
|
|
70
|
+
status: 422,
|
|
71
|
+
response: {
|
|
72
|
+
failures: [
|
|
73
|
+
{ invalid: "format" },
|
|
74
|
+
{ errorCode: "code1", errorMessage: "msg1" },
|
|
75
|
+
{ errorCode: "code2", errorMessage: "msg2" },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
81
|
+
|
|
82
|
+
expect(extractedMessages, "to equal", {
|
|
83
|
+
hasErrors: true,
|
|
84
|
+
messages: [
|
|
85
|
+
{ message: "msg1", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "code1" },
|
|
86
|
+
{ message: "msg2", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "code2" },
|
|
87
|
+
],
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("Returns error with empty messages with 422 errors", () => {
|
|
92
|
+
const response = {
|
|
93
|
+
error: true,
|
|
94
|
+
payload: {
|
|
95
|
+
status: 422,
|
|
96
|
+
response: {
|
|
97
|
+
failures: [
|
|
98
|
+
{ invalid: "format" },
|
|
99
|
+
{ errorCode: "code1", errorMessage: "msg1" },
|
|
100
|
+
{ errorCode: "code2", errorMessage: "msg2" },
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
106
|
+
|
|
107
|
+
expect(extractedMessages, "to equal", {
|
|
108
|
+
hasErrors: true,
|
|
109
|
+
messages: [
|
|
110
|
+
{ message: "msg1", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "code1" },
|
|
111
|
+
{ message: "msg2", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "code2" },
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("Returns error with empty messages with 500 status but no messages", () => {
|
|
117
|
+
const response = {
|
|
118
|
+
error: true,
|
|
119
|
+
payload: {
|
|
120
|
+
status: 500,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
124
|
+
|
|
125
|
+
expect(extractedMessages, "to equal", {
|
|
126
|
+
hasErrors: true,
|
|
127
|
+
messages: [],
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("Returns error with empty messages with 500 status without payload", () => {
|
|
132
|
+
const response = {
|
|
133
|
+
error: true,
|
|
134
|
+
};
|
|
135
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
136
|
+
|
|
137
|
+
expect(extractedMessages, "to equal", {
|
|
138
|
+
hasErrors: true,
|
|
139
|
+
messages: [],
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("Returns error with empty messages with 500 with empty messages", () => {
|
|
144
|
+
const response = {
|
|
145
|
+
error: true,
|
|
146
|
+
payload: {
|
|
147
|
+
status: 500,
|
|
148
|
+
errors: [],
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
152
|
+
|
|
153
|
+
expect(extractedMessages, "to equal", {
|
|
154
|
+
hasErrors: true,
|
|
155
|
+
messages: [],
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("Returns error with empty messages with 500 with messages", () => {
|
|
160
|
+
const response = {
|
|
161
|
+
error: true,
|
|
162
|
+
payload: {
|
|
163
|
+
status: 500,
|
|
164
|
+
response: {
|
|
165
|
+
errors: [
|
|
166
|
+
{ message: "msg1", lookupModule: "mod2", lookupName: "name3", lookupKey: "key4" },
|
|
167
|
+
{ message: "", lookupModule: "mod5", lookupName: "name5", lookupKey: "key5" },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
|
|
173
|
+
|
|
174
|
+
expect(extractedMessages, "to equal", {
|
|
175
|
+
hasErrors: true,
|
|
176
|
+
messages: [
|
|
177
|
+
{ message: "msg1", lookupModule: "mod2", lookupName: "name3", lookupKey: "key4" },
|
|
178
|
+
{ message: "", lookupModule: "mod5", lookupName: "name5", lookupKey: "key5" },
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|