@@ -22,7 +22,11 @@ import {
22
22
Relationship ,
23
23
isRelationship ,
24
24
UnboundRelationship ,
25
- isUnboundRelationship
25
+ isUnboundRelationship ,
26
+ Path ,
27
+ PathSegment ,
28
+ isPath ,
29
+ isPathSegment
26
30
} from '../src/graph-types'
27
31
28
32
import {
@@ -70,12 +74,30 @@ describe('Node', () => {
70
74
expect ( node . toString ( ) ) . toMatchSnapshot ( )
71
75
} )
72
76
73
- test . each ( validNodes ( ) ) ( 'should be consider a node' , ( node : any ) => {
77
+ test . each ( validNodes ( ) ) ( 'should be consider a node' , ( node : unknown ) => {
74
78
expect ( isNode ( node ) ) . toBe ( true )
79
+
80
+ if ( isNode ( node ) ) {
81
+ const typedNode : Node = node
82
+ expect ( typedNode ) . toEqual ( node )
83
+ } else {
84
+ // @ts -expect-error
85
+ const typedNode : Node = node
86
+ expect ( typedNode ) . toEqual ( node )
87
+ }
75
88
} )
76
89
77
- test . each ( nonNodes ( ) ) ( 'should not consider a non-node object as node' , nonNode => {
90
+ test . each ( nonNodes ( ) ) ( 'should not consider a non-node object as node' , ( nonNode : unknown ) => {
78
91
expect ( isNode ( nonNode ) ) . toBe ( false )
92
+
93
+ if ( isNode ( nonNode ) ) {
94
+ const typedNode : Node = nonNode
95
+ expect ( typedNode ) . toEqual ( nonNode )
96
+ } else {
97
+ // @ts -expect-error
98
+ const typedNode : Node = nonNode
99
+ expect ( typedNode ) . toEqual ( nonNode )
100
+ }
79
101
} )
80
102
81
103
test ( 'should type mapping labels' , ( ) => {
@@ -219,6 +241,32 @@ describe('Relationship', () => {
219
241
const _ : 'DIRECTED' = a . type
220
242
} )
221
243
244
+ test . each ( validRelationships ( ) ) ( 'should be consider a relationship' , ( relationship : unknown ) => {
245
+ expect ( isRelationship ( relationship ) ) . toBe ( true )
246
+
247
+ if ( isRelationship ( relationship ) ) {
248
+ const typedRelationship : Relationship = relationship
249
+ expect ( typedRelationship ) . toEqual ( relationship )
250
+ } else {
251
+ // @ts -expect-error
252
+ const typedRelationship : Relationship = relationship
253
+ expect ( typedRelationship ) . toEqual ( relationship )
254
+ }
255
+ } )
256
+
257
+ test . each ( nonRelationships ( ) ) ( 'should not consider a non-relationship object as relationship' , ( nonRelationship : unknown ) => {
258
+ expect ( isRelationship ( nonRelationship ) ) . toBe ( false )
259
+
260
+ if ( isRelationship ( nonRelationship ) ) {
261
+ const typedRelationship : Relationship = nonRelationship
262
+ expect ( typedRelationship ) . toEqual ( nonRelationship )
263
+ } else {
264
+ // @ts -expect-error
265
+ const typedRelationship : Relationship = nonRelationship
266
+ expect ( typedRelationship ) . toEqual ( nonRelationship )
267
+ }
268
+ } )
269
+
222
270
function validRelationships ( ) : any [ ] {
223
271
return [
224
272
[ new Relationship ( 1 , 2 , 3 , 'Rel' , { } , 'elementId' , 'startNodeElementId' , 'endNodeElementId' ) ] ,
@@ -346,6 +394,32 @@ describe('UnboundRelationship', () => {
346
394
const _ : 'DIRECTED' = a . type
347
395
} )
348
396
397
+ test . each ( validUnboundRelationships ( ) ) ( 'should be consider a unbound relationship' , ( unboundRelationship : unknown ) => {
398
+ expect ( isUnboundRelationship ( unboundRelationship ) ) . toBe ( true )
399
+
400
+ if ( isUnboundRelationship ( unboundRelationship ) ) {
401
+ const typedRelationship : UnboundRelationship = unboundRelationship
402
+ expect ( typedRelationship ) . toEqual ( unboundRelationship )
403
+ } else {
404
+ // @ts -expect-error
405
+ const typedRelationship : UnboundRelationship = unboundRelationship
406
+ expect ( typedRelationship ) . toEqual ( unboundRelationship )
407
+ }
408
+ } )
409
+
410
+ test . each ( nonUnboundRelationships ( ) ) ( 'should not consider a non-unbound relationship object as unbound relationship' , ( nonUnboundRelationship : unknown ) => {
411
+ expect ( isUnboundRelationship ( nonUnboundRelationship ) ) . toBe ( false )
412
+
413
+ if ( isUnboundRelationship ( nonUnboundRelationship ) ) {
414
+ const typedRelationship : UnboundRelationship = nonUnboundRelationship
415
+ expect ( typedRelationship ) . toEqual ( nonUnboundRelationship )
416
+ } else {
417
+ // @ts -expect-error
418
+ const typedRelationship : UnboundRelationship = nonUnboundRelationship
419
+ expect ( typedRelationship ) . toEqual ( nonUnboundRelationship )
420
+ }
421
+ } )
422
+
349
423
function validUnboundRelationships ( ) : any [ ] {
350
424
return [
351
425
[ new UnboundRelationship ( 1 , 'Rel' , { } , 'elementId' ) ] ,
@@ -388,6 +462,111 @@ describe('UnboundRelationship', () => {
388
462
}
389
463
} )
390
464
465
+ describe ( 'Path' , ( ) => {
466
+ test . each ( validPaths ( ) ) ( 'should be consider a path' , ( path : unknown ) => {
467
+ expect ( isPath ( path ) ) . toBe ( true )
468
+
469
+ if ( isPath ( path ) ) {
470
+ const typed : Path = path
471
+ expect ( typed ) . toEqual ( path )
472
+ } else {
473
+ // @ts -expect-error
474
+ const typed : Path = path
475
+ expect ( typed ) . toEqual ( path )
476
+ }
477
+ } )
478
+
479
+ test . each ( nonPaths ( ) ) ( 'should not consider a non-path object as path' , ( nonPath : unknown ) => {
480
+ expect ( isPath ( nonPath ) ) . toBe ( false )
481
+
482
+ if ( isPath ( nonPath ) ) {
483
+ const typed : Path = nonPath
484
+ expect ( typed ) . toEqual ( nonPath )
485
+ } else {
486
+ // @ts -expect-error
487
+ const typed : Path = nonPath
488
+ expect ( typed ) . toEqual ( nonPath )
489
+ }
490
+ } )
491
+
492
+ function validPaths ( ) : any [ ] {
493
+ return [
494
+ [ new Path ( new Node ( 1 , [ ] , { } ) , new Node ( 2 , [ ] , { } ) , [ ] ) ] ,
495
+ [ new Path ( new Node ( 1 , [ ] , { } ) , new Node ( 2 , [ ] , { } ) , [ new PathSegment ( new Node ( 1 , [ ] , { } ) , new Relationship ( 1 , 1 , 2 , 'type' , { } ) , new Node ( 2 , [ ] , { } ) ) ] ) ]
496
+ ]
497
+ }
498
+
499
+ function nonPaths ( ) : any [ ] {
500
+ return [
501
+ [ {
502
+ start : new Node ( 1 , [ ] , { } ) ,
503
+ end : new Node ( 2 , [ ] , { } ) ,
504
+ length : 1 ,
505
+ segments : [
506
+ new PathSegment (
507
+ new Node ( 1 , [ ] , { } ) ,
508
+ new Relationship ( 1 , 1 , 2 , 'type' , { } ) ,
509
+ new Node ( 2 , [ ] , { } ) )
510
+ ]
511
+ } ] ,
512
+ [ null ] ,
513
+ [ undefined ] ,
514
+ [ { } ] ,
515
+ [ 1 ]
516
+ ]
517
+ }
518
+ } )
519
+
520
+ describe ( 'Path' , ( ) => {
521
+ test . each ( validPathSegments ( ) ) ( 'should be consider a path segment' , ( pathSegment : unknown ) => {
522
+ expect ( isPathSegment ( pathSegment ) ) . toBe ( true )
523
+
524
+ if ( isPathSegment ( pathSegment ) ) {
525
+ const typed : PathSegment = pathSegment
526
+ expect ( typed ) . toEqual ( pathSegment )
527
+ } else {
528
+ // @ts -expect-error
529
+ const typed : PathSegment = pathSegment
530
+ expect ( typed ) . toEqual ( pathSegment )
531
+ }
532
+ } )
533
+
534
+ test . each ( nonPathSegments ( ) ) ( 'should not consider a non-path object as path segument' , ( nonPathSegment : unknown ) => {
535
+ expect ( isPathSegment ( nonPathSegment ) ) . toBe ( false )
536
+
537
+ if ( isPathSegment ( nonPathSegment ) ) {
538
+ const typed : PathSegment = nonPathSegment
539
+ expect ( typed ) . toEqual ( nonPathSegment )
540
+ } else {
541
+ // @ts -expect-error
542
+ const typed : PathSegment = nonPathSegment
543
+ expect ( typed ) . toEqual ( nonPathSegment )
544
+ }
545
+ } )
546
+
547
+ function validPathSegments ( ) : any [ ] {
548
+ return [
549
+ [ new PathSegment ( new Node ( 1 , [ ] , { } ) , new Relationship ( 1 , 1 , 2 , 'type' , { } ) , new Node ( 2 , [ ] , { } ) ) ] ,
550
+ [ new PathSegment ( new Node ( int ( 1 ) , [ ] , { } ) , new Relationship ( int ( 1 ) , int ( 1 ) , int ( 2 ) , 'type' , { } ) , new Node ( int ( 2 ) , [ ] , { } ) ) ]
551
+ ]
552
+ }
553
+
554
+ function nonPathSegments ( ) : any [ ] {
555
+ return [
556
+ [ {
557
+
558
+ start : new Node ( 1 , [ ] , { } ) ,
559
+ end : new Node ( 2 , [ ] , { } ) ,
560
+ relationship : new Relationship ( 1 , 1 , 2 , 'type' , { } )
561
+ } ] ,
562
+ [ null ] ,
563
+ [ undefined ] ,
564
+ [ { } ] ,
565
+ [ 1 ]
566
+ ]
567
+ }
568
+ } )
569
+
391
570
function validIdentityAndExpectedElementIds ( ) : any [ ] {
392
571
return [
393
572
[ 10 , '10' ] ,
0 commit comments