Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the dependencies and make it work with Neo4j 3.x #210

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib-new/errors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ $ = require 'underscore'
assert = require 'assert'
http = require 'http'

class @Error extends Error
class @Error extends global.Error

constructor: (@message='Unknown error', @neo4j={}) ->
@name = 'neo4j.' + @constructor.name
Error.captureStackTrace @, @constructor
global.Error.captureStackTrace @, @constructor

#
# Accepts the given HTTP client response, and if it represents an error,
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
],
"main": "./lib-new/exports",
"dependencies": {
"request": "^2.27.0",
"underscore": "1.7.x"
"request": "^2.78.0",
"underscore": "1.8.x"
},
"devDependencies": {
"chai": "^1.9.2",
"coffee-script": "1.8.x",
"coffeelint": "^1.9.7",
"mocha": "^2.0.1",
"streamline": "^0.10.16"
"chai": "^3.5.0",
"coffee-script": "1.11.x",
"coffeelint": "^1.16.0",
"mocha": "^3.1.2",
"streamline": "^2.0.13"
},
"engines": {
"node": ">= 0.10"
Expand Down
18 changes: 9 additions & 9 deletions test-new/_auth._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ describe 'Auth', ->
# NOTE: Explicitly not using `db.checkPasswordChangeNeeded` since that
# rejects calls when no auth is set.
db.http '/db/data/', (err, data) ->
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Security',
'AuthorizationFailed', 'No authorization header supplied.'
expect(data).to.not.exist()
'Unauthorized', 'No authentication header supplied.'
expect(data).to.not.exist
done()

it 'should fail when auth is incorrect (username)', (done) ->
Expand All @@ -85,10 +85,10 @@ describe 'Auth', ->
db.auth.username = RANDOM_PASSWORD

db.checkPasswordChangeNeeded (err, bool) ->
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Security',
'AuthorizationFailed', 'Invalid username or password.'
expect(bool).to.not.exist()
'Unauthorized', 'Invalid username or password.'
expect(bool).to.not.exist
done()

it 'should fail when auth is incorrect (password)', (done) ->
Expand All @@ -99,10 +99,10 @@ describe 'Auth', ->
db.auth.password = RANDOM_PASSWORD

db.checkPasswordChangeNeeded (err, bool) ->
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Security',
'AuthorizationFailed', 'Invalid username or password.'
expect(bool).to.not.exist()
'Unauthorized', 'Invalid username or password.'
expect(bool).to.not.exist
done()

it 'should support checking whether a password change is needed', (_) ->
Expand Down
6 changes: 3 additions & 3 deletions test-new/constraints._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ describe 'Constraints', ->

it '(verify with test query)', (done) ->
violateConstraint (err) ->
expect(err).to.exist()
expect(err).to.exist

helpers.expectError err,
'ClientError', 'Schema', 'ConstraintViolation',
'ClientError', 'Schema', 'ConstraintValidationFailed',
"Node #{TEST_NODE_A._id} already exists
with label #{TEST_LABEL}
and property \"#{TEST_PROP}\"=[#{TEST_NODE_A._id}]"
Expand All @@ -166,7 +166,7 @@ describe 'Constraints', ->
property: TEST_PROP
, _

expect(constraint).to.not.exist()
expect(constraint).to.not.exist

it 'should support dropping constraint', (_) ->
dropped = DB.dropConstraint
Expand Down
2 changes: 1 addition & 1 deletion test-new/constructor._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ expectAuth = (db, username, password) ->
expect(db.auth).to.eql {username, password}

expectNoAuth = (db) ->
expect(db.auth).to.not.exist()
expect(db.auth).to.not.exist


## TESTS
Expand Down
16 changes: 8 additions & 8 deletions test-new/cypher._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe 'GraphDatabase::cypher', ->
params: {unused: 'param'}
, _

expect(results).to.be.empty()
expect(results).to.be.empty

it 'should reject empty/missing queries', ->
fail = -> throw new Error 'Callback should not have been called'
Expand All @@ -91,7 +91,7 @@ describe 'GraphDatabase::cypher', ->

it 'should properly parse and throw Neo4j errors', (done) ->
DB.cypher 'RETURN {foo}', (err, results) ->
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Statement',
'ParameterMissing', 'Expected a parameter named foo'

Expand All @@ -101,23 +101,23 @@ describe 'GraphDatabase::cypher', ->
# before the error. In this case, the query began execution,
# so we expect an array, but no actual results.
expect(results).to.be.an 'array'
expect(results).to.be.empty()
expect(results).to.be.empty

done()

it 'should properly return null result on syntax errors', (done) ->
DB.cypher '(syntax error)', (err, results) ->
expect(err).to.exist()
expect(err).to.exist

# Simplified error checking, since the message is complex:
expect(err).to.be.an.instanceOf neo4j.ClientError
expect(err.neo4j).to.be.an 'object'
expect(err.neo4j.code).to.equal \
'Neo.ClientError.Statement.InvalidSyntax'
'Neo.ClientError.Statement.SyntaxError'

# Unlike the previous test case, since Neo4j could not be
# executed, no results should have been returned at all:
expect(results).to.not.exist()
expect(results).to.not.exist

done()

Expand Down Expand Up @@ -251,7 +251,7 @@ describe 'GraphDatabase::cypher', ->
idR: TEST_REL._id
]
, (err, results) ->
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Statement',
'ParameterMissing', 'Expected a parameter named foo'

