Skip to content

Commit 10b4443

Browse files
committed
Stop mocking the driver for tests with types
1 parent dbe6816 commit 10b4443

File tree

4 files changed

+27
-212
lines changed

4 files changed

+27
-212
lines changed

__mocks__/neo4j.js

Lines changed: 0 additions & 187 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html)$":
4848
"<rootDir>/__mocks__/fileMock.js",
4949
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
50-
"neo4j": "<rootDir>/__mocks__/neo4j.js",
50+
"^neo4j-driver-alias$": "neo4j-driver",
5151
"^react-dom/server$": "preact-render-to-string",
5252
"^react-addons-test-utils$": "preact-test-utils",
5353
"^react-addons-transition-group$": "preact-transition-group",

src/browser/modules/Stream/CypherFrame/helpers.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
/* global describe, test, expect */
22+
/* eslint-disable new-cap */
2223
import { v1 as neo4j } from 'neo4j-driver-alias'
2324
import * as viewTypes from 'shared/modules/stream/frameViewTypes'
2425
import {
@@ -517,7 +518,7 @@ describe('helpers', () => {
517518
test('extractRecordsToResultArray handles regular records', () => {
518519
// Given
519520
const start = new neo4j.types.Node(1, ['X'], { x: 1 })
520-
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.Int(1) })
521+
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.int(1) })
521522
const rel = new neo4j.types.Relationship(3, 1, 2, 'REL', { rel: 1 })
522523
const segments = [new neo4j.types.PathSegment(start, rel, end)]
523524
const path = new neo4j.types.Path(start, end, segments)
@@ -590,11 +591,11 @@ describe('helpers', () => {
590591
const records = [
591592
{
592593
keys: ['"neoInt"', '"int"', '"any"', '"backslash"'],
593-
_fields: [new neo4j.Int('882573709873217509'), 100, 0.5, '"\\"']
594+
_fields: [new neo4j.int('882573709873217509'), 100, 0.5, '"\\"']
594595
},
595596
{
596597
keys: ['"neoInt"', '"int"', '"any"'],
597-
_fields: [new neo4j.Int(300), 100, 'string']
598+
_fields: [new neo4j.int(300), 100, 'string']
598599
}
599600
]
600601

@@ -616,7 +617,7 @@ describe('helpers', () => {
616617
test('stringifyResultArray handles neo4j integers nested within graph items', () => {
617618
// Given
618619
const start = new neo4j.types.Node(1, ['X'], { x: 1 })
619-
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.Int(2) }) // <-- Neo4j integer
620+
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.int(2) }) // <-- Neo4j integer
620621
const rel = new neo4j.types.Relationship(3, 1, 2, 'REL', { rel: 1 })
621622
const segments = [new neo4j.types.PathSegment(start, rel, end)]
622623
const path = new neo4j.types.Path(start, end, segments)

src/shared/services/bolt/applyGraphTypes.test.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('applyGraphTypes', () => {
125125
test('should apply integer type', () => {
126126
const rawNumber = nativeTypesToCustom(neo4j.int(5))
127127
const typedNumber = applyGraphTypes(rawNumber)
128-
expect(typedNumber).toBeInstanceOf(neo4j.Integer)
128+
expect(neo4j.isInt(typedNumber)).toBeTruthy()
129129
})
130130

131131
test('should apply node type', () => {
@@ -134,7 +134,7 @@ describe('applyGraphTypes', () => {
134134

135135
const typedNode = applyGraphTypes(rawNode)
136136
expect(typedNode).toBeInstanceOf(neo4j.types.Node)
137-
expect(typedNode.identity).toBeInstanceOf(neo4j.Integer)
137+
expect(neo4j.isInt(typedNode.identity)).toBeTruthy()
138138
})
139139

140140
test('should not false positive on fake node object type', () => {
@@ -148,7 +148,8 @@ describe('applyGraphTypes', () => {
148148

149149
const obj = applyGraphTypes(rawObject)
150150
expect(obj).toBeInstanceOf(Object)
151-
expect(obj.identity).toBeInstanceOf(neo4j.Integer)
151+
expect(neo4j.isInt(obj.identity)).toBeTruthy()
152+
expect(neo4j.isInt(obj.identity2)).toBeFalsy()
152153
expect(obj.identity2).toBeInstanceOf(Object)
153154
expect(obj[reservedTypePropertyName]).toEqual('Node')
154155
})
@@ -180,7 +181,7 @@ describe('applyGraphTypes', () => {
180181

181182
const typedNode = applyGraphTypes(rawNode)
182183
expect(typedNode).toBeInstanceOf(neo4j.types.Node)
183-
expect(typedNode.identity).toBeInstanceOf(neo4j.Integer)
184+
expect(neo4j.isInt(typedNode.identity)).toBeTruthy()
184185

185186
expect(typedNode.properties.prop1).toBeNull()
186187
expect(typedNode.properties.prop2).toEqual(33)
@@ -191,7 +192,7 @@ describe('applyGraphTypes', () => {
191192
expect(typedNode.properties.prop6.prop1).toEqual(1)
192193
expect(typedNode.properties.prop6.prop2).toEqual('test')
193194

194-
expect(typedNode.properties.prop7.prop1).toBeInstanceOf(neo4j.Integer)
195+
expect(neo4j.isInt(typedNode.properties.prop7.prop1)).toBeTruthy()
195196
expect(typedNode.properties.prop7.prop1.toInt()).toEqual(3)
196197
expect(typedNode.properties.prop7.prop2).toEqual('test')
197198

@@ -223,9 +224,9 @@ describe('applyGraphTypes', () => {
223224
const typedNodes = applyGraphTypes(rawNodes, neo4j.types)
224225
expect(typedNodes.length).toEqual(2)
225226
expect(typedNodes[0]).toBeInstanceOf(neo4j.types.Node)
226-
expect(typedNodes[0].identity).toBeInstanceOf(neo4j.Integer)
227+
expect(neo4j.isInt(typedNodes[0].identity)).toBeTruthy()
227228
expect(typedNodes[1]).toBeInstanceOf(neo4j.types.Node)
228-
expect(typedNodes[1].identity).toBeInstanceOf(neo4j.Integer)
229+
expect(neo4j.isInt(typedNodes[1].identity)).toBeTruthy()
229230
})
230231

231232
test('should apply relationship type', () => {
@@ -241,7 +242,7 @@ describe('applyGraphTypes', () => {
241242

242243
const typedRelationship = applyGraphTypes(rawRelationship)
243244
expect(typedRelationship).toBeInstanceOf(neo4j.types.Relationship)
244-
expect(typedRelationship.identity).toBeInstanceOf(neo4j.Integer)
245+
expect(neo4j.isInt(typedRelationship.identity)).toBeTruthy()
245246
expect(typedRelationship.type).toEqual('TESTED_WITH')
246247
})
247248

@@ -268,13 +269,13 @@ describe('applyGraphTypes', () => {
268269
const typedRelationships = applyGraphTypes(rawRelationships)
269270
expect(typedRelationships.length).toEqual(2)
270271
expect(typedRelationships[0]).toBeInstanceOf(neo4j.types.Relationship)
271-
expect(typedRelationships[0].identity).toBeInstanceOf(neo4j.Integer)
272-
expect(typedRelationships[0].start).toBeInstanceOf(neo4j.Integer)
273-
expect(typedRelationships[0].end).toBeInstanceOf(neo4j.Integer)
272+
expect(neo4j.isInt(typedRelationships[0].identity)).toBeTruthy()
273+
expect(neo4j.isInt(typedRelationships[0].start)).toBeTruthy()
274+
expect(neo4j.isInt(typedRelationships[0].end)).toBeTruthy()
274275
expect(typedRelationships[1]).toBeInstanceOf(neo4j.types.Relationship)
275-
expect(typedRelationships[1].identity).toBeInstanceOf(neo4j.Integer)
276-
expect(typedRelationships[1].start).toBeInstanceOf(neo4j.Integer)
277-
expect(typedRelationships[1].end).toBeInstanceOf(neo4j.Integer)
276+
expect(neo4j.isInt(typedRelationships[1].identity)).toBeTruthy()
277+
expect(neo4j.isInt(typedRelationships[1].start)).toBeTruthy()
278+
expect(neo4j.isInt(typedRelationships[1].end)).toBeTruthy()
278279
})
279280

280281
test('should apply to custom object properties', () => {
@@ -286,7 +287,7 @@ describe('applyGraphTypes', () => {
286287

287288
const typedObject = applyGraphTypes(rawData)
288289
expect(typedObject.node).toBeInstanceOf(neo4j.types.Node)
289-
expect(typedObject.num).toBeInstanceOf(neo4j.Integer)
290+
expect(neo4j.isInt(typedObject.num)).toBeTruthy()
290291
})
291292

292293
test('should apply to array of custom object properties', () => {
@@ -304,9 +305,9 @@ describe('applyGraphTypes', () => {
304305
const typedObjects = applyGraphTypes(rawObj)
305306
expect(typedObjects.length).toEqual(2)
306307
expect(typedObjects[0].node).toBeInstanceOf(neo4j.types.Node)
307-
expect(typedObjects[0].num).toBeInstanceOf(neo4j.Integer)
308+
expect(neo4j.isInt(typedObjects[0].num)).toBeTruthy()
308309
expect(typedObjects[1].node).toBeInstanceOf(neo4j.types.Node)
309-
expect(typedObjects[1].num).toBeInstanceOf(neo4j.Integer)
310+
expect(neo4j.isInt(typedObjects[1].num)).toBeTruthy()
310311
})
311312

312313
test('should apply PathSegment type', () => {
@@ -315,7 +316,7 @@ describe('applyGraphTypes', () => {
315316
expect(typedPathSegment).toBeTruthy()
316317
expect(typedPathSegment).toBeInstanceOf(neo4j.types.PathSegment)
317318
expect(typedPathSegment.start).toBeInstanceOf(neo4j.types.Node)
318-
expect(typedPathSegment.start.identity).toBeInstanceOf(neo4j.Integer)
319+
expect(neo4j.isInt(typedPathSegment.start.identity)).toBeTruthy()
319320
expect(typedPathSegment.end).toBeInstanceOf(neo4j.types.Node)
320321
expect(typedPathSegment.relationship).toBeInstanceOf(
321322
neo4j.types.Relationship
@@ -388,7 +389,7 @@ describe('applyGraphTypes', () => {
388389
})
389390
const typedObject = applyGraphTypes(complexObj)
390391
expect(typedObject).toBeTruthy()
391-
expect(typedObject.rawNum).toBeInstanceOf(neo4j.Integer)
392+
expect(neo4j.isInt(typedObject.rawNum)).toBeTruthy()
392393
expect(typedObject.rawNode).toBeInstanceOf(neo4j.types.Node)
393394
expect(typedObject.rawRelationship).toBeInstanceOf(neo4j.types.Relationship)
394395
expect(typedObject.rawPath).toBeInstanceOf(neo4j.types.Path)
@@ -423,7 +424,7 @@ describe('applyGraphTypes', () => {
423424
12,
424425
44,
425426
0,
426-
3600,
427+
null,
427428
'Europe/Stockholm'
428429
)
429430
const rawDateTime = nativeTypesToCustom(dateTime)

0 commit comments

Comments
 (0)