Skip to content
Browse files

Merge branch 'feature/improve-tests' into develop

  • Loading branch information...
2 parents 1cf0e92 + 5297a02 commit 18f5c9d5c8ce16f34fb2838ae01ffbd1be757052 @aseemk aseemk committed Oct 6, 2012
Showing with 354 additions and 335 deletions.
  1. +7 −7 lib/Node._coffee
  2. +4 −3 package.json
  3. +116 −102 test/crud._coffee
  4. +145 −124 test/cypher._coffee
  5. +79 −80 test/gremlin._coffee
  6. +0 −3 test/index._coffee
  7. +3 −0 test/mocha.opts
  8. +0 −16 test/profile._coffee
View
14 lib/Node._coffee
@@ -214,16 +214,16 @@ module.exports = class Node extends PropertyContainer
type: type
, _
+ # client or database error:
if response.statusCode isnt status.CREATED
- # database error
- message = ''
- switch response.statusCode
+ {message, exception} = response.body or {}
+ message or= exception or switch response.statusCode
when status.BAD_REQUEST
- message = response.body?.message or
- response.body?.exception or
- "Invalid createRelationship: #{from.id} #{type} #{to.id} w/ data: #{JSON.stringify data}"
+ "Invalid createRelationship: #{from.id} #{type} #{to.id} w/ data: #{JSON.stringify data}"
when status.CONFLICT
- message = '"to" node, or the node specified by the URI not found'
+ '"to" node, or the node specified by the URI not found'
+ else
+ throw response # e.g. internal server error
throw new Error message
# success
View
7 package.json
@@ -16,7 +16,9 @@
"streamline": "~0.4.0"
},
"devDependencies": {
- "codo": "~1.5.1"
+ "codo": "~1.5.1",
+ "expect.js": "~0.1.2",
+ "mocha": "~1.3.0"
},
"engines": {
"node": ">= 0.6"
@@ -26,8 +28,7 @@
"clean": "rm lib/*.js",
"codo": "codo && codo --server",
"postinstall": "npm run build",
- "profile": "_coffee test/profile",
- "test": "_coffee test"
+ "test": "mocha"
},
"keywords": [
"neo4j", "graph", "database", "driver", "rest", "api", "client"
View
218 test/crud._coffee
@@ -1,122 +1,136 @@
# this file is in streamline syntax!
# https://github.com/Sage/streamlinejs
-assert = require 'assert'
+expect = require 'expect.js'
neo4j = require '..'
db = new neo4j.GraphDatabase 'http://localhost:7474'
+# data we're going to use:
danielData =
name: 'Daniel'
-
aseemData =
name: 'Aseem'
-daniel = db.createNode danielData
-aseem = db.createNode aseemData
-
-assert.strictEqual daniel.exists, false, 'Node should not exist'
-assert.strictEqual daniel.self, null, 'Node self should be null'
- # TODO should this really be tested? is @self a public API?
- # maybe it should just have a better name than the misleading 'self'?
-
-# test futures here by saving both aseem and daniel in parallel:
-futures = [daniel.save(), aseem.save()]
-future _ for future in futures
-
-assert.ok daniel.exists, 'Node should exist'
-assert.ok daniel.self, 'node.self should not be null' # TODO see above
-assert.deepEqual daniel.data, danielData, 'Sent and received data should match'
-
-assert.ok aseem.exists, 'Node should exist'
-assert.ok aseem.self, 'node.self should not be null' # TODO see above
-assert.deepEqual aseem.data, aseemData, 'Sent and received data should match'
+# instances we're going to reuse across tests:
+daniel = null
+aseem = null
+relationship = null
+
+@crud =
+
+ 'create nodes': (_) ->
+ daniel = db.createNode danielData
+ aseem = db.createNode aseemData
+
+ expect(daniel).to.be.an 'object'
+ expect(daniel.exists).to.be false
+ expect(daniel.self).to.be null
+ # TODO should this really be tested? is @self a public API?
+ # maybe it should just have a better name than 'self'? like url?
+
+ 'save nodes': (_) ->
+ # test futures here by saving both aseem and daniel in parallel:
+ futures = [daniel.save(), aseem.save()]
+ future _ for future in futures
+
+ expect(daniel.exists).to.be true
+ expect(daniel.self).to.be.a 'string' # TODO see above
+ expect(daniel.self).to.not.equal aseem.self # TODO see above
+ expect(daniel.data).to.eql danielData
+
+ expect(aseem.exists).to.be true
+ expect(aseem.self).to.be.a 'string' # TODO see above
+ expect(aseem.self).to.not.equal daniel.self # TODO see above
+ expect(aseem.data).to.eql aseemData
+
+ 'create realtionships': (_) ->
+ relationship = daniel.createRelationshipTo aseem, 'follows', {created: Date.now()}, _
+ testRelationship relationship
+
+ # in this case, the start and end *should* be our instances
+ expect(relationship.start).to.be daniel
+ expect(relationship.end).to.be aseem
+
+ 'fetch relationships': (_) ->
+ # test futures by *initiating* getRelationships() for both aseem and daniel in
+ # parallel. note how we'll still "collect" (process) the futures in sequence.
+ danielFuture = daniel.getRelationships('follows')
+ aseemFuture = aseem.getRelationships('follows')
+
+ relationships = danielFuture _
+ testRelationships relationships
+
+ # in this case, the start *should* be our instance
+ expect(relationships[0].start).to.be daniel
+
+ relationships = aseemFuture _
+ testRelationships relationships
+
+ # in this case, the end *should* be our instance
+ expect(relationships[0].end).to.be aseem
+
+ 'traverse nodes': (_) ->
+ # same parallel lookups using futures:
+ danielFuture = daniel.getRelationshipNodes('follows')
+ aseemFuture = aseem.getRelationshipNodes('follows')
+
+ nodes = danielFuture _
+ expect(nodes).to.be.an 'array'
+ expect(nodes).to.have.length 1
+ expect(nodes[0]).to.be.an 'object'
+ expect(nodes[0].exists).to.be true
+ expect(nodes[0].self).to.equal aseem.self # TODO see above
+ expect(nodes[0].data).to.eql aseemData
+
+ # TODO see how this is misleading? we don't respect or report direction!
+ nodes = aseemFuture _
+ expect(nodes).to.be.an 'array'
+ expect(nodes).to.have.length 1
+ expect(nodes[0]).to.be.an 'object'
+ expect(nodes[0].exists).to.be true
+ expect(nodes[0].self).to.equal daniel.self # TODO see above
+ expect(nodes[0].data).to.eql danielData
+
+ 'index nodes': (_) ->
+ daniel.index 'users', 'name', 'Daniel', _
+ node = db.getIndexedNode 'users', 'name', 'Daniel', _
+ expect(node).to.be.an 'object'
+ expect(node.exists).to.be true
+ # TODO FIXME we're not unindexing these nodes after each test, so in fact the
+ # returned node and data might be from a previous test!
+ # expect(node.self).to.equal daniel.self # TODO see above
+ # expect(node.data).to.eql danielData
+
+ 'index relationships': (_) ->
+ relationship.index 'follows', 'name', 'Daniel', _
+ rel = db.getIndexedRelationship 'follows', 'name', 'Daniel', _
+ expect(rel).to.be.an 'object'
+ expect(rel.exists).to.be true
+ expect(rel.self).to.be.a 'string' # TODO see above
+ expect(rel.type).to.be 'follows'
+
+ # TODO delete tests! that's the 'd' in 'crud'!
testRelationship = (relationship) ->
- assert.ok relationship
- assert.ok relationship.exists, 'Relationship should exist'
- assert.ok relationship.self, 'relationship.self should not be null' # TODO see above
- assert.equal relationship.type, 'follows', 'Relationship type should be "follows".'
+ expect(relationship).to.be.an 'object'
+ expect(relationship.exists).to.be true
+ expect(relationship.self).to.be.a 'string' # TODO see above
+ expect(relationship.type).to.be 'follows'
- # in some cases, the start/end nodes may not be "filled".
- # they also may not point to the same instances we have.
- #assert.equal relationship.start, daniel
- #assert.equal relationship.end, aseem
+ # in some cases, the start/end nodes may not be "filled", so these are
+ # commented out for now:
+ # expect(relationship.start).to.eql daniel
+ # expect(relationship.end).to.eql aseem
# TEMP so for the time being, we're testing that at least
# their "selves" match. not sure if this is a public API.
- assert.ok relationship.start, 'Relationship should have a start node.'
- assert.ok relationship.end, 'Relationship should have an end node.'
- assert.equal relationship.start.self, daniel.self
- assert.equal relationship.end.self, aseem.self
+ expect(relationship.start).to.be.an 'object'
+ expect(relationship.end).to.be.an 'object'
+ expect(relationship.start.self).to.equal daniel.self
+ expect(relationship.end.self).to.equal aseem.self
testRelationships = (relationships) ->
- assert.ok relationships
- assert.ok relationships.length, 'Relationships should be an array.'
- assert.equal relationships.length, 1, 'There should only be one relationship.'
- testRelationship(relationships[0])
-
-relationship = daniel.createRelationshipTo aseem, 'follows', {created: Date.now()}, _
-testRelationship(relationship)
-
-# in this case, the start and end *should* be our instances
-assert.strictEqual relationship.start, daniel
-assert.strictEqual relationship.end, aseem
-
-# TODO it would be good to test streamline futures support here if/when we
-# port the library to streamline style. we could test it here by invoking
-# getRelationships() on both daniel and aseem in parallel, then waiting for
-# both of them to return (i.e. collecting/syncing both futures).
-
-# test futures by *initiating* getRelationships() for both aseem and daniel in
-# parallel. note how we'll still "collect" (process) the futures in sequence.
-danielFuture = daniel.getRelationships 'follows'
-aseemFuture = aseem.getRelationships 'follows'
-
-relationships = danielFuture _
-testRelationships(relationships)
-
-# in this case, the start *should* be our instance
-assert.equal relationships[0].start, daniel
-
-relationships = aseemFuture _
-testRelationships(relationships)
-
-# in this case, the end *should* be our instance
-assert.equal relationships[0].end, aseem
-
-# same parallel lookups using futures:
-danielFuture = daniel.getRelationshipNodes 'follows'
-aseemFuture = aseem.getRelationshipNodes 'follows'
-
-nodes = danielFuture _
-assert.ok nodes
-assert.ok nodes.length
-assert.equal nodes.length, 1
-assert.ok nodes[0]
-assert.ok nodes[0].exists
-assert.ok nodes[0].self # TODO see above
-assert.deepEqual nodes[0].data, aseemData
-
-# TODO see how this is misleading? we don't respect or report direction!
-nodes = aseemFuture _
-assert.ok nodes
-assert.ok nodes.length
-assert.equal nodes.length, 1
-assert.ok nodes[0]
-assert.ok nodes[0].exists
-assert.ok nodes[0].self # TODO see above
-assert.deepEqual nodes[0].data, danielData
-
-daniel.index 'users', 'name', 'Daniel', _
-node = db.getIndexedNode 'users', 'name', 'Daniel', _
-assert.ok node
-
-relationship.index 'follows', 'name', 'Daniel', _
-rel = db.getIndexedRelationship 'follows', 'name', 'Daniel', _
-assert.ok rel
-
-# TODO delete tests! that's the 'd' in 'crud'!
-
-# just to ensure that no sorts of silent transformation errors plagued us
-console.log 'passed CRUD tests'
+ expect(relationships).to.be.an 'array'
+ expect(relationships).to.have.length 1
+ testRelationship relationships[0]
View
269 test/cypher._coffee
@@ -1,27 +1,15 @@
# we'll be creating a somewhat complex graph and testing that cypher queries
# on it return expected results.
-assert = require 'assert'
+expect = require 'expect.js'
neo4j = require '..'
db = new neo4j.GraphDatabase 'http://localhost:7474'
-# convenience wrapper:
-createNode = (name) ->
- node = db.createNode {name}
- node.name = name
- node.toString = -> name
- node
-
-# FOLLOWERS
-
# users: user0 thru user9
users = for i in [0..9]
- createNode "user#{i}"
-
-# save in parallel
-futures = (user.save() for user in users)
-future _ for future in futures
+ db.createNode
+ name: "user#{i}"
# convenience aliases
user0 = users[0]
@@ -35,112 +23,145 @@ user7 = users[7]
user8 = users[8]
user9 = users[9]
-# test: can query a single user
-results = db.query """
- START n=node(#{user0.id})
- RETURN n
-""", _
-assert.ok results instanceof Array
-assert.equal results.length, 1
-assert.equal typeof results[0], 'object'
-assert.ok results[0].hasOwnProperty 'n'
-assert.equal typeof results[0]['n'], 'object'
-assert.equal results[0]['n'].data.name, user0.name
-
-# test: can query multiple users
-results = db.query """
- START n=node(#{user0.id},#{user1.id},#{user2.id})
- RETURN n
- ORDER BY n.name
-""", _
-assert.equal results.length, 3
-assert.equal results[0]['n'].data.name, user0.name
-assert.equal results[1]['n'].data.name, user1.name
-assert.equal results[2]['n'].data.name, user2.name
-
-# have user0 follow user1, user2 and user3
-# have user1 follow user2, user3 and user4
-# ...
-# have user8 follow user9, user0 and user1
-# have user9 follow user0, user1 and user2
-createFollowRelationships = (i, _) ->
- user = users[i]
- i1 = (i + 1) % users.length
- i2 = (i + 2) % users.length
- i3 = (i + 3) % users.length
- # create three relationships in parallel
- # WARNING: don't use a variable named futures here!
- # coffeescript variable shadowing will kick in unexpectedly. =(
- f1 = user.createRelationshipTo users[i1], 'follows', {}
- f2 = user.createRelationshipTo users[i2], 'follows', {}
- f3 = user.createRelationshipTo users[i3], 'follows', {}
- f1 _
- f2 _
- f3 _
-
-# create follow relationships for each user in parallel
-futures = (createFollowRelationships(i) for user, i in users)
-future _ for future in futures
-
-# test: can query relationships and return multiple values
-results = db.query """
- START n=node(#{user6.id})
- MATCH (n) -[r:follows]-> (m)
- RETURN r, m.name
- ORDER BY m.name
-""", _
-assert.equal results.length, 3
-assert.equal typeof results[0]['r'], 'object'
-assert.equal typeof results[0]['m.name'], 'string'
-assert.equal results[0]['r'].type, 'follows'
-assert.equal results[0]['m.name'], user7.name
-assert.equal results[1]['m.name'], user8.name
-assert.equal results[2]['m.name'], user9.name
-
-# test: sending query parameters instead of literals
-results = db.query '''
- START n=node({userId})
- MATCH (n) -[r:follows]-> (m)
- RETURN r, m.name
- ORDER BY m.name
-''', {userId: user3.id}, _
-assert.equal results.length, 3
-assert.equal typeof results[0]['r'], 'object'
-assert.equal typeof results[0]['m.name'], 'string'
-assert.equal results[0]['r'].type, 'follows'
-assert.equal results[0]['m.name'], user4.name
-assert.equal results[1]['m.name'], user5.name
-assert.equal results[2]['m.name'], user6.name
-
-# test: can return nodes in an array
-results = db.query """
- START n=node(#{user0.id},#{user1.id},#{user2.id})
- RETURN collect(n)
-""", _
-assert.equal results.length, 1
-assert.ok results[0]['collect(n)'] instanceof Array
-assert.equal typeof results[0]['collect(n)'][0], 'object'
-assert.equal results[0]['collect(n)'][0].id, user0.id
-assert.equal results[0]['collect(n)'][0].data.name, user0.name
-
-# test: can return paths
-results = db.query """
- START from=node({fromId}), to=node({toId})
- MATCH path=shortestPath(from -[:follows*..3]-> to)
- RETURN path
-""", {fromId: user0.id, toId: user6.id}, _
-assert.equal results.length, 1
-assert.equal typeof results[0]['path'], 'object'
-assert.equal typeof results[0]['path'].start, 'object'
-assert.equal typeof results[0]['path'].end, 'object'
-assert.ok results[0]['path'].nodes instanceof Array
-assert.ok results[0]['path'].relationships instanceof Array
-assert.equal results[0]['path'].length, 2
-assert.equal results[0]['path'].start.id, user0.id
-assert.equal results[0]['path'].end.id, user6.id
-assert.equal results[0]['path'].nodes.length, 3
-assert.equal results[0]['path'].nodes[1].id, user3.id
-assert.equal results[0]['path'].relationships.length, 2
-
-# give some confidence that these tests actually passed ;)
-console.log 'passed cypher tests'
+@cypher =
+
+ '(pre-req) save nodes': (_) ->
+ # save in parallel
+ futures = (user.save() for user in users)
+ future _ for future in futures
+
+ 'query single user': (_) ->
+ results = db.query """
+ START n=node(#{user0.id})
+ RETURN n
+ """, _
+
+ expect(results).to.be.an 'array'
+ expect(results).to.have.length 1
+
+ expect(results[0]).to.be.an 'object'
+ expect(results[0]['n']).to.be.an 'object'
+ expect(results[0]['n'].id).to.equal user0.id
+ expect(results[0]['n'].data).to.eql user0.data
+
+ 'query multiple users': (_) ->
+ results = db.query """
+ START n=node(#{user0.id},#{user1.id},#{user2.id})
+ RETURN n
+ ORDER BY n.name
+ """, _
+ expect(results).to.be.an 'array'
+ expect(results).to.have.length 3
+
+ expect(results[1]).to.be.an 'object'
+ expect(results[1]['n']).to.be.an 'object'
+ expect(results[1]['n'].data).to.eql user1.data
+
+ '(pre-req) create relationships': (_) ->
+ # have user0 follow user1, user2 and user3
+ # have user1 follow user2, user3 and user4
+ # ...
+ # have user8 follow user9, user0 and user1
+ # have user9 follow user0, user1 and user2
+ createFollowRelationships = (i, _) ->
+ user = users[i]
+ i1 = (i + 1) % users.length
+ i2 = (i + 2) % users.length
+ i3 = (i + 3) % users.length
+ # create three relationships in parallel
+ # WARNING: don't use a variable named futures here!
+ # coffeescript variable shadowing will kick in unexpectedly. =(
+ f1 = user.createRelationshipTo users[i1], 'follows', {}
+ f2 = user.createRelationshipTo users[i2], 'follows', {}
+ f3 = user.createRelationshipTo users[i3], 'follows', {}
+ f1 _
+ f2 _
+ f3 _
+
+ # create follow relationships for each user in parallel
+ futures = (createFollowRelationships(i) for user, i in users)
+ future _ for future in futures
+
+ 'query relationships / return multiple values': (_) ->
+ results = db.query """
+ START n=node(#{user6.id})
+ MATCH (n) -[r:follows]-> (m)
+ RETURN r, m.name
+ ORDER BY m.name
+ """, _
+
+ expect(results).to.be.an 'array'
+ expect(results).to.have.length 3
+
+ expect(results[1]).to.be.an 'object'
+ expect(results[1]['r']).to.be.an 'object'
+ expect(results[1]['r'].type).to.be 'follows'
+ expect(results[1]['m.name']).to.equal user8.data.name
+
+ 'send query parameters instead of literals': (_) ->
+ results = db.query '''
+ START n=node({userId})
+ MATCH (n) -[r:follows]-> (m)
+ RETURN r, m.name
+ ORDER BY m.name
+ ''', {userId: user3.id}, _
+
+ expect(results).to.be.an 'array'
+ expect(results).to.have.length 3
+
+ expect(results[1]).to.be.an 'object'
+ expect(results[1]['r']).to.be.an 'object'
+ expect(results[1]['r'].type).to.be 'follows'
+ expect(results[1]['m.name']).to.equal user5.data.name
+
+ 'return collection/array of nodes': (_) ->
+ results = db.query """
+ START n=node(#{user0.id},#{user1.id},#{user2.id})
+ RETURN collect(n)
+ """, _
+
+ expect(results).to.be.an 'array'
+ expect(results).to.have.length 1
+
+ expect(results[0]).to.be.an 'object'
+ expect(results[0]['collect(n)']).to.be.an 'array'
+ expect(results[0]['collect(n)']).to.have.length 3
+ expect(results[0]['collect(n)'][1]).to.be.an 'object'
+ expect(results[0]['collect(n)'][1].id).to.equal user1.id
+ expect(results[0]['collect(n)'][1].data).to.eql user1.data
+
+ 'return paths': (_) ->
+ results = db.query """
+ START from=node({fromId}), to=node({toId})
+ MATCH path=shortestPath(from -[:follows*..3]-> to)
+ RETURN path
+ """, {fromId: user0.id, toId: user6.id}, _
+
+ # TODO Node and Rel instances in returned Path objects aren't necessarily
+ # "filled", so we don't assert equality for those instances' data. it'd be
+ # great if future versions of this library fixed that, but is it possible?
+
+ expect(results).to.be.an 'array'
+ expect(results).to.have.length 1
+
+ expect(results[0]).to.be.an 'object'
+ expect(results[0]['path']).to.be.an 'object'
+
+ expect(results[0]['path'].start).to.be.an 'object'
+ expect(results[0]['path'].start.id).to.equal user0.id
+ # expect(results[0]['path'].start.data).to.eql user0.data
+
+ expect(results[0]['path'].end).to.be.an 'object'
+ expect(results[0]['path'].end.id).to.equal user6.id
+ # expect(results[0]['path'].end.data).to.eql user6.data
+
+ expect(results[0]['path'].nodes).to.be.an 'array'
+ expect(results[0]['path'].nodes).to.have.length 3
+ expect(results[0]['path'].nodes[1]).to.be.an 'object'
+ expect(results[0]['path'].nodes[1].id).to.equal user3.id
+ # expect(results[0]['path'].nodes[1].data).to.eql user3.data
+
+ expect(results[0]['path'].relationships).to.be.an 'array'
+ expect(results[0]['path'].relationships).to.have.length 2
+ expect(results[0]['path'].relationships[1]).to.be.an 'object'
+ # expect(results[0]['path'].relationships[1].type).to.be 'follows'
View
159 test/gremlin._coffee
@@ -1,25 +1,15 @@
# will be used for testing gremlin script executions
# as well as validating the return results are as expected
-assert = require('assert')
-neo4j = require('..')
+expect = require 'expect.js'
+neo4j = require '..'
db = new neo4j.GraphDatabase 'http://localhost:7474'
-# convenience wrapper
-createNode = (name) ->
- node = db.createNode {name}
- node.name = name
- node.toString = -> name
- node
-
# create some nodes
users = for i in [0..6]
- createNode "gremlinTest#{i}"
-
-# save in parallel
-futures = (user.save() for user in users)
-future _ for future in futures
+ db.createNode
+ name: "gremlinTest#{i}"
# convenience aliases
user0 = users[0]
@@ -30,69 +20,78 @@ user4 = users[4]
user5 = users[5]
user6 = users[6]
-# test: can query a single user, using param
-result = db.execute """
- g.v(userId)
-""", {userId: user0.id}, _
-
-assert.ok result
-assert.equal typeof result, 'object'
-assert.equal typeof result.data, 'object'
-assert.equal result.data.name, user0.name
-
-# test: create relationships between users (same as cypher tests), then query by relationships
-createFollowRelationships = (i, _) ->
- user = users[i]
- i1 = (i + 1) % users.length
- i2 = (i + 2) % users.length
- i3 = (i + 3) % users.length
- f1 = user.createRelationshipTo users[i1], 'gremlin_follows', {}
- f2 = user.createRelationshipTo users[i2], 'gremlin_follows', {}
- f3 = user.createRelationshipTo users[i3], 'gremlin_follows', {}
- f1 _
- f2 _
- f3 _
-
-# create follow relationships for each user in parallel
-futures = (createFollowRelationships(i) for user, i in users)
-future _ for future in futures
-
-rels = db.execute """
- g.v(#{user0.id}).in('gremlin_follows')
-""", {} , _
-
-assert.ok rels instanceof Array
-assert.equal rels.length, 3
-assert.ok rels[1]
-assert.equal typeof rels[1], 'object'
-# order isn't specified/guaranteed:
-assert.ok rels[1].id in [user4.id, user5.id, user6.id]
-
-# handle multiple types of data return
-traversals = db.execute """
- g.v(#{user0.id}).transform{ [it, it.out.toList(), it.in.count()] }
-""", {}, _
-
-assert.ok traversals instanceof Array
-assert.equal traversals.length, 1
-
-assert.ok traversals[0] instanceof Array
-assert.equal traversals[0].length, 3
-
-assert.equal typeof traversals[0][0], 'object'
-assert.equal traversals[0][0].id, user0.id
-assert.ok traversals[0][1] instanceof Array
-assert.equal traversals[0][1].length, 3
-assert.ok traversals[0][1][1].id in [user1.id, user2.id, user3.id]
-assert.equal traversals[0][2], 3
-
-# ensure you can call without params
-params_test = db.execute """
- g.v(#{user0.id})
-""", _
-
-assert.equal typeof params_test, 'object'
-assert.equal params_test.data.name, user0.name
-
-# give some confidence that these tests actually passed ;)
-console.log 'passed gremlin tests'
+@gremlin =
+
+ '(pre-req) save nodes': (_) ->
+ # save in parallel
+ futures = (user.save() for user in users)
+ future _ for future in futures
+
+ 'query single user, using param': (_) ->
+ result = db.execute """
+ g.v(userId)
+ """, {userId: user0.id}, _
+
+ expect(result).to.be.an 'object'
+ expect(result.id).to.equal user0.id
+ expect(result.data).to.eql user0.data
+
+ '(pre-req) create relationships': (_) ->
+ createFollowRelationships = (i, _) ->
+ user = users[i]
+ i1 = (i + 1) % users.length
+ i2 = (i + 2) % users.length
+ i3 = (i + 3) % users.length
+ f1 = user.createRelationshipTo users[i1], 'gremlin_follows', {}
+ f2 = user.createRelationshipTo users[i2], 'gremlin_follows', {}
+ f3 = user.createRelationshipTo users[i3], 'gremlin_follows', {}
+ f1 _
+ f2 _
+ f3 _
+
+ # create follow relationships for each user in parallel
+ futures = (createFollowRelationships(i) for user, i in users)
+ future _ for future in futures
+
+ # TODO test returning relationships too, not just connected nodes
+
+ 'query connected nodes': (_) ->
+ rels = db.execute """
+ g.v(#{user0.id}).in('gremlin_follows')
+ """, {}, _
+
+ expect(rels).to.be.an 'array'
+ expect(rels).to.have.length 3
+ expect(rels[1]).to.be.an 'object'
+ # order isn't specified/guaranteed; TODO can we specify it?
+ expect([user4.id, user5.id, user6.id]).to.contain rels[1].id
+
+ 'return multiple types': (_) ->
+ traversals = db.execute """
+ g.v(#{user0.id}).transform{ [it, it.out.toList(), it.in.count()] }
+ """, {}, _
+
+ expect(traversals).to.be.an 'array'
+ expect(traversals).to.have.length 1
+
+ expect(traversals[0]).to.be.an 'array'
+ expect(traversals[0]).to.have.length 3
+
+ expect(traversals[0][0]).to.be.an 'object'
+ expect(traversals[0][0].id).to.equal user0.id
+ expect(traversals[0][0].data).to.eql user0.data
+ expect(traversals[0][1]).to.be.an 'array'
+ expect(traversals[0][1]).to.have.length 3
+ expect(traversals[0][1][1]).to.be.an 'object'
+ # order isn't specified/guaranteed again; TODO can we specify it?
+ expect([user1.id, user2.id, user3.id]).to.contain traversals[0][1][1].id
+ expect(traversals[0][2]).to.equal 3
+
+ 'query without params arg': (_) ->
+ params_test = db.execute """
+ g.v(#{user0.id})
+ """, _
+
+ expect(params_test).to.be.an 'object'
+ expect(params_test.id).to.equal user0.id
+ expect(params_test.data).to.eql user0.data
View
3 test/index._coffee
@@ -1,3 +0,0 @@
-require './crud'
-require './cypher'
-require './gremlin'
View
3 test/mocha.opts
@@ -0,0 +1,3 @@
+--compilers coffee:coffee-script,_coffee:streamline/register
+-u exports
+-R spec
View
16 test/profile._coffee
@@ -1,16 +0,0 @@
-# this file is in streamline syntax!
-# https://github.com/Sage/streamlinejs
-
-neo4j = require '..'
-db = new neo4j.GraphDatabase 'http://localhost:7474'
-
-NUM_NODES = 100000
-
-console.log "Constructing #{NUM_NODES} nodes..."
-beginTime = Date.now()
-
-for i in [0...NUM_NODES]
- db.createNode {}
-
-timeDelta = Date.now() - beginTime
-console.log "Took #{timeDelta / 1000} secs."

0 comments on commit 18f5c9d

Please sign in to comment.
Something went wrong with that request. Please try again.