2
2
/*global assertEqual, assertTrue, assertFalse, assertNotNull, assertNotUndefined, fail */
3
3
4
4
////////////////////////////////////////////////////////////////////////////////
5
- /// @brief test the collection interface
6
- ///
7
- /// @file
8
- ///
9
5
/// DISCLAIMER
10
6
///
11
7
/// Copyright 2020 ArangoDB Inc, Cologne, Germany
@@ -34,6 +30,7 @@ const { getEndpointById } = require('@arangodb/test-helper');
34
30
const request = require ( '@arangodb/request' ) ;
35
31
const db = internal . db ;
36
32
const arangodb = require ( "@arangodb" ) ;
33
+ const _ = require ( "lodash" ) ;
37
34
const ERRORS = arangodb . errors ;
38
35
39
36
// helper
@@ -51,6 +48,19 @@ const waitInClusterUntil = func => {
51
48
}
52
49
} ;
53
50
51
+ const waitForCollectionPredicate = ( collection , predicate ) => {
52
+ const shardList = collection . shards ( true ) ;
53
+ for ( const [ shard , servers ] of Object . entries ( shardList ) ) {
54
+ const endpoint = getEndpointById ( servers [ 0 ] ) ;
55
+ const resp = request . get ( `${ endpoint } /_api/collection/${ shard } /properties` ) ;
56
+ assertEqual ( resp . statusCode , 200 ) ;
57
+ if ( ! predicate ( resp . json ) ) {
58
+ return false ;
59
+ }
60
+ }
61
+ return true ;
62
+ } ;
63
+
54
64
const skipOptions = { "skipDocumentValidation" : true } ;
55
65
56
66
function ValidationBasicsSuite ( ) {
@@ -330,15 +340,23 @@ function ValidationBasicsSuite() {
330
340
testLevelNone : ( ) => {
331
341
validatorJson . level = "none" ;
332
342
testCollection . properties ( { "schema" : validatorJson } ) ;
333
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
343
+ waitInClusterUntil ( ( ) => {
344
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
345
+ return json . schema . level === validatorJson . level ;
346
+ } ) ;
347
+ } ) ;
334
348
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
335
349
testCollection . insert ( badDoc ) ;
336
350
} ,
337
351
338
352
testLevelNew : ( ) => {
339
353
validatorJson . level = "new" ;
340
354
testCollection . properties ( { "schema" : validatorJson } ) ;
341
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
355
+ waitInClusterUntil ( ( ) => {
356
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
357
+ return json . schema . level === validatorJson . level ;
358
+ } ) ;
359
+ } ) ;
342
360
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
343
361
344
362
let doc = testCollection . insert ( badDoc , skipOptions ) ;
@@ -355,7 +373,11 @@ function ValidationBasicsSuite() {
355
373
testLevelModerateInsert : ( ) => {
356
374
validatorJson . level = "moderate" ;
357
375
testCollection . properties ( { "schema" : validatorJson } ) ;
358
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
376
+ waitInClusterUntil ( ( ) => {
377
+
9E88
return waitForCollectionPredicate ( testCollection , ( json ) => {
378
+ return json . schema . level === validatorJson . level ;
379
+ } ) ;
380
+ } ) ;
359
381
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
360
382
361
383
testCollection . insert ( badDoc , skipOptions ) ;
@@ -370,7 +392,11 @@ function ValidationBasicsSuite() {
370
392
testLevelModerateModifyBadToGood : ( ) => {
371
393
validatorJson . level = "moderate" ;
372
394
testCollection . properties ( { "schema" : validatorJson } ) ;
373
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
395
+ waitInClusterUntil ( ( ) => {
396
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
397
+ return json . schema . level === validatorJson . level ;
398
+ } ) ;
399
+ } ) ;
374
400
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
375
401
376
402
let doc ;
@@ -385,7 +411,11 @@ function ValidationBasicsSuite() {
385
411
testLevelModerateModifyBadWithBad : ( ) => {
386
412
validatorJson . level = "moderate" ;
387
413
testCollection . properties ( { "schema" : validatorJson } ) ;
388
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
414
+ waitInClusterUntil ( ( ) => {
415
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
416
+ return json . schema . level === validatorJson . level ;
417
+ } ) ;
418
+ } ) ;
389
419
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
390
420
391
421
let doc ;
@@ -409,7 +439,12 @@ function ValidationBasicsSuite() {
409
439
testLevelModerateUpdateGoodToBad : ( ) => {
410
440
validatorJson . level = "moderate" ;
411
441
testCollection . properties ( { "schema" : validatorJson } ) ;
412
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
442
+ waitInClusterUntil ( ( ) => {
443
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
444
+ return json . schema . level === validatorJson . level ;
445
+ } ) ;
446
+ return true ;
447
+ } ) ;
413
448
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
414
449
415
450
let doc = testCollection . insert ( goodDoc ) ;
@@ -433,7 +468,11 @@ function ValidationBasicsSuite() {
433
468
testLevelModerateReplaceGoodToBad : ( ) => {
434
469
validatorJson . level = "moderate" ;
435
470
testCollection . properties ( { "schema" : validatorJson } ) ;
436
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
471
+ waitInClusterUntil ( ( ) => {
472
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
473
+ return json . schema . level === validatorJson . level ;
474
+ } ) ;
475
+ } ) ;
437
476
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
438
477
439
478
let doc = testCollection . insert ( goodDoc ) ;
@@ -454,9 +493,6 @@ function ValidationBasicsSuite() {
454
493
} ,
455
494
456
495
testLevelStict : ( ) => {
457
- validatorJson . level = "strict" ;
458
- testCollection . properties ( { "schema" : validatorJson } ) ;
459
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
460
496
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
461
497
462
498
let doc = testCollection . insert ( badDoc , skipOptions ) ;
@@ -508,16 +544,9 @@ function ValidationBasicsSuite() {
508
544
}
509
545
testCollection . properties ( { "schema" : { } } ) ;
510
546
waitInClusterUntil ( ( ) => {
511
- const shardList = testCollection . shards ( true ) ;
512
- for ( const [ shard , servers ] of Object . entries ( shardList ) ) {
513
- const endpoint = getEndpointById ( servers [ 0 ] ) ;
514
- const resp = request . get ( `${ endpoint } /_api/collection/${ shard } /properties` ) ;
515
- assertEqual ( resp . statusCode , 200 ) ;
516
- if ( resp . json . schema != null ) {
517
- return false ;
518
- }
519
- }
520
- return true ;
547
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
548
+ return json . schema === null ;
549
+ } ) ;
521
550
} ) ;
522
551
assertEqual ( testCollection . properties ( ) . schema , null ) ;
523
552
testCollection . insert ( badDoc ) ;
@@ -533,16 +562,9 @@ function ValidationBasicsSuite() {
533
562
}
534
563
testCollection . properties ( { "schema" : null } ) ;
535
564
waitInClusterUntil ( ( ) => {
536
- const shardList = testCollection . shards ( true ) ;
537
- for ( const [ shard , servers ] of Object . entries ( shardList ) ) {
538
- const endpoint = getEndpointById ( servers [ 0 ] ) ;
539
- const resp = request . get ( `${ endpoint } /_api/collection/${ shard } /properties` ) ;
540
- assertEqual ( resp . statusCode , 200 ) ;
541
- if ( resp . json . schema != null ) {
542
- return false ;
543
- }
544
- }
545
- return true ;
565
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
566
+ return json . schema === null ;
567
+ } ) ;
546
568
} ) ;
547
569
assertEqual ( testCollection . properties ( ) . schema , null ) ;
548
570
testCollection . insert ( badDoc ) ;
@@ -551,9 +573,6 @@ function ValidationBasicsSuite() {
551
573
552
574
// json ////////////////////////////////////////////////////////////////////////////////////////////
553
575
testJson : ( ) => {
554
- validatorJson . level = "strict" ;
555
- testCollection . properties ( { "schema" : validatorJson } ) ;
556
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
557
576
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
558
577
559
578
testCollection . insert ( goodDoc ) ;
@@ -571,11 +590,19 @@ function ValidationBasicsSuite() {
571
590
required : [ "numArray" , "name" ]
572
591
} ;
573
592
validatorJson . rule = p ;
574
- validatorJson . level = "strict" ;
575
593
576
594
testCollection . properties ( { "schema" : validatorJson } ) ;
577
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
595
+ waitInClusterUntil ( ( ) => {
596
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
597
+ const rule = json . schema . rule ;
598
+ if ( ! rule . hasOwnProperty ( 'required' ) ) {
599
+ return false ;
600
+ }
601
+ return _ . isEqual ( rule . required , [ "numArray" , "name" ] ) ;
602
+ } ) ;
603
+ } ) ;
578
604
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
605
+ assertEqual ( testCollection . properties ( ) . schema . rule . required , validatorJson . rule . required ) ;
579
606
580
607
try {
581
608
// name missing
@@ -609,9 +636,6 @@ function ValidationBasicsSuite() {
609
636
} ,
610
637
// AQL ////////////////////////////////////////////////////////////////////////////////////////////
611
638
testAQLSchemaGet : ( ) => {
612
- validatorJson . level = "strict" ;
613
- testCollection . properties ( { "schema" : validatorJson } ) ;
614
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema . level === validatorJson . level ) ;
615
639
assertEqual ( testCollection . properties ( ) . schema . level , validatorJson . level ) ;
616
640
617
641
// get regular schema
@@ -641,7 +665,11 @@ function ValidationBasicsSuite() {
641
665
testAqlSchemaValidate : ( ) => {
642
666
// unset schema
643
667
testCollection . properties ( { schema : { } } ) ;
644
- waitInClusterUntil ( ( ) => testCollection . properties ( ) . schema == null ) ;
668
+ waitInClusterUntil ( ( ) => {
669
+ return waitForCollectionPredicate ( testCollection , ( json ) => {
670
+ return json . schema === null ;
671
+ } ) ;
672
+ } ) ;
645
673
646
674
let res ;
647
675
// doc is not an object
0 commit comments