@@ -45,7 +45,8 @@ import {
45
45
DATABASE_URL ,
46
46
getFreshRepo ,
47
47
getRWRefs ,
48
- waitFor
48
+ waitFor ,
49
+ writeAndValidate
49
50
} from '../helpers/util' ;
50
51
51
52
use ( chaiAsPromised ) ;
@@ -351,27 +352,6 @@ describe('Database@exp Tests', () => {
351
352
goOnline ( db ) ;
352
353
} ) ;
353
354
354
- // TODO(mtewani): Remove this. This shouldn't work, right? A child level listener doesn't fulfill the full serverCache.
355
- // it.only('resolves get to serverCache when the database is offline and using a child-level listener', async () => {
356
- // const db = getDatabase(defaultApp);
357
- // const { readerRef, writerRef } = getRWRefs(db);
358
- // const toWrite = {
359
- // test: 'ghi'
360
- // };
361
- // const ec = EventAccumulatorFactory.waitsForExactCount(1);
362
- // await(
363
- // set(writerRef, toWrite)
364
- // );
365
- // onValue(child(readerRef, 'test'), (snapshot) => {
366
- // ec.addEvent(snapshot);
367
- // });
368
- // await ec.promise; // TODO: check value of this.
369
- // goOffline(db);
370
- // const result = await get(readerRef);
371
- // expect(result.val()).to.deep.eq(toWrite);
372
- // goOnline(db);
373
- // });
374
-
375
355
it ( 'only fires listener once when calling get with limitTo' , async ( ) => {
376
356
const db = getDatabase ( defaultApp ) ;
377
357
const { readerRef, writerRef } = getRWRefs ( db ) ;
@@ -380,12 +360,7 @@ describe('Database@exp Tests', () => {
380
360
child1 : 'test1' ,
381
361
child2 : 'test2'
382
362
} ;
383
- await set ( writerRef , toWrite ) ;
384
- onValue ( readerRef , snapshot => {
385
- ec . addEvent ( snapshot ) ;
386
- } ) ;
387
- const [ snap ] = await ec . promise ;
388
- expect ( snap . val ( ) ) . to . deep . eq ( toWrite ) ;
363
+ writeAndValidate ( writerRef , readerRef , toWrite , ec ) ;
389
364
const q = query ( readerRef , limitToFirst ( 1 ) ) ;
390
365
const snapshot = await get ( q ) ;
391
366
const expected = {
@@ -402,14 +377,8 @@ describe('Database@exp Tests', () => {
402
377
child2 : 'test2' ,
403
378
child3 : 'test3'
404
379
} ;
405
- await set ( writerRef , toWrite ) ;
406
380
const ec = EventAccumulatorFactory . waitsForExactCount ( 1 ) ;
407
- onValue ( readerRef , snapshot => {
408
- ec . addEvent ( snapshot ) ;
409
- } ) ;
410
- const events = await ec . promise ;
411
- expect ( events . length ) . to . eq ( 1 ) ;
412
- expect ( events [ 0 ] . val ( ) ) . to . deep . eq ( toWrite ) ;
381
+ writeAndValidate ( writerRef , readerRef , toWrite , ec ) ;
413
382
const otherChildrenQuery = query (
414
383
readerRef ,
415
384
orderByKey ( ) ,
@@ -437,14 +406,13 @@ describe('Database@exp Tests', () => {
437
406
ec . addEvent ( snapshot ) ;
438
407
} ) ;
439
408
const events = await ec . promise ;
440
- expect ( events . length ) . to . eq ( 1 ) ; // TODO(mtewani): can get rid of this.
441
409
const expected = { child1 : 'test1' } ;
442
410
expect ( events [ 0 ] . val ( ) ) . to . deep . eq ( expected ) ;
443
411
const snapshot = await get ( readerRef ) ;
444
412
expect ( snapshot . val ( ) ) . to . deep . eq ( toWrite ) ;
445
413
} ) ;
446
414
447
- it ( 'should test start with get with listener only fires once' , async ( ) => {
415
+ it ( 'should test startAt get with listener only fires once' , async ( ) => {
448
416
const db = getDatabase ( defaultApp ) ;
449
417
const { readerRef, writerRef } = getRWRefs ( db ) ;
450
418
const expected = {
@@ -453,12 +421,7 @@ describe('Database@exp Tests', () => {
453
421
child3 : 'test3'
454
422
} ;
455
423
const ec = EventAccumulatorFactory . waitsForExactCount ( 1 ) ;
456
- await set ( writerRef , expected ) ; // TODO(mtewani): Can extract this out to something like writeAndValidate()
457
- onValue ( readerRef , snapshot => {
458
- ec . addEvent ( snapshot ) ;
459
- } ) ;
460
- const [ snap ] = await ec . promise ;
461
- expect ( snap . val ( ) ) . to . deep . eq ( expected ) ;
424
+ writeAndValidate ( writerRef , readerRef , expected , ec ) ;
462
425
const q = query ( readerRef , orderByKey ( ) , startAt ( 'child2' ) ) ;
463
426
const snapshot = await get ( q ) ;
464
427
const expectedQRes = {
0 commit comments