@@ -7,6 +7,7 @@ var removeEmptyRtdbProperties = require('../../src/utils').removeEmptyRtdbProper
77var removeEmptyFirestoreProperties = require ( '../../src/utils' ) . removeEmptyFirestoreProperties ;
88var updateToRtdbObject = require ( '../../src/utils' ) . updateToRtdbObject ;
99var updateToFirestoreObject = require ( '../../src/utils' ) . updateToFirestoreObject ;
10+ var priorityComparator = require ( '../../src/utils' ) . priorityComparator ;
1011
1112describe ( 'utils' , function ( ) {
1213 describe ( 'removeEmptyRtdbProperties' , function ( ) {
@@ -164,4 +165,43 @@ describe('utils', function () {
164165 } ) ;
165166 } ) ;
166167 } ) ;
168+
169+ describe ( 'priorityComparator' , function ( ) {
170+ // https://firebase.google.com/docs/database/web/lists-of-data#data-order
171+ it ( 'should give no priority to equal items' , function ( ) {
172+ expect ( priorityComparator ( 'a' , 'a' ) ) . to . eql ( 0 ) ;
173+ } ) ;
174+ it ( 'should order null items first' , function ( ) {
175+ expect ( priorityComparator ( null , 0 ) ) . to . eql ( - 1 ) ;
176+ expect ( priorityComparator ( 0 , null ) ) . to . eql ( 1 ) ;
177+ } ) ;
178+ it ( 'should order false before true' , function ( ) {
179+ expect ( priorityComparator ( false , true ) ) . to . eql ( - 1 ) ;
180+ expect ( priorityComparator ( true , false ) ) . to . eql ( 1 ) ;
181+ } ) ;
182+ it ( 'should order booleans before numbers' , function ( ) {
183+ expect ( priorityComparator ( false , 0 ) ) . to . eql ( - 1 ) ;
184+ expect ( priorityComparator ( true , 1 ) ) . to . eql ( - 1 ) ;
185+ expect ( priorityComparator ( 0 , false ) ) . to . eql ( 1 ) ;
186+ expect ( priorityComparator ( 1 , true ) ) . to . eql ( 1 ) ;
187+ } ) ;
188+ it ( 'should order numbers before strings' , function ( ) {
189+ expect ( priorityComparator ( 5 , 'foo' ) ) . to . eql ( - 1 ) ;
190+ expect ( priorityComparator ( 3 , '3' ) ) . to . eql ( - 1 ) ;
191+ expect ( priorityComparator ( 'foo' , 0 ) ) . to . eql ( 1 ) ;
192+ expect ( priorityComparator ( '10' , 10 ) ) . to . eql ( 1 ) ;
193+ } ) ;
194+ it ( 'should order numbers in ascending order' , function ( ) {
195+ expect ( priorityComparator ( 4 , 5 ) ) . to . eql ( - 1 ) ;
196+ expect ( priorityComparator ( 5 , 4 ) ) . to . eql ( 1 ) ;
197+ expect ( priorityComparator ( 1 , 10 ) ) . to . eql ( - 1 ) ;
198+ expect ( priorityComparator ( 10 , 1 ) ) . to . eql ( 1 ) ;
199+ } ) ;
200+ it ( 'should order strings lexicographically' , function ( ) {
201+ expect ( priorityComparator ( 'bar' , 'foo' ) ) . to . eql ( - 1 ) ;
202+ expect ( priorityComparator ( 'foo' , 'bar' ) ) . to . eql ( 1 ) ;
203+ expect ( priorityComparator ( 'ant' , 'art' ) ) . to . eql ( - 1 ) ;
204+ expect ( priorityComparator ( 'art' , 'ant' ) ) . to . eql ( 1 ) ;
205+ } ) ;
206+ } ) ;
167207} ) ;
0 commit comments