Skip to content

Commit

Permalink
update error frame tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daveajrussell committed Dec 10, 2024
1 parent b241700 commit e01d2db
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/browser/modules/Stream/CypherFrame/CypherFrame.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ describe('CypherFrame', () => {
maxRows: 1000,
maxFieldItems: 1000
},
app: {}
app: {},
connections: {}
})
}
test('renders accordingly from pending to success to error to success', () => {
Expand Down
110 changes: 103 additions & 7 deletions src/browser/modules/Stream/CypherFrame/ErrorsView/ErrorsView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
*/
import { render } from '@testing-library/react'
import React from 'react'
import { combineReducers, createStore } from 'redux'
import { createBus } from 'suber'

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

const mount = (partOfProps: Partial<ErrorsViewProps>) => {
const withProvider = (store: any, children: any) => {
return <Provider store={store}>{children}</Provider>
}

const mount = (partOfProps: Partial<ErrorsViewProps>, state?: any) => {
const defaultProps: ErrorsViewProps = {
result: null,
bus: createBus(),
Expand All @@ -36,13 +40,25 @@ const mount = (partOfProps: Partial<ErrorsViewProps>) => {
neo4jVersion: null,
protocolVersion: null
}

const props = {
...defaultProps,
...partOfProps
}
const reducer = combineReducers({ ...(reducers as any) })
const store: any = createStore(reducer)
return render(<ErrorsView store={store} {...props} />)

state = state ?? {
connections: initialConnectionsState
}

const store = {
subscribe: () => {},
dispatch: () => {},
getState: () => ({
...state
})
}

return render(withProvider(store, <ErrorsView {...props} />))
}

describe('ErrorsView', () => {
Expand All @@ -58,7 +74,8 @@ describe('ErrorsView', () => {
// Then
expect(container).toMatchSnapshot()
})
test('does displays an error', () => {

test('does display an error', () => {
// Given
const error: BrowserError = {
code: 'Test.Error',
Expand All @@ -75,6 +92,84 @@ describe('ErrorsView', () => {
// Then
expect(container).toMatchSnapshot()
})

test('does display an error for gql status codes', () => {
// Given
const error: BrowserError = {
code: 'Test.Error',
message: 'Test error description',
type: 'Neo4jError',
gqlStatus: '22N14',
gqlStatusDescription:
"error: data exception - invalid temporal value combination. Cannot select both epochSeconds and 'datetime'.",
cause: undefined
}

const props = {
result: error
}

const state = {
connections: {
activeConnection: 'test',
connectionsById: {
test: {
protocolVersion: 5.7
}
}
}
}

// When
const { container } = mount(props, state)

// Then
expect(container).toMatchSnapshot()
})

test('does display a nested error for gql status codes', () => {
// Given
const error: BrowserError = {
code: 'Test.Error',
message: 'Test error description',
type: 'Neo4jError',
gqlStatus: '42N51',
gqlStatusDescription:
'error: syntax error or access rule violation - invalid parameter. Invalid parameter $`param`. ',
cause: {
gqlStatus: '22G03',
gqlStatusDescription: 'error: data exception - invalid value type',
cause: {
gqlStatus: '22N27',
gqlStatusDescription:
"error: data exception - invalid entity type. Invalid input '******' for $`param`. Expected to be STRING.",
cause: undefined
}
}
}

const props = {
result: error
}

const state = {
connections: {
activeConnection: 'test',
connectionsById: {
test: {
protocolVersion: 5.7
}
}
}
}

// When
const { container } = mount(props, state)

// Then
expect(container).toMatchSnapshot()
})

test('displays procedure link if unknown procedure', () => {
// Given
const error: BrowserError = {
Expand All @@ -93,6 +188,7 @@ describe('ErrorsView', () => {
expect(container).toMatchSnapshot()
expect(getByText('List available procedures')).not.toBeUndefined()
})

test('displays procedure link if periodic commit error', () => {
// Given
const error: BrowserError = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`ErrorsView displays nothing if no errors 1`] = `<div />`;
exports[`ErrorsView displays procedure link if unknown procedure 1`] = `
<div>
<div
class="sc-kfPuZi hoSnpS"
class="sc-kfPuZi kIbLHE"
>
<div
class="sc-fKVqWL hFvVsk"
Expand Down Expand Up @@ -52,10 +52,92 @@ exports[`ErrorsView displays procedure link if unknown procedure 1`] = `
</div>
`;

exports[`ErrorsView does displays an error 1`] = `
exports[`ErrorsView does display a nested error for gql status codes 1`] = `
<div>
<div
class="sc-kfPuZi hoSnpS"
class="sc-kfPuZi kIbLHE"
>
<div
class="sc-fKVqWL hFvVsk"
>
<div
class="sc-bBHxTw cOKOWM"
>
<div
class="sc-iJKOTD sc-ezbkAF hhmYSB fuiMKG"
>
ERROR
</div>
<h4
class="sc-hiCibw HoeQn"
>
42N51: Syntax error or access rule violation - invalid parameter
</h4>
</div>
<div
class="sc-iwjdpV"
>
<pre
class="sc-cCcXHH haCMIe"
data-testid="cypherFrameErrorMessage"
>
Invalid parameter $\`param\`.
</pre>
</div>
<div
class="sc-kfPuZi eOKuNM"
>
<div
class="sc-fKVqWL hFvVsk"
>
<div
class="sc-bBHxTw cOKOWM"
>
<h4
class="sc-hiCibw HoeQn"
>
22G03: Data exception - invalid value type
</h4>
</div>
<div
class="sc-kfPuZi eOKuNM"
>
<div
class="sc-fKVqWL hFvVsk"
>
<div
class="sc-bBHxTw cOKOWM"
>
<h4
class="sc-hiCibw HoeQn"
>
22N27: Data exception - invalid entity type
</h4>
</div>
<div
class="sc-iwjdpV"
>
<pre
class="sc-cCcXHH haCMIe"
data-testid="cypherFrameErrorMessage"
>
Invalid input '******' for $\`param\`. Expected to be STRING.
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
`;

exports[`ErrorsView does display an error 1`] = `
<div>
<div
class="sc-kfPuZi kIbLHE"
>
<div
class="sc-fKVqWL hFvVsk"
Expand Down Expand Up @@ -88,3 +170,40 @@ exports[`ErrorsView does displays an error 1`] = `
</div>
</div>
`;

exports[`ErrorsView does display an error for gql status codes 1`] = `
<div>
<div
class="sc-kfPuZi kIbLHE"
>
<div
class="sc-fKVqWL hFvVsk"
>
<div
class="sc-bBHxTw cOKOWM"
>
<div
class="sc-iJKOTD sc-ezbkAF hhmYSB fuiMKG"
>
ERROR
</div>
<h4
class="sc-hiCibw HoeQn"
>
22N14: Data exception - invalid temporal value combination
</h4>
</div>
<div
class="sc-iwjdpV"
>
<pre
class="sc-cCcXHH haCMIe"
data-testid="cypherFrameErrorMessage"
>
Cannot select both epochSeconds and 'datetime'.
</pre>
</div>
</div>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`WarningsViews WarningsView displays nothing if no notifications 1`] = `
exports[`WarningsViews WarningsView does display a warning for GQL status codes 1`] = `
<div>
<div
class="sc-hGPBjI kJlknP"
class="sc-hGPBjI kgdIGh"
>
<div
class="sc-dlVxhl fwhZkz"
Expand Down Expand Up @@ -55,7 +55,7 @@ exports[`WarningsViews WarningsView does display a warning for GQL status codes
exports[`WarningsViews WarningsView does display multiple warnings 1`] = `
<div>
<div
class="sc-hGPBjI kJlknP"
class="sc-hGPBjI kgdIGh"
>
<div
class="sc-dlVxhl fwhZkz"
Expand Down Expand Up @@ -168,7 +168,7 @@ exports[`WarningsViews WarningsView does display multiple warnings 1`] = `
exports[`WarningsViews WarningsView does display multiple warnings for GQL status codes 1`] = `
<div>
<div
class="sc-hGPBjI kJlknP"
class="sc-hGPBjI kgdIGh"
>
<div
class="sc-dlVxhl fwhZkz"
Expand Down Expand Up @@ -259,7 +259,7 @@ exports[`WarningsViews WarningsView does display multiple warnings for GQL statu
exports[`WarningsViews WarningsView does displays a warning 1`] = `
<div>
<div
class="sc-hGPBjI kJlknP"
class="sc-hGPBjI kgdIGh"
>
<div
class="sc-dlVxhl fwhZkz"
Expand Down
7 changes: 6 additions & 1 deletion src/browser/modules/Stream/CypherFrame/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import { BrowserError } from 'services/exceptions'

export function isBrowserError(object: unknown): object is BrowserError {
if (object !== null && typeof object === 'object') {
return 'type' in object || 'gqlStatus' in object
return (
'type' in object ||
'message' in object ||
'code' in object ||
'gqlStatus' in object
)
}

return false
Expand Down
1 change: 1 addition & 0 deletions src/shared/services/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type BrowserError = {
code: string
gqlStatus?: string
gqlStatusDescription?: string
cause?: Pick<BrowserError, 'gqlStatus' | 'gqlStatusDescription' | 'cause'>
}

// All errors except bolt errors have their type as their error code
Expand Down

0 comments on commit e01d2db

Please sign in to comment.