Skip to content

Commit

Permalink
Merge pull request #1007 from oskarhane/fix-use-behaviour
Browse files Browse the repository at this point in the history
Check if db exists before switching to it, throw if not
  • Loading branch information
oskarhane authored Dec 4, 2019
2 parents 80fb640 + 582669a commit 5fab1c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions e2e_tests/integration/multi-db.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,13 @@ describe('Multi database', () => {
.first()
resultFrame.should('contain', 'cannot be declared')
})
it('shows error when trying to use a db that doesnt exist', () => {
cy.executeCommand(':clear')
cy.executeCommand(':use nonexistingdb')
const resultFrame = cy
.get('[data-testid="frame"]', { timeout: 10000 })
.first()
resultFrame.should('contain', 'could not be found')
})
}
})
11 changes: 11 additions & 0 deletions src/shared/services/commandInterpreterHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ const availableCommands = [
'No multi db support detected.'
)
}
const databaseNames = getDatabases(store.getState()).map(db =>
db.name.toLowerCase()
)
// Do we have a db with that name?
if (!databaseNames.includes(dbName.toLowerCase())) {
const error = new Error(
`A database with the "${dbName}" name could not be found.`
)
error.code = 'NotFound'
throw error
}
put(useDb(dbName))
put(
frames.add({
Expand Down

0 comments on commit 5fab1c8

Please sign in to comment.