1+ const config = require ( './../../src/include/config' ) ;
2+ const expect = require ( 'chai' ) . expect ;
3+
4+ describe ( 'The config class' , ( ) => {
5+ it ( 'stores data' , ( ) => {
6+ let Config = new config ( ) ,
7+ data = 'value_' + Math . random ( ) ,
8+ key = 'key_' + Math . random ( ) ;
9+
10+ Config . set ( key , data ) ;
11+
12+ expect ( Config . get ( key ) ) . to . equal ( data ) ;
13+ } ) ;
14+
15+ it ( 'doesnt store data if the value is null or undefined until you force it' , ( ) => {
16+ let Config = new config ( ) ,
17+ data = 'value_' + Math . random ( ) ,
18+ key = 'key_' + Math . random ( ) ;
19+
20+ Config . set ( key , data ) ;
21+
22+ Config . set ( key , null ) ;
23+ expect ( Config . get ( key ) ) . to . equal ( data ) ;
24+
25+ Config . set ( key , undefined ) ;
26+ expect ( Config . get ( key ) ) . to . equal ( data ) ;
27+
28+ Config . set ( key , null , true ) ;
29+ expect ( Config . get ( key ) ) . to . equal ( null ) ;
30+
31+ Config . set ( key , undefined , true ) ;
32+ expect ( Config . get ( key ) ) . to . equal ( undefined ) ;
33+ } ) ;
34+
35+ it ( 'returns moment instances for dates' , ( ) => {
36+ let Config = new config ( ) ,
37+ dates = [ 'from' , 'to' ] ;
38+
39+ dates . forEach ( date => {
40+ Config . set ( date , "2017-08-01" ) ;
41+ expect ( typeof Config . get ( date ) . format ) . to . equal ( "function" ) ;
42+ } ) ;
43+ } ) ;
44+
45+ it ( 'makes durations human readable' , ( ) => {
46+ let Config = new config ,
47+ humanReadable = "1d 4h 30m 10s" ,
48+ seconds = 45010 ;
49+
50+ expect ( Config . toHumanReadable ( seconds ) ) . to . equal ( humanReadable ) ;
51+ } ) ;
52+ } ) ;
0 commit comments