diff --git a/__mocks__/neo4j.js b/__mocks__/neo4j.js deleted file mode 100644 index 24577d41dcd..00000000000 --- a/__mocks__/neo4j.js +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2002-2018 "Neo4j, Inc" - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -function integerFn (val) { - this.val = val -} -integerFn.prototype.toString = function () { - return this.val.toString() -} - -var out = { - v1: { - isInt: function (val) { - return val instanceof out.v1.Integer - }, - types: { - Node: function Node (id, labels, properties) { - this.identity = id - this.labels = labels - this.properties = properties - }, - Relationship: function Relationship (id, start, end, type, properties) { - this.identity = id - this.start = start - this.end = end - this.type = type - this.properties = properties - }, - Path: function Path (start, end, segments) { - this.start = start - this.end = end - this.segments = segments - this.length = segments.length - }, - PathSegment: function PathSegment (start, relationship, end) { - this.start = start - this.relationship = relationship - this.end = end - }, - Point: function Point (srid, x, y, z) { - this.srid = srid - this.x = x - this.y = y - this.z = z - }, - Date: function Date (year, month, day) { - this.year = year - this.month = month - this.day = day - }, - DateTime: function DateTime ( - year, - month, - day, - hour, - minute, - second, - nanosecond, - timeZoneOffsetSeconds, - timeZoneId - ) { - this.year = year - this.month = month - this.day = day - this.hour = hour - this.minute = minute - this.second = second - this.nanosecond = nanosecond - this.timeZoneOffsetSeconds = timeZoneOffsetSeconds - this.timeZoneId = timeZoneId - }, - Duration: function Duration (months, days, seconds, nanoseconds) { - this.months = months - this.days = days - this.seconds = seconds - this.nanoseconds = nanoseconds - }, - LocalDateTime: function LocalDateTime ( - year, - month, - day, - hour, - minute, - second, - nanosecond - ) { - this.year = year - this.month = month - this.day = day - this.hour = hour - this.minute = minute - this.second = second - this.nanosecond = nanosecond - }, - LocalTime: function LocalTime (hour, minute, second, nanosecond) { - this.hour = hour - this.minute = minute - this.second = second - this.nanosecond = nanosecond - }, - Time: function Time ( - hour, - minute, - second, - nanosecond, - timeZoneOffsetSeconds - ) { - this.hour = hour - this.minute = minute - this.second = second - this.nanosecond = nanosecond - this.timeZoneOffsetSeconds = timeZoneOffsetSeconds - } - }, - Integer: function Integer (low, high) { - this.low = low - this.high = high - } - } -} - -out.v1.types.Node.prototype.toString = function () { - return 'node' -} -out.v1.types.Relationship.prototype.toString = function () { - return 'rel' -} -out.v1.types.Path.prototype.toString = function () { - return 'path' -} -out.v1.types.PathSegment.prototype.toString = function () { - return 'pathsegment' -} -out.v1.types.Point.prototype.toString = function () { - return 'point' -} -out.v1.types.Date.prototype.toString = function () { - return 'date' -} -out.v1.types.DateTime.prototype.toString = function () { - return 'datetime' -} -out.v1.types.Duration.prototype.toString = function () { - return 'duration' -} -out.v1.types.LocalDateTime.prototype.toString = function () { - return 'localdatetime' -} -out.v1.types.LocalTime.prototype.toString = function () { - return 'localtime' -} -out.v1.types.Time.prototype.toString = function () { - return 'time' -} -out.v1.Integer.prototype.toInt = function () { - return this.low -} -out.v1.Integer.prototype.toString = function () { - return this.low -} -out.v1.Int = out.v1.Integer -out.v1.int = val => { - if (val /* is compatible */ instanceof out.v1.Integer) return val - if (typeof val === 'number') return new out.v1.Integer(val) - if (typeof val === 'string') return new out.v1.Integer(val) - // Throws for non-objects, converts non-instanceof Integer: - return new out.v1.Integer(val.low, val.high) -} - -module.exports = out diff --git a/package.json b/package.json index 5e10a5063f4..21513c2267a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html)$": "/__mocks__/fileMock.js", "\\.(css|less)$": "/__mocks__/styleMock.js", - "neo4j": "/__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", diff --git a/src/browser/modules/Stream/CypherFrame/helpers.test.js b/src/browser/modules/Stream/CypherFrame/helpers.test.js index 659776cf95d..54b45d0777d 100644 --- a/src/browser/modules/Stream/CypherFrame/helpers.test.js +++ b/src/browser/modules/Stream/CypherFrame/helpers.test.js @@ -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 { @@ -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) @@ -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'] } ] @@ -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) diff --git a/src/shared/services/bolt/applyGraphTypes.test.js b/src/shared/services/bolt/applyGraphTypes.test.js index ab5b6885d22..ad583e1e76f 100644 --- a/src/shared/services/bolt/applyGraphTypes.test.js +++ b/src/shared/services/bolt/applyGraphTypes.test.js @@ -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', () => { @@ -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', () => { @@ -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') }) @@ -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) @@ -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') @@ -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', () => { @@ -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') }) @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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 @@ -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) @@ -423,7 +424,7 @@ describe('applyGraphTypes', () => { 12, 44, 0, - 3600, + null, 'Europe/Stockholm' ) const rawDateTime = nativeTypesToCustom(dateTime)