Expand All @@ -270,7 +270,7 @@ describe 'GraphDatabase::cypher', ->
expect(resultsA).to.eql [
a: TEST_NODE_A.properties
]
expect(resultsB).to.be.empty()
expect(resultsB).to.be.empty

done()

Expand Down
12 changes: 6 additions & 6 deletions test-new/http._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ describe 'GraphDatabase::http', ->
method: 'POST'
path: '/'
, (err, body) ->
expect(err).to.exist()
expect(body).to.not.exist()
expect(err).to.exist
expect(body).to.not.exist

helpers.expectRawError err, 'ClientError',
'405 Method Not Allowed response for POST /'
Expand All @@ -122,8 +122,8 @@ describe 'GraphDatabase::http', ->
method: 'GET'
path: '/db/data/node/-1'
, (err, body) ->
expect(err).to.exist()
expect(body).to.not.exist()
expect(err).to.exist
expect(body).to.not.exist

# Neo4j 2.2 returns a proper new-style error object for this case,
# but previous versions return an old-style error.
Expand Down Expand Up @@ -168,8 +168,8 @@ describe 'GraphDatabase::http', ->
path: '/'
raw: true
, (err, resp) ->
expect(err).to.exist()
expect(resp).to.not.exist()
expect(err).to.exist
expect(resp).to.not.exist

# NOTE: *Not* using our `expectError` helpers here, because we
# explicitly don't wrap native (non-Neo4j) errors.
Expand Down
6 changes: 3 additions & 3 deletions test-new/indexes._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ describe 'Indexes', ->
# So we explicitly guard against that, and just continue then.
# TODO: Would be nice to test the index another way...
try
expect(err).to.exist()
expect(results).to.not.exist()
expect(err).to.exist
expect(results).to.not.exist
catch assertionErr
# HACK: Because this test isn't a Streamline function,
# relying on `fixtures.queryDbVersion` having been called
Expand Down Expand Up @@ -205,7 +205,7 @@ describe 'Indexes', ->
property: TEST_PROP
, _

expect(index).to.not.exist()
expect(index).to.not.exist

it 'should support dropping index', (_) ->
dropped = DB.dropIndex
Expand Down
6 changes: 3 additions & 3 deletions test-new/schema._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ describe 'Schema', ->
labels = DB.getLabels _

expect(labels).to.be.an 'array'
expect(labels).to.not.be.empty()
expect(labels).to.not.be.empty
expect(labels).to.contain TEST_LABEL

it 'should support listing all property keys', (_) ->
keys = DB.getPropertyKeys _

expect(keys).to.be.an 'array'
expect(keys).to.not.be.empty()
expect(keys).to.not.be.empty

for key of TEST_NODE_A.properties
expect(keys).to.contain key
Expand All @@ -43,7 +43,7 @@ describe 'Schema', ->
types = DB.getRelationshipTypes _

expect(types).to.be.an 'array'
expect(types).to.not.be.empty()
expect(types).to.not.be.empty
expect(types).to.contain TEST_REL_TYPE

it '(delete test graph)', (_) ->
Expand Down
26 changes: 14 additions & 12 deletions test-new/transactions._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe 'Transactions', ->
expect(tx.state).to.equal tx.STATE_PENDING

cb = (err, results) ->
expect(err).to.not.exist()
expect(err).to.not.exist
expect(tx.state).to.equal tx.STATE_OPEN
done()

