Skip to content

Commit

Permalink
Fix issue where metadata is fetched when params are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
pe4cey committed Apr 20, 2018
1 parent 26d2de8 commit 95e44a1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
8 changes: 1 addition & 7 deletions e2e_tests/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,7 @@ describe('Neo4j Browser', () => {
it('will add parameter using `:param` command', () => {
// add cypher evalutated param function
const command = ':param foo => 1 + 1'
cy.get(Editor).type(command, { force: true })
cy.get(Editor).should('have.value', command)
cy.get(SubmitQueryButton).click()
cy
.get('[data-test-id="frameCommand"]')
.first()
.should('contain', command)
cy.executeCommand(command)
cy
.get('[data-test-id="rawParamData"]')
.first()
Expand Down
33 changes: 31 additions & 2 deletions src/shared/modules/commands/commandsDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,37 @@ describe('commandsDuck', () => {
const cmdString = cmd + ' x: 2'
const id = 1
const action = commands.executeCommand(cmdString, id)

bus.take('NOOP', currentAction => {
// Then
expect(store.getActions()).toEqual([
action,
addHistory(cmdString, maxHistory),
{ type: commands.KNOWN_COMMAND },
updateParams({ x: 2 }),
frames.add({
...action,
success: true,
type: 'param',
params: { x: 2 }
}),
{ type: 'NOOP' }
])
done()
})

// When
store.dispatch(action)

// Then
// See above
})
test('does the right thing for :param x => 2', done => {
// Given
const cmd = store.getState().settings.cmdchar + 'param'
const cmdString = cmd + ' x: 2'
const id = 1
const action = commands.executeCommand(cmdString, id)
bolt.routedWriteTransaction = jest.fn(() =>
Promise.resolve({
records: [{ get: () => 2 }]
Expand All @@ -163,7 +194,6 @@ describe('commandsDuck', () => {
type: 'param',
params: { x: 2 }
}),
{ type: 'meta/FORCE_FETCH' },
{ type: 'NOOP' }
])
done()
Expand All @@ -189,7 +219,6 @@ describe('commandsDuck', () => {
{ type: commands.KNOWN_COMMAND },
replaceParams({ x: 2, y: 3 }),
frames.add({ ...action, success: true, type: 'params', params: {} }),
{ type: 'meta/FORCE_FETCH' },
{ type: 'NOOP' }
])
done()
Expand Down
8 changes: 4 additions & 4 deletions src/shared/modules/commands/helpers/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ export const handleParamsCommand = (action, cmdchar, put) => {
}
} else {
// Single param
const { key, value, isFn } = extractParams(param)
if (!isFn || !key || !value) {
return resolveAndStoreJsonValue(param, put, resolve, reject)
}
try {
const { key, value, isFn } = extractParams(param)
if (!key || !value || !isFn) {
return resolveAndStoreJsonValue(param, put, resolve, reject)
}
const cypherStatement = mapParamToCypherStatement(key, value)
bolt
.routedWriteTransaction(
Expand Down
2 changes: 0 additions & 2 deletions src/shared/modules/commands/helpers/params.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ describe('commandsDuck params helper', () => {
})
test('handles :param "x": 2 and calls the update action creator', () => {
// Given
// jest.spyOn(params, , accessType?)

const action = { cmd: ':param "x": 2' }
const cmdchar = ':'
const put = jest.fn()
Expand Down
3 changes: 1 addition & 2 deletions src/shared/services/commandInterpreterHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
import { getRemoteContentHostnameWhitelist } from 'shared/modules/dbMeta/dbMetaDuck'
import { fetchRemoteGuide } from 'shared/modules/commands/helpers/play'
import remote from 'services/remote'
import bolt from 'services/bolt/bolt'
import { isLocalRequest, authHeaderFromCredentials } from 'services/remoteUtils'
import { handleServerCommand } from 'shared/modules/commands/helpers/server'
import { handleCypherCommand } from 'shared/modules/commands/helpers/cypher'
Expand Down Expand Up @@ -91,7 +90,7 @@ const availableCommands = [
name: 'set-params',
match: cmd => /^params?\s/.test(cmd),
exec: function (action, cmdchar, put, store) {
return handleParamsCommand(action, cmdchar, put, bolt)
handleParamsCommand(action, cmdchar, put)
.then(res => {
const params =
res.type === 'param' ? res.result : getParams(store.getState())
Expand Down

0 comments on commit 95e44a1

Please sign in to comment.