Skip to content

Commit e01d2db

Browse files
committed
update error frame tests
1 parent b241700 commit e01d2db

File tree

6 files changed

+238
-16
lines changed

6 files changed

+238
-16
lines changed

src/browser/modules/Stream/CypherFrame/CypherFrame.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ describe('CypherFrame', () => {
6262
maxRows: 1000,
6363
maxFieldItems: 1000
6464
},
65-
app: {}
65+
app: {},
66+
connections: {}
6667
})
6768
}
6869
test('renders accordingly from pending to success to error to success', () => {

src/browser/modules/Stream/CypherFrame/ErrorsView/ErrorsView.test.tsx

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
*/
2020
import { render } from '@testing-library/react'
2121
import React from 'react'
22-
import { combineReducers, createStore } from 'redux'
2322
import { createBus } from 'suber'
2423

2524
import { ErrorsView, ErrorsViewProps } from './ErrorsView'
26-
import reducers from 'project-root/src/shared/rootReducer'
2725
import { BrowserError } from 'services/exceptions'
26+
import { Provider } from 'react-redux'
27+
import { initialState as initialConnectionsState } from 'shared/modules/connections/connectionsDuck'
2828

29-
const mount = (partOfProps: Partial<ErrorsViewProps>) => {
29+
const withProvider = (store: any, children: any) => {
30+
return <Provider store={store}>{children}</Provider>
31+
}
32+
33+
const mount = (partOfProps: Partial<ErrorsViewProps>, state?: any) => {
3034
const defaultProps: ErrorsViewProps = {
3135
result: null,
3236
bus: createBus(),
@@ -36,13 +40,25 @@ const mount = (partOfProps: Partial<ErrorsViewProps>) => {
3640
neo4jVersion: null,
3741
protocolVersion: null
3842
}
43+
3944
const props = {
4045
...defaultProps,
4146
...partOfProps
4247
}
43-
const reducer = combineReducers({ ...(reducers as any) })
44-
const store: any = createStore(reducer)
45-
return render(<ErrorsView store={store} {...props} />)
48+
49+
state = state ?? {
50+
connections: initialConnectionsState
51+
}
52+
53+
const store = {
54+
subscribe: () => {},
55+
dispatch: () => {},
56+
getState: () => ({
57+
...state
58+
})
59+
}
60+
61+
return render(withProvider(store, <ErrorsView {...props} />))
4662
}
4763

4864
describe('ErrorsView', () => {
@@ -58,7 +74,8 @@ describe('ErrorsView', () => {
5874
// Then
5975
expect(container).toMatchSnapshot()
6076
})
61-
test('does displays an error', () => {
77+
78+
test('does display an error', () => {
6279
// Given
6380
const error: BrowserError = {
6481
code: 'Test.Error',
@@ -75,6 +92,84 @@ describe('ErrorsView', () => {
7592
// Then
7693
expect(container).toMatchSnapshot()
7794
})
95+
96+
test('does display an error for gql status codes', () => {
97+
// Given
98+
const error: BrowserError = {
99+
code: 'Test.Error',
100+
message: 'Test error description',
101+
type: 'Neo4jError',
102+
gqlStatus: '22N14',
103+
gqlStatusDescription:
104+
"error: data exception - invalid temporal value combination. Cannot select both epochSeconds and 'datetime'.",
105+
cause: undefined
106+
}
107+
108+
const props = {
109+
result: error
110+
}
111+
112+
const state = {
113+
connections: {
114+
activeConnection: 'test',
115+
connectionsById: {
116+
test: {
117+
protocolVersion: 5.7
118+
}
119+
}
120+
}
121+
}
122+
123+
// When
124+
const { container } = mount(props, state)
125+
126+
// Then
127+
expect(container).toMatchSnapshot()
128+
})
129+
130+
test('does display a nested error for gql status codes', () => {
131+
// Given
132+
const error: BrowserError = {
133+
code: 'Test.Error',
134+
message: 'Test error description',
135+
type: 'Neo4jError',
136+
gqlStatus: '42N51',
137+
gqlStatusDescription:
138+
'error: syntax error or access rule violation - invalid parameter. Invalid parameter $`param`. ',
139+
cause: {
140+
gqlStatus: '22G03',
141+
gqlStatusDescription: 'error: data exception - invalid value type',
142+
cause: {
143+
gqlStatus: '22N27',
144+
gqlStatusDescription:
145+
"error: data exception - invalid entity type. Invalid input '******' for $`param`. Expected to be STRING.",
146+
cause: undefined
147+
}
148+
}
149+
}
150+
151+
const props = {
152+
result: error
153+
}
154+
155+
const state = {
156+
connections: {
157+
activeConnection: 'test',
158+
connectionsById: {
159+
test: {
160+
protocolVersion: 5.7
161+
}
162+
}
163+
}
164+
}
165+
166+
// When
167+
const { container } = mount(props, state)
168+
169+
// Then
170+
expect(container).toMatchSnapshot()
171+
})
172+
78173
test('displays procedure link if unknown procedure', () => {
79174
// Given
80175
const error: BrowserError = {
@@ -93,6 +188,7 @@ describe('ErrorsView', () => {
93188
expect(container).toMatchSnapshot()
94189
expect(getByText('List available procedures')).not.toBeUndefined()
95190
})
191+
96192
test('displays procedure link if periodic commit error', () => {
97193
// Given
98194
const error: BrowserError = {

src/browser/modules/Stream/CypherFrame/ErrorsView/__snapshots__/ErrorsView.test.tsx.snap

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`ErrorsView displays nothing if no errors 1`] = `<div />`;
55
exports[`ErrorsView displays procedure link if unknown procedure 1`] = `
66
<div>
77
<div
8-
class="sc-kfPuZi hoSnpS"
8+
class="sc-kfPuZi kIbLHE"
99
>
1010
<div
1111
class="sc-fKVqWL hFvVsk"
@@ -52,10 +52,92 @@ exports[`ErrorsView displays procedure link if unknown procedure 1`] = `
5252
</div>
5353
`;
5454

55-
exports[`ErrorsView does displays an error 1`] = `
55+
exports[`ErrorsView does display a nested error for gql status codes 1`] = `
5656
<div>
5757
<div
58-
class="sc-kfPuZi hoSnpS"
58+
class="sc-kfPuZi kIbLHE"
59+
>
60+
<div
61+
class="sc-fKVqWL hFvVsk"
62+
>
63+
<div
64+
class="sc-bBHxTw cOKOWM"
65+
>
66+
<div
67+
class="sc-iJKOTD sc-ezbkAF hhmYSB fuiMKG"
68+
>
69+
ERROR
70+
</div>
71+
<h4
72+
class="sc-hiCibw HoeQn"
73+
>
74+
42N51: Syntax error or access rule violation - invalid parameter
75+
</h4>
76+
</div>
77+
<div
78+
class="sc-iwjdpV"
79+
>
80+
<pre
81+
class="sc-cCcXHH haCMIe"
82+
data-testid="cypherFrameErrorMessage"
83+
>
84+
Invalid parameter $\`param\`.
85+
</pre>
86+
</div>
87+
<div
88+
class="sc-kfPuZi eOKuNM"
89+
>
90+
<div
91+
class="sc-fKVqWL hFvVsk"
92+
>
93+
<div
94+
class="sc-bBHxTw cOKOWM"
95+
>
96+
<h4
97+
class="sc-hiCibw HoeQn"
98+
>
99+
22G03: Data exception - invalid value type
100+
</h4>
101+
</div>
102+
103+
<div
104+
class="sc-kfPuZi eOKuNM"
105+
>
106+
<div
107+
class="sc-fKVqWL hFvVsk"
108+
>
109+
<div
110+
class="sc-bBHxTw cOKOWM"
111+
>
112+
<h4
113+
class="sc-hiCibw HoeQn"
114+
>
115+
22N27: Data exception - invalid entity type
116+
</h4>
117+
</div>
118+
<div
119+
class="sc-iwjdpV"
120+
>
121+
<pre
122+
class="sc-cCcXHH haCMIe"
123+
data-testid="cypherFrameErrorMessage"
124+
>
125+
Invalid input '******' for $\`param\`. Expected to be STRING.
126+
</pre>
127+
</div>
128+
</div>
129+
</div>
130+
</div>
131+
</div>
132+
</div>
133+
</div>
134+
</div>
135+
`;
136+
137+
exports[`ErrorsView does display an error 1`] = `
138+
<div>
139+
<div
140+
class="sc-kfPuZi kIbLHE"
59141
>
60142
<div
61143
class="sc-fKVqWL hFvVsk"
@@ -88,3 +170,40 @@ exports[`ErrorsView does displays an error 1`] = `
88170
</div>
89171
</div>
90172
`;
173+
174+
exports[`ErrorsView does display an error for gql status codes 1`] = `
175+
<div>
176+
<div
177+
class="sc-kfPuZi kIbLHE"
178+
>
179+
<div
180+
class="sc-fKVqWL hFvVsk"
181+
>
182+
<div
183+
class="sc-bBHxTw cOKOWM"
184+
>
185+
<div
186+
class="sc-iJKOTD sc-ezbkAF hhmYSB fuiMKG"
187+
>
188+
ERROR
189+
</div>
190+
<h4
191+
class="sc-hiCibw HoeQn"
192+
>
193+
22N14: Data exception - invalid temporal value combination
194+
</h4>
195+
</div>
196+
<div
197+
class="sc-iwjdpV"
198+
>
199+
<pre
200+
class="sc-cCcXHH haCMIe"
201+
data-testid="cypherFrameErrorMessage"
202+
>
203+
Cannot select both epochSeconds and 'datetime'.
204+
</pre>
205+
</div>
206+
</div>
207+
</div>
208+
</div>
209+
`;

src/browser/modules/Stream/CypherFrame/__snapshots__/WarningsView.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`WarningsViews WarningsView displays nothing if no notifications 1`] = `
55
exports[`WarningsViews WarningsView does display a warning for GQL status codes 1`] = `
66
<div>
77
<div
8-
class="sc-hGPBjI kJlknP"
8+
class="sc-hGPBjI kgdIGh"
99
>
1010
<div
1111
class="sc-dlVxhl fwhZkz"
@@ -55,7 +55,7 @@ exports[`WarningsViews WarningsView does display a warning for GQL status codes
5555
exports[`WarningsViews WarningsView does display multiple warnings 1`] = `
5656
<div>
5757
<div
58-
class="sc-hGPBjI kJlknP"
58+
class="sc-hGPBjI kgdIGh"
5959
>
6060
<div
6161
class="sc-dlVxhl fwhZkz"
@@ -168,7 +168,7 @@ exports[`WarningsViews WarningsView does display multiple warnings 1`] = `
168168
exports[`WarningsViews WarningsView does display multiple warnings for GQL status codes 1`] = `
169169
<div>
170170
<div
171-
class="sc-hGPBjI kJlknP"
171+
class="sc-hGPBjI kgdIGh"
172172
>
173173
<div
174174
class="sc-dlVxhl fwhZkz"
@@ -259,7 +259,7 @@ exports[`WarningsViews WarningsView does display multiple warnings for GQL statu
259259
exports[`WarningsViews WarningsView does displays a warning 1`] = `
260260
<div>
261261
<div
262-
class="sc-hGPBjI kJlknP"
262+
class="sc-hGPBjI kgdIGh"
263263
>
264264
<div
265265
class="sc-dlVxhl fwhZkz"

src/browser/modules/Stream/CypherFrame/errorUtils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import { BrowserError } from 'services/exceptions'
2727

2828
export function isBrowserError(object: unknown): object is BrowserError {
2929
if (object !== null && typeof object === 'object') {
30-
return 'type' in object || 'gqlStatus' in object
30+
return (
31+
'type' in object ||
32+
'message' in object ||
33+
'code' in object ||
34+
'gqlStatus' in object
35+
)
3136
}
3237

3338
return false

src/shared/services/exceptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type BrowserError = {
3838
code: string
3939
gqlStatus?: string
4040
gqlStatusDescription?: string
41+
cause?: Pick<BrowserError, 'gqlStatus' | 'gqlStatusDescription' | 'cause'>
4142
}
4243

4344
// All errors except bolt errors have their type as their error code

0 commit comments

Comments
 (0)