@@ -20,14 +20,19 @@ import * as firestore from 'firestore';
20
20
import { Deferred } from '../../../src/util/promise' ;
21
21
import { asyncIt } from '../../util/helpers' ;
22
22
import firebase from '../util/firebase_export' ;
23
- import { apiDescribe , withTestCollection , withTestDb } from '../util/helpers' ;
23
+ import {
24
+ apiDescribe ,
25
+ withTestCollection ,
26
+ withTestDb ,
27
+ withTestDoc
28
+ } from '../util/helpers' ;
24
29
import { Firestore } from '../../../src/api/database' ;
25
30
26
31
apiDescribe ( 'Database' , persistence => {
27
32
asyncIt ( 'can set a document' , ( ) => {
28
- return withTestDb ( persistence , db => {
29
- return db . doc ( 'rooms/Eros' ) . set ( {
30
- desc : 'Stuff related to Eros project...' ,
33
+ return withTestDoc ( persistence , docRef => {
34
+ return docRef . set ( {
35
+ desc : 'Stuff related to Firestore project...' ,
31
36
owner : {
32
37
name : 'Jonny' ,
33
38
title : 'scallywag'
@@ -46,8 +51,7 @@ apiDescribe('Database', persistence => {
46
51
} ) ;
47
52
48
53
asyncIt ( 'can delete a document' , ( ) => {
49
- return withTestDb ( persistence , db => {
50
- const docRef = db . doc ( 'rooms/Eros' ) ;
54
+ return withTestDoc ( persistence , docRef => {
51
55
return docRef
52
56
. set ( { foo : 'bar' } )
53
57
. then ( ( ) => {
@@ -67,8 +71,7 @@ apiDescribe('Database', persistence => {
67
71
} ) ;
68
72
69
73
asyncIt ( 'can update existing document' , ( ) => {
70
- return withTestDb ( persistence , db => {
71
- const doc = db . doc ( 'rooms/Eros' ) ;
74
+ return withTestDoc ( persistence , doc => {
72
75
const initialData = {
73
76
desc : 'Description' ,
74
77
owner :
{ name :
'Jonny' , email :
'[email protected] ' }
@@ -93,8 +96,7 @@ apiDescribe('Database', persistence => {
93
96
} ) ;
94
97
95
98
asyncIt ( 'can merge data with an existing document using set' , ( ) => {
96
- return withTestDb ( persistence , db => {
97
- const doc = db . doc ( 'rooms/Eros' ) ;
99
+ return withTestDoc ( persistence , doc => {
98
100
const initialData = {
99
101
desc : 'description' ,
100
102
'owner.data' :
{ name :
'Jonny' , email :
'[email protected] ' }
@@ -120,8 +122,7 @@ apiDescribe('Database', persistence => {
120
122
} ) ;
121
123
122
124
asyncIt ( 'can merge server timestamps' , ( ) => {
123
- return withTestDb ( persistence , db => {
124
- const doc = db . doc ( 'rooms/Eros' ) ;
125
+ return withTestDoc ( persistence , doc => {
125
126
const initialData = {
126
127
updated : false
127
128
} ;
@@ -141,8 +142,7 @@ apiDescribe('Database', persistence => {
141
142
} ) ;
142
143
143
144
asyncIt ( 'can replace an array by merging using set' , ( ) => {
144
- return withTestDb ( persistence , db => {
145
- const doc = db . doc ( 'rooms/Eros' ) ;
145
+ return withTestDoc ( persistence , doc => {
146
146
const initialData = {
147
147
untouched : true ,
148
148
data : 'old' ,
@@ -172,8 +172,7 @@ apiDescribe('Database', persistence => {
172
172
} ) ;
173
173
174
174
asyncIt ( 'cannot update nonexistent document' , ( ) => {
175
- return withTestDb ( persistence , db => {
176
- const doc = db . collection ( 'rooms' ) . doc ( ) ;
175
+ return withTestDoc ( persistence , doc => {
177
176
return doc
178
177
. update ( { owner : 'abc' } )
179
178
. then (
@@ -192,8 +191,7 @@ apiDescribe('Database', persistence => {
192
191
} ) ;
193
192
194
193
asyncIt ( 'can delete a field with an update' , ( ) => {
195
- return withTestDb ( persistence , db => {
196
- const doc = db . doc ( 'rooms/Eros' ) ;
194
+ return withTestDoc ( persistence , doc => {
197
195
const initialData = {
198
196
desc : 'Description' ,
199
197
owner :
{ name :
'Jonny' , email :
'[email protected] ' }
@@ -219,8 +217,7 @@ apiDescribe('Database', persistence => {
219
217
asyncIt ( 'can update nested fields' , ( ) => {
220
218
const FieldPath = firebase . firestore . FieldPath ;
221
219
222
- return withTestDb ( persistence , db => {
223
- const doc = db . doc ( 'rooms/Eros' ) ;
220
+ return withTestDoc ( persistence , doc => {
224
221
const initialData = {
225
222
desc : 'Description' ,
226
223
owner : { name : 'Jonny' } ,
@@ -248,8 +245,7 @@ apiDescribe('Database', persistence => {
248
245
const invalidDocValues = [ undefined , null , 0 , 'foo' , [ 'a' ] , new Date ( ) ] ;
249
246
for ( const val of invalidDocValues ) {
250
247
asyncIt ( 'set/update should reject: ' + val , ( ) => {
251
- return withTestDb ( persistence , db => {
252
- const doc = db . collection ( 'rooms' ) . doc ( ) ;
248
+ return withTestDoc ( persistence , doc => {
253
249
// tslint:disable-next-line:no-any Intentionally passing bad types.
254
250
expect ( ( ) => doc . set ( val as any ) ) . to . throw ( ) ;
255
251
// tslint:disable-next-line:no-any Intentionally passing bad types.
@@ -337,10 +333,9 @@ apiDescribe('Database', persistence => {
337
333
} ) ;
338
334
339
335
asyncIt ( 'Local document events are fired with hasLocalChanges=true.' , ( ) => {
340
- return withTestDb ( persistence , db => {
336
+ return withTestDoc ( persistence , docRef => {
341
337
let gotLocalDocEvent = false ;
342
338
const remoteDocEventDeferred = new Deferred ( ) ;
343
- const docRef = db . collection ( 'rooms' ) . doc ( ) ;
344
339
const unlisten = docRef . onSnapshot (
345
340
{ includeMetadataChanges : true } ,
346
341
doc => {
@@ -366,10 +361,9 @@ apiDescribe('Database', persistence => {
366
361
asyncIt (
367
362
'Metadata only changes are not fired when no options provided' ,
368
363
( ) => {
369
- return withTestDb ( persistence , db => {
364
+ return withTestDoc ( persistence , docRef => {
370
365
const secondUpdateFound = new Deferred ( ) ;
371
366
let count = 0 ;
372
- const docRef = db . collection ( 'rooms' ) . doc ( ) ;
373
367
const unlisten = docRef . onSnapshot ( doc => {
374
368
if ( doc ) {
375
369
count ++ ;
@@ -563,8 +557,7 @@ apiDescribe('Database', persistence => {
563
557
} ) ;
564
558
565
559
asyncIt ( 'can queue writes while offline' , ( ) => {
566
- return withTestDb ( persistence , db => {
567
- const docRef = db . collection ( 'rooms' ) . doc ( ) ;
560
+ return withTestDoc ( persistence , docRef => {
568
561
// TODO(mikelehen): Find better way to expose this to tests.
569
562
// tslint:disable-next-line:no-any enableNetwork isn't exposed via d.ts
570
563
const firestoreInternal = docRef . firestore . INTERNAL as any ;
@@ -585,8 +578,7 @@ apiDescribe('Database', persistence => {
585
578
} ) ;
586
579
587
580
asyncIt ( 'can get documents while offline' , ( ) => {
588
- return withTestDb ( persistence , db => {
589
- const docRef = db . collection ( 'rooms' ) . doc ( ) ;
581
+ return withTestDoc ( persistence , docRef => {
590
582
// TODO(mikelehen): Find better way to expose this to tests.
591
583
// tslint:disable-next-line:no-any enableNetwork isn't exposed via d.ts
592
584
const firestoreInternal = docRef . firestore . INTERNAL as any ;
0 commit comments