@@ -8,6 +8,8 @@ neo4j = require '../'
8
8
9
9
{DB , TEST_LABEL , TEST_REL_TYPE } = fixtures
10
10
11
+ [DB_VERSION_STR , DB_VERSION_NUM ] = []
12
+
11
13
TEST_NODE_A = new neo4j.Node
12
14
# _id will get filled in once we persist
13
15
labels : [TEST_LABEL]
@@ -141,6 +143,25 @@ describe 'GraphDatabase::http', ->
141
143
142
144
# # Object parsing:
143
145
146
+ it ' (query Neo4j version)' , (_ ) ->
147
+ info = DB .http
148
+ method : ' GET'
149
+ path : ' /db/data/'
150
+ , _
151
+
152
+ DB_VERSION_STR = info .neo4j_version or ' 0'
153
+ DB_VERSION_NUM = parseFloat DB_VERSION_STR, 10
154
+
155
+ if DB_VERSION_NUM < 2
156
+ throw new Error ' *** node-neo4j v2 supports Neo4j v2+ only.
157
+ These tests will fail! ***'
158
+
159
+ # Neo4j <2.1.5 didn't return label info, so returned nodes won't have
160
+ # the labels we expect. Account for that:
161
+ if DB_VERSION_STR < ' 2.1.5'
162
+ TEST_NODE_A .labels = null
163
+ TEST_NODE_B .labels = null
164
+
144
165
it ' (create test objects)' , (_ ) ->
145
166
# NOTE: Using the old Cypher endpoint for simplicity here.
146
167
# Nicer than using the raw REST API to create these test objects,
@@ -222,9 +243,13 @@ describe 'GraphDatabase::http', ->
222
243
, _
223
244
224
245
expect (body).to .not .be .an .instanceOf neo4j .Node
225
- expect (body .metadata ).to .be .an ' object'
226
- expect (body .metadata .id ).to .equal TEST_NODE_A ._id
227
- expect (body .metadata .labels ).to .eql TEST_NODE_A .labels
246
+
247
+ # NOTE: Neo4j <2.1.5 didn't return `metadata`, so can't rely on it:
248
+ if DB_VERSION_STR >= ' 2.1.5'
249
+ expect (body .metadata ).to .be .an ' object'
250
+ expect (body .metadata .id ).to .equal TEST_NODE_A ._id
251
+ expect (body .metadata .labels ).to .eql TEST_NODE_A .labels
252
+
228
253
expect (body .data ).to .eql TEST_NODE_A .properties
229
254
230
255
it ' should not parse relationships for raw responses' , (_ ) ->
@@ -234,9 +259,13 @@ describe 'GraphDatabase::http', ->
234
259
raw : true
235
260
, _
236
261
237
- expect (body .metadata ).to .be .an ' object'
238
- expect (body .metadata .id ).to .equal TEST_REL ._id
239
262
expect (body).to .not .be .an .instanceOf neo4j .Relationship
263
+
264
+ # NOTE: Neo4j <2.1.5 didn't return `metadata`, so can't rely on it:
265
+ if DB_VERSION_STR >= ' 2.1.5'
266
+ expect (body .metadata ).to .be .an ' object'
267
+ expect (body .metadata .id ).to .equal TEST_REL ._id
268
+
240
269
expect (body .type ).to .equal TEST_REL .type
241
270
expect (body .data ).to .eql TEST_REL .properties
242
271
0 commit comments