diff --git a/lib-new/errors.coffee b/lib-new/errors.coffee index 681c78b..85b7a59 100644 --- a/lib-new/errors.coffee +++ b/lib-new/errors.coffee @@ -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, diff --git a/package.json b/package.json index 07aa6eb..1c78c93 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test-new/_auth._coffee b/test-new/_auth._coffee index 5d49b22..72c7665 100644 --- a/test-new/_auth._coffee +++ b/test-new/_auth._coffee @@ -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) -> @@ -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) -> @@ -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', (_) -> diff --git a/test-new/constraints._coffee b/test-new/constraints._coffee index fd5595a..e19b7ac 100644 --- a/test-new/constraints._coffee +++ b/test-new/constraints._coffee @@ -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}]" @@ -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 diff --git a/test-new/constructor._coffee b/test-new/constructor._coffee index b36d29f..247f976 100644 --- a/test-new/constructor._coffee +++ b/test-new/constructor._coffee @@ -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 diff --git a/test-new/cypher._coffee b/test-new/cypher._coffee index 45feacc..87ee271 100644 --- a/test-new/cypher._coffee +++ b/test-new/cypher._coffee @@ -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' @@ -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' @@ -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() @@ -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' @@ -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() diff --git a/test-new/http._coffee b/test-new/http._coffee index c6c1bda..a1b73bd 100644 --- a/test-new/http._coffee +++ b/test-new/http._coffee @@ -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 /' @@ -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. @@ -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. diff --git a/test-new/indexes._coffee b/test-new/indexes._coffee index c28dc07..358bcde 100644 --- a/test-new/indexes._coffee +++ b/test-new/indexes._coffee @@ -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 @@ -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 diff --git a/test-new/schema._coffee b/test-new/schema._coffee index 04a311f..2db8678 100644 --- a/test-new/schema._coffee +++ b/test-new/schema._coffee @@ -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 @@ -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)', (_) -> diff --git a/test-new/transactions._coffee b/test-new/transactions._coffee index 759a434..7007ba2 100644 --- a/test-new/transactions._coffee +++ b/test-new/transactions._coffee @@ -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() @@ -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() @@ -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() @@ -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', @@ -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 @@ -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)' @@ -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() @@ -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() @@ -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() @@ -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] @@ -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 diff --git a/test-new/util/helpers._coffee b/test-new/util/helpers._coffee index b4a9a38..c558a6f 100644 --- a/test-new/util/helpers._coffee +++ b/test-new/util/helpers._coffee @@ -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 # @@ -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? #