Skip to content

Commit 5d62408

Browse files
dhennekemikehardy
authored andcommitted
test(firestore): use getDoc in all e2e tests that use a document reference
1 parent e90782b commit 5d62408

21 files changed

+179
-195
lines changed

packages/firestore/e2e/CollectionReference/add.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ describe('firestore.collection().add()', function () {
5858
});
5959

6060
it('adds a new document', async function () {
61-
const { getFirestore, collection, addDoc, getDocs, deleteDoc } = firestoreModular;
61+
const { getFirestore, collection, addDoc, getDoc, deleteDoc } = firestoreModular;
6262

6363
const data = { foo: 'bar' };
6464
const docRef = await addDoc(collection(getFirestore(), COLLECTION), data);
6565
should.equal(docRef.constructor.name, 'FirestoreDocumentReference');
66-
const docSnap = await getDocs(docRef);
66+
const docSnap = await getDoc(docRef);
6767
docSnap.data().should.eql(jet.contextify(data));
6868
docSnap.exists.should.eql(true);
6969
await deleteDoc(docRef);

packages/firestore/e2e/DocumentReference/delete.e2e.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ describe('firestore.doc().delete()', function () {
3838

3939
describe('modular', function () {
4040
it('deletes a document', async function () {
41-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
41+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
4242

4343
const ref = doc(getFirestore(), `${COLLECTION}/deleteme`);
4444
await setDoc(ref, { foo: 'bar' });
45-
const snapshot1 = await getDocs(ref);
45+
const snapshot1 = await getDoc(ref);
4646
snapshot1.id.should.equal('deleteme');
4747
snapshot1.exists.should.equal(true);
4848
await deleteDoc(ref);
49-
const snapshot2 = await getDocs(ref);
49+
const snapshot2 = await getDoc(ref);
5050
snapshot2.id.should.equal('deleteme');
5151
snapshot2.exists.should.equal(false);
5252
});

packages/firestore/e2e/DocumentReference/get.e2e.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,35 @@ describe('firestore.doc().get()', function () {
7777

7878
describe('modular', function () {
7979
it('gets data from default source', async function () {
80-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
80+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
8181

8282
const ref = doc(getFirestore(), `${COLLECTION}/get`);
8383
const data = { foo: 'bar', bar: 123 };
8484
await setDoc(ref, data);
85-
const snapshot = await getDocs(ref);
85+
const snapshot = await getDoc(ref);
8686
snapshot.data().should.eql(jet.contextify(data));
8787
await deleteDoc(ref);
8888
});
8989

9090
it('gets data from the server', async function () {
91-
const { getFirestore, doc, setDoc, getDocsFromServer, deleteDoc } = firestoreModular;
91+
const { getFirestore, doc, setDoc, getDocFromServer, deleteDoc } = firestoreModular;
9292

9393
const ref = doc(getFirestore(), `${COLLECTION}/get`);
9494
const data = { foo: 'bar', bar: 123 };
9595
await setDoc(ref, data);
96-
const snapshot = await getDocsFromServer(ref);
96+
const snapshot = await getDocFromServer(ref);
9797
snapshot.data().should.eql(jet.contextify(data));
9898
snapshot.metadata.fromCache.should.equal(false);
9999
await deleteDoc(ref);
100100
});
101101

102102
it('gets data from cache', async function () {
103-
const { getFirestore, doc, setDoc, getDocsFromCache, deleteDoc } = firestoreModular;
103+
const { getFirestore, doc, setDoc, getDocFromCache, deleteDoc } = firestoreModular;
104104

105105
const ref = doc(getFirestore(), `${COLLECTION}/get`);
106106
const data = { foo: 'bar', bar: 123 };
107107
await setDoc(ref, data);
108-
const snapshot = await getDocsFromCache(ref);
108+
const snapshot = await getDocFromCache(ref);
109109
snapshot.data().should.eql(jet.contextify(data));
110110
snapshot.metadata.fromCache.should.equal(true);
111111
await deleteDoc(ref);

packages/firestore/e2e/DocumentReference/set.e2e.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,49 +342,49 @@ describe('firestore.doc().set()', function () {
342342
});
343343

344344
it('sets new data', async function () {
345-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
345+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
346346
const ref = doc(getFirestore(), `${COLLECTION}/set`);
347347
const data1 = { foo: 'bar' };
348348
const data2 = { foo: 'baz', bar: 123 };
349349
await setDoc(ref, data1);
350-
const snapshot1 = await getDocs(ref);
350+
const snapshot1 = await getDoc(ref);
351351
snapshot1.data().should.eql(jet.contextify(data1));
352352
await setDoc(ref, data2);
353-
const snapshot2 = await getDocs(ref);
353+
const snapshot2 = await getDoc(ref);
354354
snapshot2.data().should.eql(jet.contextify(data2));
355355
await deleteDoc(ref);
356356
});
357357

358358
it('merges all fields', async function () {
359-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
359+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
360360
const ref = doc(getFirestore(), `${COLLECTION}/merge`);
361361
const data1 = { foo: 'bar' };
362362
const data2 = { bar: 'baz' };
363363
const merged = { ...data1, ...data2 };
364364
await setDoc(ref, data1);
365-
const snapshot1 = await getDocs(ref);
365+
const snapshot1 = await getDoc(ref);
366366
snapshot1.data().should.eql(jet.contextify(data1));
367367
await setDoc(ref, data2, {
368368
merge: true,
369369
});
370-
const snapshot2 = await getDocs(ref);
370+
const snapshot2 = await getDoc(ref);
371371
snapshot2.data().should.eql(jet.contextify(merged));
372372
await deleteDoc(ref);
373373
});
374374

375375
it('merges specific fields', async function () {
376-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
376+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
377377
const ref = doc(getFirestore(), `${COLLECTION}/merge`);
378378
const data1 = { foo: '123', bar: 123, baz: '456' };
379379
const data2 = { foo: '234', bar: 234, baz: '678' };
380380
const merged = { foo: data1.foo, bar: data2.bar, baz: data2.baz };
381381
await setDoc(ref, data1);
382-
const snapshot1 = await getDocs(ref);
382+
const snapshot1 = await getDoc(ref);
383383
snapshot1.data().should.eql(jet.contextify(data1));
384384
await setDoc(ref, data2, {
385385
mergeFields: ['bar', new firebase.firestore.FieldPath('baz')],
386386
});
387-
const snapshot2 = await getDocs(ref);
387+
const snapshot2 = await getDoc(ref);
388388
snapshot2.data().should.eql(jet.contextify(merged));
389389
await deleteDoc(ref);
390390
});
@@ -428,7 +428,7 @@ describe('firestore.doc().set()', function () {
428428
});
429429

430430
it('filters out undefined properties when setting enabled', async function () {
431-
const { getFirestore, initializeFirestore, doc, setDoc, getDocs } = firestoreModular;
431+
const { getFirestore, initializeFirestore, doc, setDoc, getDoc } = firestoreModular;
432432
const db = getFirestore();
433433
initializeFirestore(db.app, { ignoreUndefinedProperties: true });
434434

@@ -438,7 +438,7 @@ describe('firestore.doc().set()', function () {
438438
field2: undefined,
439439
});
440440

441-
const snap = await getDocs(docRef);
441+
const snap = await getDoc(docRef);
442442
const snapData = snap.data();
443443
if (!snapData) {
444444
return Promise.reject(new Error('Snapshot not saved'));
@@ -449,7 +449,7 @@ describe('firestore.doc().set()', function () {
449449
});
450450

451451
it('filters out nested undefined properties when setting enabled', async function () {
452-
const { getFirestore, initializeFirestore, doc, setDoc, getDocs } = firestoreModular;
452+
const { getFirestore, initializeFirestore, doc, setDoc, getDoc } = firestoreModular;
453453
const db = getFirestore();
454454
initializeFirestore(db.app, { ignoreUndefinedProperties: true });
455455

@@ -467,7 +467,7 @@ describe('firestore.doc().set()', function () {
467467
],
468468
});
469469

470-
const snap = await getDocs(docRef);
470+
const snap = await getDoc(docRef);
471471
const snapData = snap.data();
472472
if (!snapData) {
473473
return Promise.reject(new Error('Snapshot not saved'));

packages/firestore/e2e/DocumentReference/update.e2e.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,27 @@ describe('firestore.doc().update()', function () {
127127
});
128128

129129
it('updates data with an object value', async function () {
130-
const { getFirestore, doc, setDoc, getDocs, updateDoc, deleteDoc } = firestoreModular;
130+
const { getFirestore, doc, setDoc, getDoc, updateDoc, deleteDoc } = firestoreModular;
131131
const ref = doc(getFirestore(), `${COLLECTION}/update-obj`);
132132
const value = Date.now();
133133
const data1 = { foo: value };
134134
const data2 = { foo: 'bar' };
135135
await setDoc(ref, data1);
136-
const snapshot1 = await getDocs(ref);
136+
const snapshot1 = await getDoc(ref);
137137
snapshot1.data().should.eql(jet.contextify(data1));
138138
await updateDoc(ref, data2);
139-
const snapshot2 = await getDocs(ref);
139+
const snapshot2 = await getDoc(ref);
140140
snapshot2.data().should.eql(jet.contextify(data2));
141141
await deleteDoc(ref);
142142
});
143143

144144
it('updates data with an key/value pairs', async function () {
145-
const { getFirestore, doc, setDoc, getDocs, updateDoc, deleteDoc } = firestoreModular;
145+
const { getFirestore, doc, setDoc, getDoc, updateDoc, deleteDoc } = firestoreModular;
146146
const ref = doc(getFirestore(), `${COLLECTION}/update-obj`);
147147
const value = Date.now();
148148
const data1 = { foo: value, bar: value };
149149
await setDoc(ref, data1);
150-
const snapshot1 = await getDocs(ref);
150+
const snapshot1 = await getDoc(ref);
151151
snapshot1.data().should.eql(jet.contextify(data1));
152152

153153
await updateDoc(ref, 'foo', 'bar', 'bar', 'baz', 'foo1', 'bar1');
@@ -156,7 +156,7 @@ describe('firestore.doc().update()', function () {
156156
bar: 'baz',
157157
foo1: 'bar1',
158158
};
159-
const snapshot2 = await getDocs(ref);
159+
const snapshot2 = await getDoc(ref);
160160
snapshot2.data().should.eql(jet.contextify(expected));
161161
await deleteDoc(ref);
162162
});

packages/firestore/e2e/DocumentSnapshot/data.e2e.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,28 @@ describe('firestore().doc() -> snapshot.data()', function () {
145145

146146
describe('modular', function () {
147147
it('returns undefined if documet does not exist', async function () {
148-
const { getFirestore, doc, getDocs } = firestoreModular;
148+
const { getFirestore, doc, getDoc } = firestoreModular;
149149
const ref = doc(getFirestore(), `${COLLECTION}/idonotexist`);
150-
const snapshot = await getDocs(ref);
150+
const snapshot = await getDoc(ref);
151151
should.equal(snapshot.data(), undefined);
152152
});
153153

154154
it('returns an object if exists', async function () {
155-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
155+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
156156
const ref = doc(getFirestore(), `${COLLECTION}/getData`);
157157
const data = { foo: 'bar' };
158158
await setDoc(ref, data);
159-
const snapshot = await getDocs(ref);
159+
const snapshot = await getDoc(ref);
160160
snapshot.data().should.eql(jet.contextify(data));
161161
await deleteDoc(ref);
162162
});
163163

164164
it('returns an object when document is empty', async function () {
165-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
165+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
166166
const ref = doc(getFirestore(), `${COLLECTION}/getData`);
167167
const data = {};
168168
await setDoc(ref, data);
169-
const snapshot = await getDocs(ref);
169+
const snapshot = await getDoc(ref);
170170
snapshot.data().should.eql(jet.contextify(data));
171171
await deleteDoc(ref);
172172
});
@@ -176,7 +176,7 @@ describe('firestore().doc() -> snapshot.data()', function () {
176176
// });
177177

178178
it('handles all data types', async function () {
179-
const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular;
179+
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
180180
const types = {
181181
string: '123456',
182182
stringEmpty: '',
@@ -203,7 +203,7 @@ describe('firestore().doc() -> snapshot.data()', function () {
203203

204204
const ref = doc(getFirestore(), `${COLLECTION}/types`);
205205
await setDoc(ref, types);
206-
const snapshot = await getDocs(ref);
206+
const snapshot = await getDoc(ref);
207207
const data = snapshot.data();
208208

209209
// String

packages/firestore/e2e/DocumentSnapshot/get.e2e.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ describe('firestore().doc() -> snapshot.get()', function () {
168168

169169
describe('modular', function () {
170170
it('throws if invalid fieldPath argument', async function () {
171-
const { getFirestore, doc, getDocs } = firestoreModular;
171+
const { getFirestore, doc, getDoc } = firestoreModular;
172172
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
173-
const snapshot = await getDocs(ref);
173+
const snapshot = await getDoc(ref);
174174

175175
try {
176176
snapshot.get(123);
@@ -182,9 +182,9 @@ describe('firestore().doc() -> snapshot.get()', function () {
182182
});
183183

184184
it('throws if fieldPath is an empty string', async function () {
185-
const { getFirestore, doc, getDocs } = firestoreModular;
185+
const { getFirestore, doc, getDoc } = firestoreModular;
186186
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
187-
const snapshot = await getDocs(ref);
187+
const snapshot = await getDoc(ref);
188188

189189
try {
190190
snapshot.get('');
@@ -196,9 +196,9 @@ describe('firestore().doc() -> snapshot.get()', function () {
196196
});
197197

198198
it('throws if fieldPath starts with a period (.)', async function () {
199-
const { getFirestore, doc, getDocs } = firestoreModular;
199+
const { getFirestore, doc, getDoc } = firestoreModular;
200200
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
201-
const snapshot = await getDocs(ref);
201+
const snapshot = await getDoc(ref);
202202

203203
try {
204204
snapshot.get('.foo');
@@ -210,9 +210,9 @@ describe('firestore().doc() -> snapshot.get()', function () {
210210
});
211211

212212
it('throws if fieldPath ends with a period (.)', async function () {
213-
const { getFirestore, doc, getDocs } = firestoreModular;
213+
const { getFirestore, doc, getDoc } = firestoreModular;
214214
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
215-
const snapshot = await getDocs(ref);
215+
const snapshot = await getDoc(ref);
216216

217217
try {
218218
snapshot.get('foo.');
@@ -224,9 +224,9 @@ describe('firestore().doc() -> snapshot.get()', function () {
224224
});
225225

226226
it('throws if fieldPath contains ..', async function () {
227-
const { getFirestore, doc, getDocs } = firestoreModular;
227+
const { getFirestore, doc, getDoc } = firestoreModular;
228228
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
229-
const snapshot = await getDocs(ref);
229+
const snapshot = await getDoc(ref);
230230

231231
try {
232232
snapshot.get('foo..bar');
@@ -238,9 +238,9 @@ describe('firestore().doc() -> snapshot.get()', function () {
238238
});
239239

240240
it('returns undefined if the data does not exist', async function () {
241-
const { getFirestore, doc, getDocs, FieldPath } = firestoreModular;
241+
const { getFirestore, doc, getDoc, FieldPath } = firestoreModular;
242242
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
243-
const snapshot = await getDocs(ref);
243+
const snapshot = await getDoc(ref);
244244

245245
const val1 = snapshot.get('foo');
246246
const val2 = snapshot.get('foo.bar');
@@ -256,7 +256,7 @@ describe('firestore().doc() -> snapshot.get()', function () {
256256
});
257257

258258
it('returns the correct data with string fieldPath', async function () {
259-
const { getFirestore, doc, getDocs, setDoc, deleteDoc } = firestoreModular;
259+
const { getFirestore, doc, getDoc, setDoc, deleteDoc } = firestoreModular;
260260
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
261261
const types = {
262262
string: '12345',
@@ -270,7 +270,7 @@ describe('firestore().doc() -> snapshot.get()', function () {
270270
};
271271

272272
await setDoc(ref, types);
273-
const snapshot = await getDocs(ref);
273+
const snapshot = await getDoc(ref);
274274

275275
const string1 = snapshot.get('string');
276276
const string2 = snapshot.get('map.string');
@@ -287,7 +287,7 @@ describe('firestore().doc() -> snapshot.get()', function () {
287287
});
288288

289289
it('returns the correct data with FieldPath', async function () {
290-
const { getFirestore, doc, getDocs, setDoc, deleteDoc, FieldPath } = firestoreModular;
290+
const { getFirestore, doc, getDoc, setDoc, deleteDoc, FieldPath } = firestoreModular;
291291
const ref = doc(getFirestore(), `${COLLECTION}/foo`);
292292
const types = {
293293
string: '12345',
@@ -301,7 +301,7 @@ describe('firestore().doc() -> snapshot.get()', function () {
301301
};
302302

303303
await setDoc(ref, types);
304-
const snapshot = await getDocs(ref);
304+
const snapshot = await getDoc(ref);
305305

306306
const string1 = snapshot.get(new FieldPath('string'));
307307
const string2 = snapshot.get(new FieldPath('map', 'string'));

0 commit comments

Comments
 (0)