Skip to content

Commit

Permalink
Stop mocking the driver for tests with types
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarhane committed Apr 17, 2018
1 parent 6eb3692 commit ac1dcc8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 212 deletions.
187 changes: 0 additions & 187 deletions __mocks__/neo4j.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html)$":
"<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"neo4j": "<rootDir>/__mocks__/neo4j.js",
"^neo4j-driver-alias$": "neo4j-driver",
"^react-dom/server$": "preact-render-to-string",
"^react-addons-test-utils$": "preact-test-utils",
"^react-addons-transition-group$": "preact-transition-group",
Expand Down
9 changes: 5 additions & 4 deletions src/browser/modules/Stream/CypherFrame/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

/* global describe, test, expect */
/* eslint-disable new-cap */
import { v1 as neo4j } from 'neo4j-driver-alias'
import * as viewTypes from 'shared/modules/stream/frameViewTypes'
import {
Expand Down Expand Up @@ -517,7 +518,7 @@ describe('helpers', () => {
test('extractRecordsToResultArray handles regular records', () => {
// Given
const start = new neo4j.types.Node(1, ['X'], { x: 1 })
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.Int(1) })
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.int(1) })
const rel = new neo4j.types.Relationship(3, 1, 2, 'REL', { rel: 1 })
const segments = [new neo4j.types.PathSegment(start, rel, end)]
const path = new neo4j.types.Path(start, end, segments)
Expand Down Expand Up @@ -590,11 +591,11 @@ describe('helpers', () => {
const records = [
{
keys: ['"neoInt"', '"int"', '"any"', '"backslash"'],
_fields: [new neo4j.Int('882573709873217509'), 100, 0.5, '"\\"']
_fields: [new neo4j.int('882573709873217509'), 100, 0.5, '"\\"']
},
{
keys: ['"neoInt"', '"int"', '"any"'],
_fields: [new neo4j.Int(300), 100, 'string']
_fields: [new neo4j.int(300), 100, 'string']
}
]

Expand All @@ -616,7 +617,7 @@ describe('helpers', () => {
test('stringifyResultArray handles neo4j integers nested within graph items', () => {
// Given
const start = new neo4j.types.Node(1, ['X'], { x: 1 })
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.Int(2) }) // <-- Neo4j integer
const end = new neo4j.types.Node(2, ['Y'], { y: new neo4j.int(2) }) // <-- Neo4j integer
const rel = new neo4j.types.Relationship(3, 1, 2, 'REL', { rel: 1 })
const segments = [new neo4j.types.PathSegment(start, rel, end)]
const path = new neo4j.types.Path(start, end, segments)
Expand Down
41 changes: 21 additions & 20 deletions src/shared/services/bolt/applyGraphTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('applyGraphTypes', () => {
test('should apply integer type', () => {
const rawNumber = nativeTypesToCustom(neo4j.int(5))
const typedNumber = applyGraphTypes(rawNumber)
expect(typedNumber).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedNumber)).toBeTruthy()
})

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

const typedNode = applyGraphTypes(rawNode)
expect(typedNode).toBeInstanceOf(neo4j.types.Node)
expect(typedNode.identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedNode.identity)).toBeTruthy()
})

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

const obj = applyGraphTypes(rawObject)
expect(obj).toBeInstanceOf(Object)
expect(obj.identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(obj.identity)).toBeTruthy()
expect(neo4j.isInt(obj.identity2)).toBeFalsy()
expect(obj.identity2).toBeInstanceOf(Object)
expect(obj[reservedTypePropertyName]).toEqual('Node')
})
Expand Down Expand Up @@ -180,7 +181,7 @@ describe('applyGraphTypes', () => {

const typedNode = applyGraphTypes(rawNode)
expect(typedNode).toBeInstanceOf(neo4j.types.Node)
expect(typedNode.identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedNode.identity)).toBeTruthy()

expect(typedNode.properties.prop1).toBeNull()
expect(typedNode.properties.prop2).toEqual(33)
Expand All @@ -191,7 +192,7 @@ describe('applyGraphTypes', () => {
expect(typedNode.properties.prop6.prop1).toEqual(1)
expect(typedNode.properties.prop6.prop2).toEqual('test')

expect(typedNode.properties.prop7.prop1).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedNode.properties.prop7.prop1)).toBeTruthy()
expect(typedNode.properties.prop7.prop1.toInt()).toEqual(3)
expect(typedNode.properties.prop7.prop2).toEqual('test')

Expand Down Expand Up @@ -223,9 +224,9 @@ describe('applyGraphTypes', () => {
const typedNodes = applyGraphTypes(rawNodes, neo4j.types)
expect(typedNodes.length).toEqual(2)
expect(typedNodes[0]).toBeInstanceOf(neo4j.types.Node)
expect(typedNodes[0].identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedNodes[0].identity)).toBeTruthy()
expect(typedNodes[1]).toBeInstanceOf(neo4j.types.Node)
expect(typedNodes[1].identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedNodes[1].identity)).toBeTruthy()
})

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