Expand Down Expand Up @@ -165,7 +165,7 @@ describe 'Transactions', ->
params: {properties}
, _

expect(results).to.be.empty()
expect(results).to.be.empty

it 'should support committing, and reject subsequent requests', (_) ->
tx = beginTx()
Expand Down Expand Up @@ -390,7 +390,7 @@ describe 'Transactions', ->
params:
idA: TEST_NODE_A._id
, (err, results) =>
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Statement',
'ParameterMissing', 'Expected a parameter named foo'
cont()
Expand Down Expand Up @@ -484,7 +484,7 @@ describe 'Transactions', ->
params:
idA: TEST_NODE_A._id
, (err, results) ->
expect(err).to.exist()
expect(err).to.exist
# NOTE: Deadlock detected messages aren't predictable,
# so having the assertion for it simply check itself:
helpers.expectError err, 'TransientError', 'Transaction',
Expand All @@ -504,7 +504,9 @@ describe 'Transactions', ->
expect(nodeB.properties.test).to.not.equal 'transient errors'
expect(nodeB.properties.tx).to.equal 1

it 'should properly handle (fatal) database errors', (_) ->
# TODO: Skipping this test for now, because the hack used here has been
# fixed, and this is not crucial, unique test coverage.
it.skip 'should properly handle (fatal) database errors', (_) ->
tx = beginTx()

# Important: don't auto-commit in the first query, because that doesn't
Expand Down Expand Up @@ -533,7 +535,7 @@ describe 'Transactions', ->
params:
props: {foo: null}
, (err, results) =>
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err,
'DatabaseError', 'Statement', 'ExecutionFailure',
'scala.MatchError: (foo,null) (of class scala.Tuple2)'
Expand Down Expand Up @@ -588,7 +590,7 @@ describe 'Transactions', ->
idA: TEST_NODE_A._id
commit: true
, (err, results) =>
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Statement',
'ParameterMissing', 'Expected a parameter named foo'
cont()
Expand All @@ -603,7 +605,7 @@ describe 'Transactions', ->
# For precision, implementing this step without Streamline.
do (cont=_) =>
tx.cypher 'RETURN {foo}', (err, results) =>
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Statement',
'ParameterMissing', 'Expected a parameter named foo'
cont()
Expand All @@ -624,7 +626,7 @@ describe 'Transactions', ->
query: 'RETURN {foo}'
commit: true
, (err, results) =>
expect(err).to.exist()
expect(err).to.exist
helpers.expectError err, 'ClientError', 'Statement',
'ParameterMissing', 'Expected a parameter named foo'
cont()
Expand Down Expand Up @@ -659,7 +661,7 @@ describe 'Transactions', ->
for result in results
expect(result).to.be.an 'array'

expect(results[0]).to.be.empty()
expect(results[0]).to.be.empty
expect(results[1]).to.have.length 1

[{nodeA}] = results[1]
Expand Down Expand Up @@ -694,13 +696,13 @@ describe 'Transactions', ->
idA: TEST_NODE_A._id
]
, (err, results) =>
expect(err).to.exist()
expect(err).to.exist

# Simplified error checking, since the message is complex:
expect(err).to.be.an.instanceOf neo4j.ClientError
expect(err.neo4j).to.be.an 'object'
expect(err.neo4j.code).to.equal \
'Neo.ClientError.Statement.InvalidSyntax'
'Neo.ClientError.Statement.SyntaxError'

expect(results).to.be.an 'array'
expect(results).to.have.length 1
Expand Down
6 changes: 3 additions & 3 deletions test-new/util/helpers._coffee
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ exports.expectOldError = (err, statusCode, shortName, longName, message) ->
message: message

expect(err.neo4j.stacktrace).to.be.an 'array'
expect(err.neo4j.stacktrace).to.not.be.empty()
expect(err.neo4j.stacktrace).to.not.be.empty
for line in err.neo4j.stacktrace
expect(line).to.be.a 'string'
expect(line).to.not.be.empty()
expect(line).to.not.be.empty


#
Expand All @@ -118,7 +118,7 @@ exports.expectRawError = (err, classification, message) ->
throw new Error "Unrecognized type of expected `message`:
#{typeof message} / #{message?.constructor.name}"

expect(err.neo4j).to.be.empty() # TODO: Should this really be the case?
expect(err.neo4j).to.be.empty # TODO: Should this really be the case?


#
Expand Down