4
4
const transform = require ( '../lib/Adapters/Storage/Mongo/MongoTransform' ) ;
5
5
const dd = require ( 'deep-diff' ) ;
6
6
const mongodb = require ( 'mongodb' ) ;
7
+ const Utils = require ( '../lib/Utils' ) ;
7
8
8
9
describe ( 'parseObjectToMongoObjectForCreate' , ( ) => {
9
10
it ( 'a basic number' , done => {
@@ -592,7 +593,7 @@ describe('relativeTimeToDate', () => {
592
593
describe ( 'In the future' , ( ) => {
593
594
it ( 'should parse valid natural time' , ( ) => {
594
595
const text = 'in 1 year 2 weeks 12 days 10 hours 24 minutes 30 seconds' ;
595
- const { result, status, info } = transform . relativeTimeToDate ( text , now ) ;
596
+ const { result, status, info } = Utils . relativeTimeToDate ( text , now ) ;
596
597
expect ( result . toISOString ( ) ) . toBe ( '2018-10-22T23:52:46.617Z' ) ;
597
598
expect ( status ) . toBe ( 'success' ) ;
598
599
expect ( info ) . toBe ( 'future' ) ;
@@ -602,7 +603,7 @@ describe('relativeTimeToDate', () => {
602
603
describe ( 'In the past' , ( ) => {
603
604
it ( 'should parse valid natural time' , ( ) => {
604
605
const text = '2 days 12 hours 1 minute 12 seconds ago' ;
605
- const { result, status, info } = transform . relativeTimeToDate ( text , now ) ;
606
+ const { result, status, info } = Utils . relativeTimeToDate ( text , now ) ;
606
607
expect ( result . toISOString ( ) ) . toBe ( '2017-09-24T01:27:04.617Z' ) ;
607
608
expect ( status ) . toBe ( 'success' ) ;
608
609
expect ( info ) . toBe ( 'past' ) ;
@@ -612,7 +613,7 @@ describe('relativeTimeToDate', () => {
612
613
describe ( 'From now' , ( ) => {
613
614
it ( 'should equal current time' , ( ) => {
614
615
const text = 'now' ;
615
- const { result, status, info } = transform . relativeTimeToDate ( text , now ) ;
616
+ const { result, status, info } = Utils . relativeTimeToDate ( text , now ) ;
616
617
expect ( result . toISOString ( ) ) . toBe ( '2017-09-26T13:28:16.617Z' ) ;
617
618
expect ( status ) . toBe ( 'success' ) ;
618
619
expect ( info ) . toBe ( 'present' ) ;
@@ -621,54 +622,54 @@ describe('relativeTimeToDate', () => {
621
622
622
623
describe ( 'Error cases' , ( ) => {
623
624
it ( 'should error if string is completely gibberish' , ( ) => {
624
- expect ( transform . relativeTimeToDate ( 'gibberishasdnklasdnjklasndkl123j123' ) ) . toEqual ( {
625
+ expect ( Utils . relativeTimeToDate ( 'gibberishasdnklasdnjklasndkl123j123' ) ) . toEqual ( {
625
626
status : 'error' ,
626
627
info : "Time should either start with 'in' or end with 'ago'" ,
627
628
} ) ;
628
629
} ) ;
629
630
630
631
it ( 'should error if string contains neither `ago` nor `in`' , ( ) => {
631
- expect ( transform . relativeTimeToDate ( '12 hours 1 minute' ) ) . toEqual ( {
632
+ expect ( Utils . relativeTimeToDate ( '12 hours 1 minute' ) ) . toEqual ( {
632
633
status : 'error' ,
633
634
info : "Time should either start with 'in' or end with 'ago'" ,
634
635
} ) ;
635
636
} ) ;
636
637
637
638
it ( 'should error if there are missing units or numbers' , ( ) => {
638
- expect ( transform . relativeTimeToDate ( 'in 12 hours 1' ) ) . toEqual ( {
639
+ expect ( Utils . relativeTimeToDate ( 'in 12 hours 1' ) ) . toEqual ( {
639
640
status : 'error' ,
640
641
info : 'Invalid time string. Dangling unit or number.' ,
641
642
} ) ;
642
643
643
- expect ( transform . relativeTimeToDate ( '12 hours minute ago' ) ) . toEqual ( {
644
+ expect ( Utils . relativeTimeToDate ( '12 hours minute ago' ) ) . toEqual ( {
644
645
status : 'error' ,
645
646
info : 'Invalid time string. Dangling unit or number.' ,
646
647
} ) ;
647
648
} ) ;
648
649
649
650
it ( 'should error on floating point numbers' , ( ) => {
650
- expect ( transform . relativeTimeToDate ( 'in 12.3 hours' ) ) . toEqual ( {
651
+ expect ( Utils . relativeTimeToDate ( 'in 12.3 hours' ) ) . toEqual ( {
651
652
status : 'error' ,
652
653
info : "'12.3' is not an integer." ,
653
654
} ) ;
654
655
} ) ;
655
656
656
657
it ( 'should error if numbers are invalid' , ( ) => {
657
- expect ( transform . relativeTimeToDate ( '12 hours 123a minute ago' ) ) . toEqual ( {
658
+ expect ( Utils . relativeTimeToDate ( '12 hours 123a minute ago' ) ) . toEqual ( {
658
659
status : 'error' ,
659
660
info : "'123a' is not an integer." ,
660
661
} ) ;
661
662
} ) ;
662
663
663
664
it ( 'should error on invalid interval units' , ( ) => {
664
- expect ( transform . relativeTimeToDate ( '4 score 7 years ago' ) ) . toEqual ( {
665
+ expect ( Utils . relativeTimeToDate ( '4 score 7 years ago' ) ) . toEqual ( {
665
666
status : 'error' ,
666
667
info : "Invalid interval: 'score'" ,
667
668
} ) ;
668
669
} ) ;
669
670
670
671
it ( "should error when string contains 'ago' and 'in'" , ( ) => {
671
- expect ( transform . relativeTimeToDate ( 'in 1 day 2 minutes ago' ) ) . toEqual ( {
672
+ expect ( Utils . relativeTimeToDate ( 'in 1 day 2 minutes ago' ) ) . toEqual ( {
672
673
status : 'error' ,
673
674
info : "Time cannot have both 'in' and 'ago'" ,
674
675
} ) ;
0 commit comments