const typedRelationship = applyGraphTypes(rawRelationship)
expect(typedRelationship).toBeInstanceOf(neo4j.types.Relationship)
expect(typedRelationship.identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedRelationship.identity)).toBeTruthy()
expect(typedRelationship.type).toEqual('TESTED_WITH')
})

Expand All @@ -268,13 +269,13 @@ describe('applyGraphTypes', () => {
const typedRelationships = applyGraphTypes(rawRelationships)
expect(typedRelationships.length).toEqual(2)
expect(typedRelationships[0]).toBeInstanceOf(neo4j.types.Relationship)
expect(typedRelationships[0].identity).toBeInstanceOf(neo4j.Integer)
expect(typedRelationships[0].start).toBeInstanceOf(neo4j.Integer)
expect(typedRelationships[0].end).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedRelationships[0].identity)).toBeTruthy()
expect(neo4j.isInt(typedRelationships[0].start)).toBeTruthy()
expect(neo4j.isInt(typedRelationships[0].end)).toBeTruthy()
expect(typedRelationships[1]).toBeInstanceOf(neo4j.types.Relationship)
expect(typedRelationships[1].identity).toBeInstanceOf(neo4j.Integer)
expect(typedRelationships[1].start).toBeInstanceOf(neo4j.Integer)
expect(typedRelationships[1].end).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedRelationships[1].identity)).toBeTruthy()
expect(neo4j.isInt(typedRelationships[1].start)).toBeTruthy()
expect(neo4j.isInt(typedRelationships[1].end)).toBeTruthy()
})

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

const typedObject = applyGraphTypes(rawData)
expect(typedObject.node).toBeInstanceOf(neo4j.types.Node)
expect(typedObject.num).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedObject.num)).toBeTruthy()
})

test('should apply to array of custom object properties', () => {
Expand All @@ -304,9 +305,9 @@ describe('applyGraphTypes', () => {
const typedObjects = applyGraphTypes(rawObj)
expect(typedObjects.length).toEqual(2)
expect(typedObjects[0].node).toBeInstanceOf(neo4j.types.Node)
expect(typedObjects[0].num).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedObjects[0].num)).toBeTruthy()
expect(typedObjects[1].node).toBeInstanceOf(neo4j.types.Node)
expect(typedObjects[1].num).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedObjects[1].num)).toBeTruthy()
})

test('should apply PathSegment type', () => {
Expand All @@ -315,7 +316,7 @@ describe('applyGraphTypes', () => {
expect(typedPathSegment).toBeTruthy()
expect(typedPathSegment).toBeInstanceOf(neo4j.types.PathSegment)
expect(typedPathSegment.start).toBeInstanceOf(neo4j.types.Node)
expect(typedPathSegment.start.identity).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedPathSegment.start.identity)).toBeTruthy()
expect(typedPathSegment.end).toBeInstanceOf(neo4j.types.Node)
expect(typedPathSegment.relationship).toBeInstanceOf(
neo4j.types.Relationship
Expand Down Expand Up @@ -388,7 +389,7 @@ describe('applyGraphTypes', () => {
})
const typedObject = applyGraphTypes(complexObj)
expect(typedObject).toBeTruthy()
expect(typedObject.rawNum).toBeInstanceOf(neo4j.Integer)
expect(neo4j.isInt(typedObject.rawNum)).toBeTruthy()
expect(typedObject.rawNode).toBeInstanceOf(neo4j.types.Node)
expect(typedObject.rawRelationship).toBeInstanceOf(neo4j.types.Relationship)
expect(typedObject.rawPath).toBeInstanceOf(neo4j.types.Path)
Expand Down Expand Up @@ -423,7 +424,7 @@ describe('applyGraphTypes', () => {
12,
44,
0,
3600,
null,
'Europe/Stockholm'
)
const rawDateTime = nativeTypesToCustom(dateTime)
Expand Down

0 comments on commit ac1dcc8

Please sign in to comment.