44const transform = require ( '../lib/Adapters/Storage/Mongo/MongoTransform' ) ;
55const dd = require ( 'deep-diff' ) ;
66const mongodb = require ( 'mongodb' ) ;
7+ const Utils = require ( '../lib/Utils' ) ;
78
89describe ( 'parseObjectToMongoObjectForCreate' , ( ) => {
910 it ( 'a basic number' , done => {
@@ -592,7 +593,7 @@ describe('relativeTimeToDate', () => {
592593 describe ( 'In the future' , ( ) => {
593594 it ( 'should parse valid natural time' , ( ) => {
594595 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 ) ;
596597 expect ( result . toISOString ( ) ) . toBe ( '2018-10-22T23:52:46.617Z' ) ;
597598 expect ( status ) . toBe ( 'success' ) ;
598599 expect ( info ) . toBe ( 'future' ) ;
@@ -602,7 +603,7 @@ describe('relativeTimeToDate', () => {
602603 describe ( 'In the past' , ( ) => {
603604 it ( 'should parse valid natural time' , ( ) => {
604605 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 ) ;
606607 expect ( result . toISOString ( ) ) . toBe ( '2017-09-24T01:27:04.617Z' ) ;
607608 expect ( status ) . toBe ( 'success' ) ;
608609 expect ( info ) . toBe ( 'past' ) ;
@@ -612,7 +613,7 @@ describe('relativeTimeToDate', () => {
612613 describe ( 'From now' , ( ) => {
613614 it ( 'should equal current time' , ( ) => {
614615 const text = 'now' ;
615- const { result, status, info } = transform . relativeTimeToDate ( text , now ) ;
616+ const { result, status, info } = Utils . relativeTimeToDate ( text , now ) ;
616617 expect ( result . toISOString ( ) ) . toBe ( '2017-09-26T13:28:16.617Z' ) ;
617618 expect ( status ) . toBe ( 'success' ) ;
618619 expect ( info ) . toBe ( 'present' ) ;
@@ -621,54 +622,54 @@ describe('relativeTimeToDate', () => {
621622
622623 describe ( 'Error cases' , ( ) => {
623624 it ( 'should error if string is completely gibberish' , ( ) => {
624- expect ( transform . relativeTimeToDate ( 'gibberishasdnklasdnjklasndkl123j123' ) ) . toEqual ( {
625+ expect ( Utils . relativeTimeToDate ( 'gibberishasdnklasdnjklasndkl123j123' ) ) . toEqual ( {
625626 status : 'error' ,
626627 info : "Time should either start with 'in' or end with 'ago'" ,
627628 } ) ;
628629 } ) ;
629630
630631 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 ( {
632633 status : 'error' ,
633634 info : "Time should either start with 'in' or end with 'ago'" ,
634635 } ) ;
635636 } ) ;
636637
637638 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 ( {
639640 status : 'error' ,
640641 info : 'Invalid time string. Dangling unit or number.' ,
641642 } ) ;
642643
643- expect ( transform . relativeTimeToDate ( '12 hours minute ago' ) ) . toEqual ( {
644+ expect ( Utils . relativeTimeToDate ( '12 hours minute ago' ) ) . toEqual ( {
644645 status : 'error' ,
645646 info : 'Invalid time string. Dangling unit or number.' ,
646647 } ) ;
647648 } ) ;
648649
649650 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 ( {
651652 status : 'error' ,
652653 info : "'12.3' is not an integer." ,
653654 } ) ;
654655 } ) ;
655656
656657 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 ( {
658659 status : 'error' ,
659660 info : "'123a' is not an integer." ,
660661 } ) ;
661662 } ) ;
662663
663664 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 ( {
665666 status : 'error' ,
666667 info : "Invalid interval: 'score'" ,
667668 } ) ;
668669 } ) ;
669670
670671 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 ( {
672673 status : 'error' ,
673674 info : "Time cannot have both 'in' and 'ago'" ,
674675 } ) ;
0 commit comments