Skip to content

Commit 0e202b1

Browse files
committed
Finish tests and deserialize all types
1 parent 0075505 commit 0e202b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+297
-195
lines changed

__tests__/neovis.tests.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ describe('Neovis', () => {
162162
expect(neovis.edges.length).toBe(1);
163163
});
164164

165+
it('should work with big int', async () => {
166+
testUtils.mockNormalRunSubscribe([
167+
testUtils.makeRecord([testUtils.makePathFromNodes([
168+
testUtils.makeNode([label1], {}, new Neo4j.types.Integer(0, 1)),
169+
testUtils.makeNode([label1], {}, new Neo4j.types.Integer(1, 1))
170+
], relationshipType)]),
171+
]);
172+
neovis.render();
173+
await testUtils.neovisRenderDonePromise(neovis);
174+
expect(neovis.nodes.length).toBe(2);
175+
expect(neovis.edges.length).toBe(1);
176+
expect(neovis.nodes.getIds()).toEqual(['4294967296', '4294967297']);
177+
});
178+
165179
it('should save record with multiple parameters', async () => {
166180
const firstNode = testUtils.makeNode([label1]);
167181
const secondNode = testUtils.makeNode([label1]);
@@ -238,7 +252,7 @@ describe('Neovis', () => {
238252
default: [testUtils.makeRecord([node])]
239253
},
240254
[sizeCypher]: {
241-
[node.identity]: [testUtils.makeRecord([Neo4j.int(1)])]
255+
[typeof node.identity === 'object' ? node.identity.toInt(): node.identity]: [testUtils.makeRecord([Neo4j.int(1)])]
242256
}
243257
});
244258

@@ -500,7 +514,7 @@ describe('Neovis', () => {
500514
default: [testUtils.makeRecord([node1])]
501515
},
502516
[sizeCypher]: {
503-
[node1.identity]: [testUtils.makeRecord([intPropertyValue])]
517+
[typeof node1.identity === 'object' ? node1.identity.toInt(): node1.identity]: [testUtils.makeRecord([intPropertyValue])]
504518
}
505519
});
506520
neovis.render();
@@ -545,7 +559,17 @@ describe('Neovis', () => {
545559
const retData = [new Neo4j.types.Record(
546560
['a', 'b', 'c', 'd'], [
547561
new Neo4j.types.Node(new Neo4j.types.Integer(0, 0), ['Test'], { test: 1, test2: new Neo4j.types.Integer(1, 0) }),
548-
new Neo4j.types.Node(new Neo4j.types.Integer(1, 0), ['Test'], {}),
562+
new Neo4j.types.Node(new Neo4j.types.Integer(1, 0), ['Test'], {
563+
test1: new Neo4j.types.Date(new Neo4j.types.Integer(1, 0), new Neo4j.types.Integer(1, 0), new Neo4j.types.Integer(1, 0)),
564+
test2: new Neo4j.types.DateTime(1, 2, 3, 4, 5, 6, 7, 8),
565+
test3: new Neo4j.types.DateTime(1, 2, 3, 4, 5, 6, 7, 8, 'US/Pacific'),
566+
test4: new Neo4j.types.Duration(1, 2, 3, 5),
567+
test5: new Neo4j.types.LocalDateTime(1, 2, 3, 4, 5, 6, 7),
568+
test6: new Neo4j.types.LocalTime(1, 2, 3, 4),
569+
test7: new Neo4j.types.Point(1, 2, 3, 4),
570+
test8: new Neo4j.types.Point(1, 2, 3),
571+
test9: new Neo4j.types.Time(1, 2, 3, 4, 5)
572+
}),
549573
new Neo4j.types.Relationship(new Neo4j.types.Integer(0, 0), new Neo4j.types.Integer(0, 0), new Neo4j.types.Integer(1, 0), 'TEST', {}),
550574
new Neo4j.types.Path(
551575
new Neo4j.types.Node(new Neo4j.types.Integer(2, 0), ['Test'], {}),
@@ -608,5 +632,21 @@ describe('Neovis', () => {
608632
await testUtils.neovisRenderDonePromise(neovis);
609633
expect(neovis.nodes.get(0)?.label).toBe(1);
610634
});
635+
it('should desriallize all neo4j types', async () => {
636+
neovis.render();
637+
await testUtils.neovisRenderDonePromise(neovis);
638+
expect(neovis.nodes.get(1)?.raw.properties.test1).toBeInstanceOf(Neo4j.types.Date);
639+
expect((neovis.nodes.get(1)?.raw.properties.test1 as any).year).toBeInstanceOf(Neo4j.types.Integer);
640+
expect((neovis.nodes.get(1)?.raw.properties.test1 as any).month).toBeInstanceOf(Neo4j.types.Integer);
641+
expect((neovis.nodes.get(1)?.raw.properties.test1 as any).day).toBeInstanceOf(Neo4j.types.Integer);
642+
expect(neovis.nodes.get(1)?.raw.properties.test2).toBeInstanceOf(Neo4j.types.DateTime);
643+
expect(neovis.nodes.get(1)?.raw.properties.test3).toBeInstanceOf(Neo4j.types.DateTime);
644+
expect(neovis.nodes.get(1)?.raw.properties.test4).toBeInstanceOf(Neo4j.types.Duration);
645+
expect(neovis.nodes.get(1)?.raw.properties.test5).toBeInstanceOf(Neo4j.types.LocalDateTime);
646+
expect(neovis.nodes.get(1)?.raw.properties.test6).toBeInstanceOf(Neo4j.types.LocalTime);
647+
expect(neovis.nodes.get(1)?.raw.properties.test7).toBeInstanceOf(Neo4j.types.Point);
648+
expect(neovis.nodes.get(1)?.raw.properties.test8).toBeInstanceOf(Neo4j.types.Point);
649+
expect(neovis.nodes.get(1)?.raw.properties.test9).toBeInstanceOf(Neo4j.types.Time);
650+
});
611651
});
612652
});

__tests__/testUtils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ export function clearIdCounter(): void {
1818
counter = 1;
1919
}
2020

21-
export function makeNode(labels: string[], properties: Record<string, unknown> = {}): Neo4jCore.Node<number> {
22-
return new Neo4jCore.Node(counter++, labels, properties);
21+
export function makeNode(labels: string[], properties: Record<string, unknown> = {}, id?: Neo4jCore.Integer | number): Neo4jCore.Node<Neo4jCore.Integer | number> {
22+
return new Neo4jCore.Node(id ?? new Neo4jCore.Integer(counter++, 0), labels, properties);
2323
}
2424

25-
export function makeRelationship(type: string, startNode: Neo4jCore.Node<number>, endNode: Neo4jCore.Node<number>, properties: Record<string, unknown> = {}): Neo4jCore.Relationship<number> {
25+
export function makeRelationship(type: string, startNode: Neo4jCore.Node<number | Neo4jCore.Integer>, endNode: Neo4jCore.Node<number | Neo4jCore.Integer>, properties: Record<string, unknown> = {}): Neo4jCore.Relationship<number | Neo4jCore.Integer> {
2626
return new Neo4jCore.Relationship(counter++, startNode.identity, endNode.identity, type, properties);
2727
}
2828

29-
export function makePathFromNodes(nodes: Neo4jType.Node<number>[], relationshipType: string): Neo4jCore.Path<number> {
30-
const pathSegments: Neo4jCore.PathSegment<number>[] = [];
29+
export function makePathFromNodes(nodes: Neo4jType.Node<number | Neo4jCore.Integer>[], relationshipType: string): Neo4jCore.Path<number | Neo4jCore.Integer> {
30+
const pathSegments: Neo4jCore.PathSegment<number | Neo4jCore.Integer>[] = [];
3131
for (let i = 0; i < nodes.length - 1; i++) {
3232
pathSegments.push(new Neo4jCore.PathSegment(
3333
nodes[i],

dist/main.map2489d4e85c450ccb9a89

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/main.map3b1a796034f11ac32d28

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

dist/main.map17f7ad97fc82072a62f9 renamed to dist/main.mapee859397c970b34f7589

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/neovis-without-dependencies.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export declare class NeoVis {
5050
/**
5151
* Renders the network
5252
*/
53-
render(query?: Cypher, parameters?: any): void;
53+
render(query?: Cypher, parameters?: unknown): void;
5454
/**
5555
* Clear the data for the visualization
5656
*/

dist/neovis.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export interface BaseNeovisConfig {
105105
* function to get the data instead of neo4j driver
106106
* @returns list of neo4j data
107107
*/
108-
dataFunction?: (any?: any) => AsyncIterable<Neo4jTypes.Record> | Promise<Iterable<Neo4jTypes.Record>>;
108+
dataFunction?: (any?: unknown) => AsyncIterable<Neo4jTypes.Record> | Promise<Iterable<Neo4jTypes.Record>> | Iterable<Neo4jTypes.Record>;
109109
/**
110110
* The Cypher query that will get the data
111111
*/
@@ -321,7 +321,6 @@ export interface Node extends VisNetwork.Node {
321321
/**
322322
* @link https://neo4j.com/docs/api/javascript-driver/current/class/src/graph-types.js~Node.html
323323
*/
324-
id: number;
325324
raw: Neo4jTypes.Node<NumberOrInteger>;
326325
}
327326
/**
@@ -331,6 +330,6 @@ export interface Edge extends VisNetwork.Edge {
331330
/**
332331
* https://neo4j.com/docs/api/javascript-driver/current/class/src/graph-types.js~Relationship.html
333332
*/
334-
id: number;
333+
id: number | string;
335334
raw: Neo4jTypes.Relationship<NumberOrInteger>;
336335
}

docs/assets/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)