@@ -20,48 +20,105 @@ const { PATH, wipe } = require('./helpers');
2020const TEST_PATH = `${ PATH } /statics` ;
2121
2222describe ( 'database.X' , function ( ) {
23- after ( function ( ) {
24- return wipe ( TEST_PATH ) ;
25- } ) ;
23+ describe ( 'v8 compatibility' , function ( ) {
24+ after ( function ( ) {
25+ return wipe ( TEST_PATH ) ;
26+ } ) ;
27+
28+ describe ( 'ServerValue.TIMESTAMP' , function ( ) {
29+ it ( 'returns a valid object' , function ( ) {
30+ const { TIMESTAMP } = firebase . database . ServerValue ;
31+ should . equal ( Object . keys ( TIMESTAMP ) . length , 1 ) ;
32+ TIMESTAMP . should . have . property ( '.sv' ) ;
33+ TIMESTAMP [ '.sv' ] . should . eql ( 'timestamp' ) ;
34+ } ) ;
35+ } ) ;
36+
37+ describe ( 'ServerValue.increment' , function ( ) {
38+ it ( 'returns a valid object' , function ( ) {
39+ const incrementObject = firebase . database . ServerValue . increment ( 1 ) ;
40+ should . equal ( Object . keys ( incrementObject ) . length , 1 ) ;
41+ incrementObject . should . have . property ( '.sv' ) ;
42+ incrementObject [ '.sv' ] . should . have . property ( 'increment' ) ;
43+ } ) ;
44+
45+ it ( 'increments on the server' , async function ( ) {
46+ const ref = firebase . database ( ) . ref ( `${ TEST_PATH } /increment` ) ;
47+
48+ await ref . set ( { increment : 0 } ) ;
49+
50+ const res1 = await ref . once ( 'value' ) ;
51+ res1 . val ( ) . increment . should . equal ( 0 ) ;
52+
53+ await ref . set ( { increment : firebase . database . ServerValue . increment ( 1 ) } ) ;
54+
55+ const res2 = await ref . once ( 'value' ) ;
56+ res2 . val ( ) . increment . should . equal ( 1 ) ;
57+ } ) ;
2658
27- describe ( 'ServerValue.TIMESTAMP' , function ( ) {
28- it ( 'returns a valid object' , function ( ) {
29- const { TIMESTAMP } = firebase . database . ServerValue ;
30- should . equal ( Object . keys ( TIMESTAMP ) . length , 1 ) ;
31- TIMESTAMP . should . have . property ( '.sv' ) ;
32- TIMESTAMP [ '.sv' ] . should . eql ( 'timestamp' ) ;
59+ it ( 'increments on the server when no value is present' , async function ( ) {
60+ const ref = firebase . database ( ) . ref ( `${ TEST_PATH } /increment-empty` ) ;
61+
62+ await ref . set ( { increment : firebase . database . ServerValue . increment ( 2 ) } ) ;
63+
64+ const res = await ref . once ( 'value' ) ;
65+ res . val ( ) . increment . should . equal ( 2 ) ;
66+ } ) ;
3367 } ) ;
3468 } ) ;
3569
36- describe ( 'ServerValue.increment' , function ( ) {
37- it ( 'returns a valid object' , function ( ) {
38- const incrementObject = firebase . database . ServerValue . increment ( 1 ) ;
39- should . equal ( Object . keys ( incrementObject ) . length , 1 ) ;
40- incrementObject . should . have . property ( '.sv' ) ;
41- incrementObject [ '.sv' ] . should . have . property ( 'increment' ) ;
70+ describe ( 'modular' , function ( ) {
71+ after ( function ( ) {
72+ return wipe ( TEST_PATH ) ;
4273 } ) ;
4374
44- it ( 'increments on the server' , async function ( ) {
45- const ref = firebase . database ( ) . ref ( `${ TEST_PATH } /increment` ) ;
75+ describe ( 'serverTimestamp' , function ( ) {
76+ it ( 'returns a valid object' , function ( ) {
77+ const { serverTimestamp } = databaseModular ;
78+ const timestamp = serverTimestamp ( ) ;
4679
47- await ref . set ( { increment : 0 } ) ;
80+ should . equal ( Object . keys ( timestamp ) . length , 1 ) ;
81+ timestamp . should . have . property ( '.sv' ) ;
82+ timestamp [ '.sv' ] . should . eql ( 'timestamp' ) ;
83+ } ) ;
84+ } ) ;
4885
49- const res1 = await ref . once ( 'value' ) ;
50- res1 . val ( ) . increment . should . equal ( 0 ) ;
86+ describe ( 'increment' , function ( ) {
87+ it ( 'returns a valid object' , function ( ) {
88+ const { increment } = databaseModular ;
5189
52- await ref . set ( { increment : firebase . database . ServerValue . increment ( 1 ) } ) ;
90+ const incrementObject = increment ( 1 ) ;
91+ should . equal ( Object . keys ( incrementObject ) . length , 1 ) ;
92+ incrementObject . should . have . property ( '.sv' ) ;
93+ incrementObject [ '.sv' ] . should . have . property ( 'increment' ) ;
94+ } ) ;
5395
54- const res2 = await ref . once ( 'value' ) ;
55- res2 . val ( ) . increment . should . equal ( 1 ) ;
56- } ) ;
96+ it ( 'increments on the server' , async function ( ) {
97+ const { getDatabase, ref, set, get, increment } = databaseModular ;
98+
99+ const dbRef = ref ( getDatabase ( ) , `${ TEST_PATH } /increment` ) ;
100+
101+ await set ( dbRef , { increment : 0 } ) ;
102+
103+ const res1 = await get ( dbRef ) ;
104+ res1 . val ( ) . increment . should . equal ( 0 ) ;
105+
106+ await set ( dbRef , { increment : increment ( 1 ) } ) ;
107+
108+ const res2 = await get ( dbRef ) ;
109+ res2 . val ( ) . increment . should . equal ( 1 ) ;
110+ } ) ;
111+
112+ it ( 'increments on the server when no value is present' , async function ( ) {
113+ const { getDatabase, ref, set, get, increment } = databaseModular ;
57114
58- it ( 'increments on the server when no value is present' , async function ( ) {
59- const ref = firebase . database ( ) . ref ( `${ TEST_PATH } /increment-empty` ) ;
115+ const dbRef = ref ( getDatabase ( ) , `${ TEST_PATH } /increment-empty` ) ;
60116
61- await ref . set ( { increment : firebase . database . ServerValue . increment ( 2 ) } ) ;
117+ await set ( dbRef , { increment : increment ( 2 ) } ) ;
62118
63- const res = await ref . once ( 'value' ) ;
64- res . val ( ) . increment . should . equal ( 2 ) ;
119+ const res = await get ( dbRef ) ;
120+ res . val ( ) . increment . should . equal ( 2 ) ;
121+ } ) ;
65122 } ) ;
66123 } ) ;
67124} ) ;
0 commit comments