@@ -536,33 +536,123 @@ describe('Hive - List Store', function() {
536
536
537
537
describe ( 'Set' , async ( ) => {
538
538
it ( 'success' , async ( ) => {
539
- const request = prepareMockRequest ( fakeResult )
539
+ const composeRequest = async value => {
540
+ const request = prepareMockRequest ( fakeResult )
540
541
541
- const result = await store . set ( [ 'value1' , 'value2' ] )
542
+ const result = await store . set ( value )
542
543
543
- expect ( request ) . to . deep . include ( {
544
- method : 'PUT' ,
545
- path : `${ APP_PATH } /hive/${ hiveName } /list/${ storeKey } ` ,
546
- body : [ 'value1' , 'value2' ]
547
- } )
544
+ const payload = {
545
+ method : 'PUT' ,
546
+ path : `${ APP_PATH } /hive/${ hiveName } /list/${ storeKey } ` ,
547
+ body : value
548
+ }
548
549
549
- expect ( result ) . to . be . eql ( fakeResult )
550
+ return { request, result, payload }
551
+ }
552
+
553
+ const request1 = await composeRequest ( [ 'string' ] )
554
+ const request2 = await composeRequest ( [ '' ] )
555
+ const request3 = await composeRequest ( [ false ] )
556
+ const request4 = await composeRequest ( [ true ] )
557
+ const request5 = await composeRequest ( [ [ ] ] )
558
+ const request6 = await composeRequest ( [ 123 ] )
559
+ const request7 = await composeRequest ( [ { a : 1 } ] )
560
+
561
+ expect ( request1 . request ) . to . deep . include ( request1 . payload )
562
+ expect ( request2 . request ) . to . deep . include ( request2 . payload )
563
+ expect ( request3 . request ) . to . deep . include ( request3 . payload )
564
+ expect ( request4 . request ) . to . deep . include ( request4 . payload )
565
+ expect ( request5 . request ) . to . deep . include ( request5 . payload )
566
+ expect ( request6 . request ) . to . deep . include ( request6 . payload )
567
+ expect ( request7 . request ) . to . deep . include ( request7 . payload )
568
+
569
+ expect ( request1 . result ) . to . be . eql ( fakeResult )
570
+ expect ( request2 . result ) . to . be . eql ( fakeResult )
571
+ expect ( request3 . result ) . to . be . eql ( fakeResult )
572
+ expect ( request4 . result ) . to . be . eql ( fakeResult )
573
+ expect ( request5 . result ) . to . be . eql ( fakeResult )
574
+ expect ( request6 . result ) . to . be . eql ( fakeResult )
575
+ expect ( request7 . result ) . to . be . eql ( fakeResult )
550
576
} )
551
577
552
- it ( 'success with index' , async ( ) => {
553
- const request = prepareMockRequest ( fakeResult )
578
+ it ( 'success values with index' , async ( ) => {
579
+ const composeRequest = async value => {
580
+ const request = prepareMockRequest ( fakeResult )
554
581
555
- const result = await store . set ( 'value1' , 0 )
582
+ const result = await store . set ( value , 0 )
556
583
557
- expect ( request ) . to . deep . include ( {
558
- method : 'PUT' ,
559
- path : `${ APP_PATH } /hive/${ hiveName } /list/${ storeKey } /0` ,
560
- body : {
561
- value : 'value1'
584
+ const payload = {
585
+ method : 'PUT' ,
586
+ path : `${ APP_PATH } /hive/${ hiveName } /list/${ storeKey } /0` ,
587
+ body : {
588
+ value : value
589
+ }
562
590
}
563
- } )
564
591
565
- expect ( result ) . to . be . eql ( fakeResult )
592
+ return { request, result, payload }
593
+ }
594
+
595
+ const request1 = await composeRequest ( 'string' )
596
+ const request2 = await composeRequest ( '' )
597
+ const request3 = await composeRequest ( false )
598
+ const request4 = await composeRequest ( true )
599
+ const request5 = await composeRequest ( [ ] )
600
+ const request6 = await composeRequest ( 123 )
601
+ const request7 = await composeRequest ( 0 )
602
+ const request8 = await composeRequest ( { a : 1 } )
603
+
604
+ expect ( request1 . request ) . to . deep . include ( request1 . payload )
605
+ expect ( request2 . request ) . to . deep . include ( request2 . payload )
606
+ expect ( request3 . request ) . to . deep . include ( request3 . payload )
607
+ expect ( request4 . request ) . to . deep . include ( request4 . payload )
608
+ expect ( request5 . request ) . to . deep . include ( request5 . payload )
609
+ expect ( request6 . request ) . to . deep . include ( request6 . payload )
610
+ expect ( request7 . request ) . to . deep . include ( request7 . payload )
611
+ expect ( request8 . request ) . to . deep . include ( request8 . payload )
612
+
613
+ expect ( request1 . result ) . to . be . eql ( fakeResult )
614
+ expect ( request2 . result ) . to . be . eql ( fakeResult )
615
+ expect ( request3 . result ) . to . be . eql ( fakeResult )
616
+ expect ( request4 . result ) . to . be . eql ( fakeResult )
617
+ expect ( request5 . result ) . to . be . eql ( fakeResult )
618
+ expect ( request6 . result ) . to . be . eql ( fakeResult )
619
+ expect ( request7 . result ) . to . be . eql ( fakeResult )
620
+ expect ( request8 . result ) . to . be . eql ( fakeResult )
621
+ } )
622
+
623
+ it ( 'fails with invalid value' , async ( ) => {
624
+ store = Backendless . Hive ( hiveName ) . ListStore ( storeKey )
625
+
626
+ const errorMsg = 'Value must be provided and must be a list of valid JSON items.'
627
+
628
+ await expect ( ( ) => store . set ( undefined ) ) . to . throw ( errorMsg )
629
+ await expect ( ( ) => store . set ( null ) ) . to . throw ( errorMsg )
630
+ await expect ( ( ) => store . set ( [ ] ) ) . to . throw ( errorMsg )
631
+ await expect ( ( ) => store . set ( 'string' ) ) . to . throw ( errorMsg )
632
+ await expect ( ( ) => store . set ( '' ) ) . to . throw ( errorMsg )
633
+ await expect ( ( ) => store . set ( 0 ) ) . to . throw ( errorMsg )
634
+ await expect ( ( ) => store . set ( false ) ) . to . throw ( errorMsg )
635
+ await expect ( ( ) => store . set ( '' ) ) . to . throw ( errorMsg )
636
+ await expect ( ( ) => store . set ( true ) ) . to . throw ( errorMsg )
637
+ await expect ( ( ) => store . set ( 123 ) ) . to . throw ( errorMsg )
638
+ await expect ( ( ) => store . set ( ( ) => undefined ) ) . to . throw ( errorMsg )
639
+ await expect ( ( ) => store . set ( { } ) ) . to . throw ( errorMsg )
640
+ await expect ( ( ) => store . set ( Symbol ( 'id' ) ) ) . to . throw ( errorMsg )
641
+ await expect ( ( ) => store . set ( 10n ) ) . to . throw ( errorMsg )
642
+ await expect ( ( ) => store . set ( [ 10n ] ) ) . to . throw ( errorMsg )
643
+ } )
644
+
645
+ it ( 'fails with index' , async ( ) => {
646
+ store = Backendless . Hive ( hiveName ) . ListStore ( storeKey )
647
+
648
+ const errorMsg = 'Value must be provided and must be one of types: string, number, boolean, object, array.'
649
+
650
+ await expect ( ( ) => store . set ( undefined , 0 ) ) . to . throw ( errorMsg )
651
+ await expect ( ( ) => store . set ( null , 0 ) ) . to . throw ( errorMsg )
652
+ await expect ( ( ) => store . set ( ( ) => true , 0 ) ) . to . throw ( errorMsg )
653
+ await expect ( ( ) => store . set ( 10n , 0 ) ) . to . throw ( errorMsg )
654
+ await expect ( ( ) => store . set ( Symbol ( 'id' ) , 0 ) ) . to . throw ( errorMsg )
655
+ await expect ( ( ) => store . set ( [ 10n ] , 0 ) ) . to . throw ( errorMsg )
566
656
} )
567
657
568
658
it ( 'fails with invalid index' , async ( ) => {
@@ -573,11 +663,14 @@ describe('Hive - List Store', function() {
573
663
await expect ( ( ) => store . set ( 'v' , null ) ) . to . throw ( errorMsg )
574
664
await expect ( ( ) => store . set ( 'v' , NaN ) ) . to . throw ( errorMsg )
575
665
await expect ( ( ) => store . set ( 'v' , false ) ) . to . throw ( errorMsg )
666
+ await expect ( ( ) => store . set ( 'v' , true ) ) . to . throw ( errorMsg )
576
667
await expect ( ( ) => store . set ( 'v' , '' ) ) . to . throw ( errorMsg )
577
668
await expect ( ( ) => store . set ( 'v' , 'qwe' ) ) . to . throw ( errorMsg )
578
- await expect ( ( ) => store . set ( 'v' , true ) ) . to . throw ( errorMsg )
669
+ await expect ( ( ) => store . set ( 'v' , 10n ) ) . to . throw ( errorMsg )
670
+ await expect ( ( ) => store . set ( 'v' , Symbol ( 'id' ) ) ) . to . throw ( errorMsg )
579
671
await expect ( ( ) => store . set ( 'v' , ( ) => undefined ) ) . to . throw ( errorMsg )
580
672
await expect ( ( ) => store . set ( 'v' , { } ) ) . to . throw ( errorMsg )
673
+ await expect ( ( ) => store . set ( 'v' , [ ] ) ) . to . throw ( errorMsg )
581
674
} )
582
675
} )
583
676
@@ -693,7 +786,7 @@ describe('Hive - List Store', function() {
693
786
} )
694
787
695
788
it ( 'fails with invalid ValueToInsert' , async ( ) => {
696
- const errorMsg = 'ValueToInsert must be provided and must be on of types: string, number, boolean, object, array.'
789
+ const errorMsg = 'ValueToInsert must be provided and must be one of types: string, number, boolean, object, array.'
697
790
698
791
await expect ( ( ) => store . insertBefore ( undefined , 'v' ) ) . to . throw ( errorMsg )
699
792
await expect ( ( ) => store . insertBefore ( null , 'v' ) ) . to . throw ( errorMsg )
@@ -811,7 +904,7 @@ describe('Hive - List Store', function() {
811
904
} )
812
905
813
906
it ( 'fails with invalid ValueToInsert' , async ( ) => {
814
- const errorMsg = 'ValueToInsert must be provided and must be on of types: string, number, boolean, object, array.'
907
+ const errorMsg = 'ValueToInsert must be provided and must be one of types: string, number, boolean, object, array.'
815
908
816
909
await expect ( ( ) => store . insertAfter ( undefined , 'v' ) ) . to . throw ( errorMsg )
817
910
await expect ( ( ) => store . insertAfter ( null , 'v' ) ) . to . throw ( errorMsg )
@@ -1035,7 +1128,6 @@ describe('Hive - List Store', function() {
1035
1128
await expect ( ( ) => store . addFirstValues ( { } ) ) . to . throw ( errorMsg )
1036
1129
await expect ( ( ) => store . addFirstValues ( Symbol ( 'id' ) ) ) . to . throw ( errorMsg )
1037
1130
await expect ( ( ) => store . addFirstValues ( 10n ) ) . to . throw ( errorMsg )
1038
- await expect ( ( ) => store . addFirstValues ( [ ] ) ) . to . throw ( errorMsg )
1039
1131
await expect ( ( ) => store . addFirstValues ( [ 10n ] ) ) . to . throw ( errorMsg )
1040
1132
} )
1041
1133
} )
0 commit comments