From 5d62408743fd140add577a5e6967257712f0fffe Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Thu, 18 Apr 2024 09:41:57 +0200 Subject: [PATCH] test(firestore): use getDoc in all e2e tests that use a document reference --- .../e2e/CollectionReference/add.e2e.js | 4 +- .../e2e/DocumentReference/delete.e2e.js | 6 +-- .../e2e/DocumentReference/get.e2e.js | 12 ++--- .../e2e/DocumentReference/set.e2e.js | 26 +++++------ .../e2e/DocumentReference/update.e2e.js | 12 ++--- .../e2e/DocumentSnapshot/data.e2e.js | 16 +++---- .../firestore/e2e/DocumentSnapshot/get.e2e.js | 32 +++++++------- .../e2e/DocumentSnapshot/isEqual.e2e.js | 14 +++--- .../e2e/DocumentSnapshot/properties.e2e.js | 22 +++++----- packages/firestore/e2e/FieldValue.e2e.js | 44 +++++++++---------- packages/firestore/e2e/GeoPoint.e2e.js | 4 +- packages/firestore/e2e/Query/endAt.e2e.js | 21 ++++----- packages/firestore/e2e/Query/endBefore.e2e.js | 21 ++++----- packages/firestore/e2e/Query/orderBy.e2e.js | 8 ++-- .../firestore/e2e/Query/startAfter.e2e.js | 25 ++++++----- packages/firestore/e2e/Query/startAt.e2e.js | 21 ++++----- packages/firestore/e2e/QuerySnapshot.e2e.js | 4 +- .../firestore/e2e/SnapshotMetadata.e2e.js | 8 ++-- packages/firestore/e2e/Transaction.e2e.js | 28 ++++++------ .../firestore/e2e/WriteBatch/commit.e2e.js | 40 +++++------------ packages/firestore/e2e/firestore.e2e.js | 6 +-- 21 files changed, 179 insertions(+), 195 deletions(-) diff --git a/packages/firestore/e2e/CollectionReference/add.e2e.js b/packages/firestore/e2e/CollectionReference/add.e2e.js index 19e7857ded..abe16e6649 100644 --- a/packages/firestore/e2e/CollectionReference/add.e2e.js +++ b/packages/firestore/e2e/CollectionReference/add.e2e.js @@ -58,12 +58,12 @@ describe('firestore.collection().add()', function () { }); it('adds a new document', async function () { - const { getFirestore, collection, addDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, collection, addDoc, getDoc, deleteDoc } = firestoreModular; const data = { foo: 'bar' }; const docRef = await addDoc(collection(getFirestore(), COLLECTION), data); should.equal(docRef.constructor.name, 'FirestoreDocumentReference'); - const docSnap = await getDocs(docRef); + const docSnap = await getDoc(docRef); docSnap.data().should.eql(jet.contextify(data)); docSnap.exists.should.eql(true); await deleteDoc(docRef); diff --git a/packages/firestore/e2e/DocumentReference/delete.e2e.js b/packages/firestore/e2e/DocumentReference/delete.e2e.js index 3e91932755..96bd232b7d 100644 --- a/packages/firestore/e2e/DocumentReference/delete.e2e.js +++ b/packages/firestore/e2e/DocumentReference/delete.e2e.js @@ -38,15 +38,15 @@ describe('firestore.doc().delete()', function () { describe('modular', function () { it('deletes a document', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/deleteme`); await setDoc(ref, { foo: 'bar' }); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.id.should.equal('deleteme'); snapshot1.exists.should.equal(true); await deleteDoc(ref); - const snapshot2 = await getDocs(ref); + const snapshot2 = await getDoc(ref); snapshot2.id.should.equal('deleteme'); snapshot2.exists.should.equal(false); }); diff --git a/packages/firestore/e2e/DocumentReference/get.e2e.js b/packages/firestore/e2e/DocumentReference/get.e2e.js index 76eae852c0..7604375118 100644 --- a/packages/firestore/e2e/DocumentReference/get.e2e.js +++ b/packages/firestore/e2e/DocumentReference/get.e2e.js @@ -77,35 +77,35 @@ describe('firestore.doc().get()', function () { describe('modular', function () { it('gets data from default source', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/get`); const data = { foo: 'bar', bar: 123 }; await setDoc(ref, data); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().should.eql(jet.contextify(data)); await deleteDoc(ref); }); it('gets data from the server', async function () { - const { getFirestore, doc, setDoc, getDocsFromServer, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDocFromServer, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/get`); const data = { foo: 'bar', bar: 123 }; await setDoc(ref, data); - const snapshot = await getDocsFromServer(ref); + const snapshot = await getDocFromServer(ref); snapshot.data().should.eql(jet.contextify(data)); snapshot.metadata.fromCache.should.equal(false); await deleteDoc(ref); }); it('gets data from cache', async function () { - const { getFirestore, doc, setDoc, getDocsFromCache, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDocFromCache, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/get`); const data = { foo: 'bar', bar: 123 }; await setDoc(ref, data); - const snapshot = await getDocsFromCache(ref); + const snapshot = await getDocFromCache(ref); snapshot.data().should.eql(jet.contextify(data)); snapshot.metadata.fromCache.should.equal(true); await deleteDoc(ref); diff --git a/packages/firestore/e2e/DocumentReference/set.e2e.js b/packages/firestore/e2e/DocumentReference/set.e2e.js index d2098f5664..aa89ddc919 100644 --- a/packages/firestore/e2e/DocumentReference/set.e2e.js +++ b/packages/firestore/e2e/DocumentReference/set.e2e.js @@ -342,49 +342,49 @@ describe('firestore.doc().set()', function () { }); it('sets new data', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/set`); const data1 = { foo: 'bar' }; const data2 = { foo: 'baz', bar: 123 }; await setDoc(ref, data1); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.data().should.eql(jet.contextify(data1)); await setDoc(ref, data2); - const snapshot2 = await getDocs(ref); + const snapshot2 = await getDoc(ref); snapshot2.data().should.eql(jet.contextify(data2)); await deleteDoc(ref); }); it('merges all fields', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/merge`); const data1 = { foo: 'bar' }; const data2 = { bar: 'baz' }; const merged = { ...data1, ...data2 }; await setDoc(ref, data1); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.data().should.eql(jet.contextify(data1)); await setDoc(ref, data2, { merge: true, }); - const snapshot2 = await getDocs(ref); + const snapshot2 = await getDoc(ref); snapshot2.data().should.eql(jet.contextify(merged)); await deleteDoc(ref); }); it('merges specific fields', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/merge`); const data1 = { foo: '123', bar: 123, baz: '456' }; const data2 = { foo: '234', bar: 234, baz: '678' }; const merged = { foo: data1.foo, bar: data2.bar, baz: data2.baz }; await setDoc(ref, data1); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.data().should.eql(jet.contextify(data1)); await setDoc(ref, data2, { mergeFields: ['bar', new firebase.firestore.FieldPath('baz')], }); - const snapshot2 = await getDocs(ref); + const snapshot2 = await getDoc(ref); snapshot2.data().should.eql(jet.contextify(merged)); await deleteDoc(ref); }); @@ -428,7 +428,7 @@ describe('firestore.doc().set()', function () { }); it('filters out undefined properties when setting enabled', async function () { - const { getFirestore, initializeFirestore, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, initializeFirestore, doc, setDoc, getDoc } = firestoreModular; const db = getFirestore(); initializeFirestore(db.app, { ignoreUndefinedProperties: true }); @@ -438,7 +438,7 @@ describe('firestore.doc().set()', function () { field2: undefined, }); - const snap = await getDocs(docRef); + const snap = await getDoc(docRef); const snapData = snap.data(); if (!snapData) { return Promise.reject(new Error('Snapshot not saved')); @@ -449,7 +449,7 @@ describe('firestore.doc().set()', function () { }); it('filters out nested undefined properties when setting enabled', async function () { - const { getFirestore, initializeFirestore, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, initializeFirestore, doc, setDoc, getDoc } = firestoreModular; const db = getFirestore(); initializeFirestore(db.app, { ignoreUndefinedProperties: true }); @@ -467,7 +467,7 @@ describe('firestore.doc().set()', function () { ], }); - const snap = await getDocs(docRef); + const snap = await getDoc(docRef); const snapData = snap.data(); if (!snapData) { return Promise.reject(new Error('Snapshot not saved')); diff --git a/packages/firestore/e2e/DocumentReference/update.e2e.js b/packages/firestore/e2e/DocumentReference/update.e2e.js index 6e59ad4260..074d72717f 100644 --- a/packages/firestore/e2e/DocumentReference/update.e2e.js +++ b/packages/firestore/e2e/DocumentReference/update.e2e.js @@ -127,27 +127,27 @@ describe('firestore.doc().update()', function () { }); it('updates data with an object value', async function () { - const { getFirestore, doc, setDoc, getDocs, updateDoc, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, updateDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/update-obj`); const value = Date.now(); const data1 = { foo: value }; const data2 = { foo: 'bar' }; await setDoc(ref, data1); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.data().should.eql(jet.contextify(data1)); await updateDoc(ref, data2); - const snapshot2 = await getDocs(ref); + const snapshot2 = await getDoc(ref); snapshot2.data().should.eql(jet.contextify(data2)); await deleteDoc(ref); }); it('updates data with an key/value pairs', async function () { - const { getFirestore, doc, setDoc, getDocs, updateDoc, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, updateDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/update-obj`); const value = Date.now(); const data1 = { foo: value, bar: value }; await setDoc(ref, data1); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.data().should.eql(jet.contextify(data1)); await updateDoc(ref, 'foo', 'bar', 'bar', 'baz', 'foo1', 'bar1'); @@ -156,7 +156,7 @@ describe('firestore.doc().update()', function () { bar: 'baz', foo1: 'bar1', }; - const snapshot2 = await getDocs(ref); + const snapshot2 = await getDoc(ref); snapshot2.data().should.eql(jet.contextify(expected)); await deleteDoc(ref); }); diff --git a/packages/firestore/e2e/DocumentSnapshot/data.e2e.js b/packages/firestore/e2e/DocumentSnapshot/data.e2e.js index 8edc2a6e2c..d3a8f20ba4 100644 --- a/packages/firestore/e2e/DocumentSnapshot/data.e2e.js +++ b/packages/firestore/e2e/DocumentSnapshot/data.e2e.js @@ -145,28 +145,28 @@ describe('firestore().doc() -> snapshot.data()', function () { describe('modular', function () { it('returns undefined if documet does not exist', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/idonotexist`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); should.equal(snapshot.data(), undefined); }); it('returns an object if exists', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/getData`); const data = { foo: 'bar' }; await setDoc(ref, data); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().should.eql(jet.contextify(data)); await deleteDoc(ref); }); it('returns an object when document is empty', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/getData`); const data = {}; await setDoc(ref, data); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().should.eql(jet.contextify(data)); await deleteDoc(ref); }); @@ -176,7 +176,7 @@ describe('firestore().doc() -> snapshot.data()', function () { // }); it('handles all data types', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const types = { string: '123456', stringEmpty: '', @@ -203,7 +203,7 @@ describe('firestore().doc() -> snapshot.data()', function () { const ref = doc(getFirestore(), `${COLLECTION}/types`); await setDoc(ref, types); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const data = snapshot.data(); // String diff --git a/packages/firestore/e2e/DocumentSnapshot/get.e2e.js b/packages/firestore/e2e/DocumentSnapshot/get.e2e.js index a4824c3d2d..22af767db8 100644 --- a/packages/firestore/e2e/DocumentSnapshot/get.e2e.js +++ b/packages/firestore/e2e/DocumentSnapshot/get.e2e.js @@ -168,9 +168,9 @@ describe('firestore().doc() -> snapshot.get()', function () { describe('modular', function () { it('throws if invalid fieldPath argument', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); try { snapshot.get(123); @@ -182,9 +182,9 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('throws if fieldPath is an empty string', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); try { snapshot.get(''); @@ -196,9 +196,9 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('throws if fieldPath starts with a period (.)', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); try { snapshot.get('.foo'); @@ -210,9 +210,9 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('throws if fieldPath ends with a period (.)', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); try { snapshot.get('foo.'); @@ -224,9 +224,9 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('throws if fieldPath contains ..', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); try { snapshot.get('foo..bar'); @@ -238,9 +238,9 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('returns undefined if the data does not exist', async function () { - const { getFirestore, doc, getDocs, FieldPath } = firestoreModular; + const { getFirestore, doc, getDoc, FieldPath } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const val1 = snapshot.get('foo'); const val2 = snapshot.get('foo.bar'); @@ -256,7 +256,7 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('returns the correct data with string fieldPath', async function () { - const { getFirestore, doc, getDocs, setDoc, deleteDoc } = firestoreModular; + const { getFirestore, doc, getDoc, setDoc, deleteDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); const types = { string: '12345', @@ -270,7 +270,7 @@ describe('firestore().doc() -> snapshot.get()', function () { }; await setDoc(ref, types); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const string1 = snapshot.get('string'); const string2 = snapshot.get('map.string'); @@ -287,7 +287,7 @@ describe('firestore().doc() -> snapshot.get()', function () { }); it('returns the correct data with FieldPath', async function () { - const { getFirestore, doc, getDocs, setDoc, deleteDoc, FieldPath } = firestoreModular; + const { getFirestore, doc, getDoc, setDoc, deleteDoc, FieldPath } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/foo`); const types = { string: '12345', @@ -301,7 +301,7 @@ describe('firestore().doc() -> snapshot.get()', function () { }; await setDoc(ref, types); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const string1 = snapshot.get(new FieldPath('string')); const string2 = snapshot.get(new FieldPath('map', 'string')); diff --git a/packages/firestore/e2e/DocumentSnapshot/isEqual.e2e.js b/packages/firestore/e2e/DocumentSnapshot/isEqual.e2e.js index 1493eca7dd..b4859d1dcc 100644 --- a/packages/firestore/e2e/DocumentSnapshot/isEqual.e2e.js +++ b/packages/firestore/e2e/DocumentSnapshot/isEqual.e2e.js @@ -61,11 +61,11 @@ describe('firestore.doc() -> snapshot.isEqual()', function () { describe('modular', function () { it('throws if other is not a DocumentSnapshot', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; try { const docRef = doc(getFirestore(), `${COLLECTION}/baz`); - const docSnapshot = await getDocs(docRef); + const docSnapshot = await getDoc(docRef); docSnapshot.isEqual(123); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -75,15 +75,15 @@ describe('firestore.doc() -> snapshot.isEqual()', function () { }); it('returns false when not equal', async function () { - const { getFirestore, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc } = firestoreModular; const db = getFirestore(); const docRef = doc(db, `${COLLECTION}/isEqual-false-exists`); await setDoc(docRef, { foo: 'bar' }); - const docSnapshot1 = await getDocs(docRef); + const docSnapshot1 = await getDoc(docRef); const docSnapshot2 = await doc(db, `${COLLECTION}/idonotexist`).get(); await setDoc(docRef, { foo: 'baz' }); - const docSnapshot3 = await getDocs(docRef); + const docSnapshot3 = await getDoc(docRef); const eql1 = docSnapshot1.isEqual(docSnapshot2); const eql2 = docSnapshot1.isEqual(docSnapshot3); @@ -93,11 +93,11 @@ describe('firestore.doc() -> snapshot.isEqual()', function () { }); it('returns true when equal', async function () { - const { getFirestore, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc } = firestoreModular; const docRef = doc(getFirestore(), `${COLLECTION}/isEqual-true-exists`); await setDoc(docRef, { foo: 'bar' }); - const docSnapshot = await getDocs(docRef); + const docSnapshot = await getDoc(docRef); const eql1 = docSnapshot.isEqual(docSnapshot); diff --git a/packages/firestore/e2e/DocumentSnapshot/properties.e2e.js b/packages/firestore/e2e/DocumentSnapshot/properties.e2e.js index 5c8ba6a017..8fa3cb986d 100644 --- a/packages/firestore/e2e/DocumentSnapshot/properties.e2e.js +++ b/packages/firestore/e2e/DocumentSnapshot/properties.e2e.js @@ -68,14 +68,14 @@ describe('firestore().doc() -> snapshot', function () { describe('modular', function () { it('.exists -> returns a boolean for exists', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(firebase.app()); const ref1 = doc(db, `${COLLECTION}/exists`); const ref2 = doc(db, `${COLLECTION}/idonotexist`); await setDoc(ref1, { foo: ' bar' }); - const snapshot1 = await getDocs(ref1); - const snapshot2 = await getDocs(ref2); + const snapshot1 = await getDoc(ref1); + const snapshot2 = await getDoc(ref2); snapshot1.exists.should.equal(true); snapshot2.exists.should.equal(false); @@ -83,14 +83,14 @@ describe('firestore().doc() -> snapshot', function () { }); it('.id -> returns the correct id', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(firebase.app()); const ref1 = doc(db, `${COLLECTION}/exists`); const ref2 = doc(db, `${COLLECTION}/idonotexist`); await setDoc(ref1, { foo: ' bar' }); - const snapshot1 = await getDocs(ref1); - const snapshot2 = await getDocs(ref2); + const snapshot1 = await getDoc(ref1); + const snapshot2 = await getDoc(ref2); snapshot1.id.should.equal('exists'); snapshot2.id.should.equal('idonotexist'); @@ -98,20 +98,20 @@ describe('firestore().doc() -> snapshot', function () { }); it('.metadata -> returns a SnapshotMetadata instance', async function () { - const { getFirestore, doc, getDocs } = firestoreModular; + const { getFirestore, doc, getDoc } = firestoreModular; const ref = doc(getFirestore(), `${COLLECTION}/exists`); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.metadata.constructor.name.should.eql('FirestoreSnapshotMetadata'); }); it('.ref -> returns the correct document ref', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(firebase.app()); const ref1 = doc(db, `${COLLECTION}/exists`); const ref2 = doc(db, `${COLLECTION}/idonotexist`); await setDoc(ref1, { foo: ' bar' }); - const snapshot1 = await getDocs(ref1); - const snapshot2 = await getDocs(ref2); + const snapshot1 = await getDoc(ref1); + const snapshot2 = await getDoc(ref2); snapshot1.ref.path.should.equal(`${COLLECTION}/exists`); snapshot2.ref.path.should.equal(`${COLLECTION}/idonotexist`); diff --git a/packages/firestore/e2e/FieldValue.e2e.js b/packages/firestore/e2e/FieldValue.e2e.js index 91074ba176..8d390ffeee 100644 --- a/packages/firestore/e2e/FieldValue.e2e.js +++ b/packages/firestore/e2e/FieldValue.e2e.js @@ -335,25 +335,25 @@ describe('firestore.FieldValue', function () { }); it('increments a number if it exists', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, increment, deleteDoc } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, increment, deleteDoc } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/increment`); await setDoc(ref, { foo: 2 }); await updateDoc(ref, { foo: increment(1) }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().foo.should.equal(3); await deleteDoc(ref); }); it('sets the value if it doesnt exist or being set', async function () { - const { getFirestore, doc, setDoc, getDocs, increment, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, increment, deleteDoc } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/increment`); await setDoc(ref, { foo: increment(1) }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().foo.should.equal(1); await deleteDoc(ref); }); @@ -361,24 +361,24 @@ describe('firestore.FieldValue', function () { describe('serverTime()', function () { it('sets a new server time value', async function () { - const { getFirestore, doc, setDoc, getDocs, serverTimestamp, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, serverTimestamp, deleteDoc } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/servertime`); await setDoc(ref, { foo: serverTimestamp() }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().foo.seconds.should.be.a.Number(); await deleteDoc(ref); }); it('updates a server time value', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, serverTimestamp, deleteDoc } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, serverTimestamp, deleteDoc } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/servertime`); await setDoc(ref, { foo: serverTimestamp() }); - const snapshot1 = await getDocs(ref); + const snapshot1 = await getDoc(ref); snapshot1.data().foo.nanoseconds.should.be.a.Number(); const current = snapshot1.data().foo.nanoseconds; await Utils.sleep(100); @@ -392,14 +392,14 @@ describe('firestore.FieldValue', function () { describe('delete()', function () { it('removes a value', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, deleteDoc, deleteField } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, deleteDoc, deleteField } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/valuedelete`); await setDoc(ref, { foo: 'bar', bar: 'baz' }); await updateDoc(ref, { bar: deleteField() }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); snapshot.data().should.eql(jet.contextify({ foo: 'bar' })); await deleteDoc(ref); }); @@ -433,7 +433,7 @@ describe('firestore.FieldValue', function () { }); it('updates an existing array', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, arrayUnion, deleteDoc } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, arrayUnion, deleteDoc } = firestoreModular; const db = getFirestore(); @@ -444,14 +444,14 @@ describe('firestore.FieldValue', function () { await updateDoc(ref, { foo: arrayUnion(3, 4), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const expected = [1, 2, 3, 4]; snapshot.data().foo.should.eql(jet.contextify(expected)); await deleteDoc(ref); }); it('sets an array if existing value isnt an array with update', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, arrayUnion, deleteDoc } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, arrayUnion, deleteDoc } = firestoreModular; const db = getFirestore(); @@ -462,14 +462,14 @@ describe('firestore.FieldValue', function () { await updateDoc(ref, { foo: arrayUnion(3, 4), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const expected = [3, 4]; snapshot.data().foo.should.eql(jet.contextify(expected)); await deleteDoc(ref); }); it('sets an existing array to the new array with set', async function () { - const { getFirestore, doc, setDoc, getDocs, arrayUnion, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, arrayUnion, deleteDoc } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/arrayunion`); @@ -479,7 +479,7 @@ describe('firestore.FieldValue', function () { await setDoc(ref, { foo: arrayUnion(3, 4), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const expected = [3, 4]; snapshot.data().foo.should.eql(jet.contextify(expected)); await deleteDoc(ref); @@ -514,7 +514,7 @@ describe('firestore.FieldValue', function () { }); it('removes items in an array', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, arrayRemove, deleteDoc } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, arrayRemove, deleteDoc } = firestoreModular; const db = getFirestore(); @@ -525,14 +525,14 @@ describe('firestore.FieldValue', function () { await updateDoc(ref, { foo: arrayRemove(3, 4), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const expected = [1, 2]; snapshot.data().foo.should.eql(jet.contextify(expected)); await deleteDoc(ref); }); it('removes all items in the array if existing value isnt array with update', async function () { - const { getFirestore, doc, setDoc, updateDoc, getDocs, arrayRemove, deleteDoc } = + const { getFirestore, doc, setDoc, updateDoc, getDoc, arrayRemove, deleteDoc } = firestoreModular; const db = getFirestore(); @@ -543,14 +543,14 @@ describe('firestore.FieldValue', function () { await updateDoc(ref, { foo: arrayRemove(3, 4), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const expected = []; snapshot.data().foo.should.eql(jet.contextify(expected)); await deleteDoc(ref); }); it('removes all items in the array if existing value isnt array with set', async function () { - const { getFirestore, doc, setDoc, getDocs, arrayRemove, deleteDoc } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, arrayRemove, deleteDoc } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/arrayunion`); @@ -560,7 +560,7 @@ describe('firestore.FieldValue', function () { await setDoc(ref, { foo: arrayRemove(3, 4), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const expected = []; snapshot.data().foo.should.eql(jet.contextify(expected)); await deleteDoc(ref); diff --git a/packages/firestore/e2e/GeoPoint.e2e.js b/packages/firestore/e2e/GeoPoint.e2e.js index 22de41a0c0..740cf405a7 100644 --- a/packages/firestore/e2e/GeoPoint.e2e.js +++ b/packages/firestore/e2e/GeoPoint.e2e.js @@ -252,14 +252,14 @@ describe('firestore.GeoPoint', function () { }); it('sets & returns correctly', async function () { - const { getFirestore, doc, setDoc, getDocs, deleteDoc, GeoPoint } = firestoreModular; + const { getFirestore, doc, setDoc, getDoc, deleteDoc, GeoPoint } = firestoreModular; const db = getFirestore(); const ref = doc(db, `${COLLECTION}/geopoint`); await setDoc(ref, { geopoint: new GeoPoint(20, 30), }); - const snapshot = await getDocs(ref); + const snapshot = await getDoc(ref); const geo = snapshot.data().geopoint; should.equal(geo.constructor.name, 'FirestoreGeoPoint'); geo.latitude.should.equal(20); diff --git a/packages/firestore/e2e/Query/endAt.e2e.js b/packages/firestore/e2e/Query/endAt.e2e.js index e203f0dbf8..8bb48c83ab 100644 --- a/packages/firestore/e2e/Query/endAt.e2e.js +++ b/packages/firestore/e2e/Query/endAt.e2e.js @@ -168,10 +168,10 @@ describe('firestore().collection().endAt()', function () { }); it('throws if providing snapshot and field values', async function () { - const { getFirestore, collection, doc, endAt, query, getDocs } = firestoreModular; + const { getFirestore, collection, doc, endAt, query, getDoc } = firestoreModular; const db = getFirestore(); try { - const docRef = await getDocs(doc(collection(db, COLLECTION), 'foo')); + const docRef = await getDoc(doc(collection(db, COLLECTION), 'foo')); query(collection(db, COLLECTION), endAt(docRef, 'baz')); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -181,10 +181,10 @@ describe('firestore().collection().endAt()', function () { }); it('throws if provided snapshot does not exist', async function () { - const { getFirestore, collection, doc, endAt, query, getDocs } = firestoreModular; + const { getFirestore, collection, doc, endAt, query, getDoc } = firestoreModular; const db = getFirestore(); try { - const docSnapshot = await getDocs(doc(db, `${COLLECTION}/idonotexist`)); + const docSnapshot = await getDoc(doc(db, `${COLLECTION}/idonotexist`)); query(collection(db, COLLECTION), endAt(docSnapshot)); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -194,13 +194,13 @@ describe('firestore().collection().endAt()', function () { }); it('throws if order used with snapshot but fields do not exist', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, endAt, orderBy, query } = + const { getFirestore, collection, doc, setDoc, getDoc, endAt, orderBy, query } = firestoreModular; const db = getFirestore(); try { const docRef = doc(db, `${COLLECTION}/iexist`); await setDoc(docRef, { foo: { bar: 'baz' } }); - const snap = await getDocs(docRef); + const snap = await getDoc(docRef); query(collection(db, COLLECTION), orderBy('foo.baz'), endAt(snap)); return Promise.reject(new Error('Did not throw an Error.')); @@ -236,7 +236,7 @@ describe('firestore().collection().endAt()', function () { }); it('ends at snapshot field values', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, endAt, orderBy, query } = + const { getFirestore, collection, doc, setDoc, getDocs, getDoc, endAt, orderBy, query } = firestoreModular; // await Utils.sleep(3000); const colRef = collection(getFirestore(), `${COLLECTION}/endsAt/snapshotFields`); @@ -250,7 +250,7 @@ describe('firestore().collection().endAt()', function () { setDoc(doc3, { foo: 3, bar: { value: 1 } }), ]); - const endAtSnapshot = await getDocs(doc2); + const endAtSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, orderBy('bar.value'), endAt(endAtSnapshot))); @@ -260,7 +260,8 @@ describe('firestore().collection().endAt()', function () { }); it('ends at snapshot', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, endAt, query } = firestoreModular; + const { getFirestore, collection, doc, setDoc, getDocs, getDoc, endAt, query } = + firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/endsAt/snapshot`); const doc1 = doc(colRef, 'doc1'); @@ -273,7 +274,7 @@ describe('firestore().collection().endAt()', function () { setDoc(doc3, { foo: 1 }), ]); - const endAtSnapshot = await getDocs(doc2); + const endAtSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, endAt(endAtSnapshot))); diff --git a/packages/firestore/e2e/Query/endBefore.e2e.js b/packages/firestore/e2e/Query/endBefore.e2e.js index 554b244df2..594beb65bf 100644 --- a/packages/firestore/e2e/Query/endBefore.e2e.js +++ b/packages/firestore/e2e/Query/endBefore.e2e.js @@ -166,10 +166,10 @@ describe('firestore().collection().endBefore()', function () { }); it('throws if providing snapshot and field values', async function () { - const { getFirestore, collection, doc, getDocs, query, endBefore } = firestoreModular; + const { getFirestore, collection, doc, getDoc, query, endBefore } = firestoreModular; const db = getFirestore(); try { - const docRef = await getDocs(doc(db, `${COLLECTION}/stuff`)); + const docRef = await getDoc(doc(db, `${COLLECTION}/stuff`)); query(collection(db, COLLECTION), endBefore(docRef, 'baz')); return Promise.reject(new Error('Did not throw an Error.')); @@ -180,10 +180,10 @@ describe('firestore().collection().endBefore()', function () { }); it('throws if provided snapshot does not exist', async function () { - const { getFirestore, collection, doc, getDocs, query, endBefore } = firestoreModular; + const { getFirestore, collection, doc, getDoc, query, endBefore } = firestoreModular; const db = getFirestore(); try { - const docRef = await getDocs(doc(db, `${COLLECTION}/idonotexist`)); + const docRef = await getDoc(doc(db, `${COLLECTION}/idonotexist`)); query(collection(db, COLLECTION), endBefore(docRef)); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -193,13 +193,13 @@ describe('firestore().collection().endBefore()', function () { }); it('throws if order used with snapshot but fields do not exist', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, query, orderBy, endBefore } = + const { getFirestore, collection, doc, setDoc, getDoc, query, orderBy, endBefore } = firestoreModular; const db = getFirestore(); try { const docRef = doc(db, `${COLLECTION}/iexist`); await setDoc(docRef, { foo: { bar: 'baz' } }); - const snap = await getDocs(docRef); + const snap = await getDoc(docRef); query(collection(db, COLLECTION), orderBy('foo.baz'), endBefore(snap)); return Promise.reject(new Error('Did not throw an Error.')); @@ -232,7 +232,7 @@ describe('firestore().collection().endBefore()', function () { }); it('ends before snapshot field values', async function () { - const { getFirestore, collection, doc, setDoc, query, orderBy, endBefore, getDocs } = + const { getFirestore, collection, doc, setDoc, query, orderBy, endBefore, getDocs, getDoc } = firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/endBefore/snapshotFields`); const doc1 = doc(colRef, 'doc1'); @@ -245,7 +245,7 @@ describe('firestore().collection().endBefore()', function () { setDoc(doc3, { foo: 3, bar: { value: 1 } }), ]); - const endBeforeSnapshot = await getDocs(doc2); + const endBeforeSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, orderBy('bar.value'), endBefore(endBeforeSnapshot))); @@ -254,7 +254,8 @@ describe('firestore().collection().endBefore()', function () { }); it('ends before snapshot', async function () { - const { getFirestore, collection, doc, setDoc, query, endBefore, getDocs } = firestoreModular; + const { getFirestore, collection, doc, setDoc, query, endBefore, getDocs, getDoc } = + firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/endBefore/snapshot`); const doc1 = doc(colRef, 'doc1'); const doc2 = doc(colRef, 'doc2'); @@ -266,7 +267,7 @@ describe('firestore().collection().endBefore()', function () { setDoc(doc3, { foo: 1 }), ]); - const endBeforeSnapshot = await getDocs(doc2); + const endBeforeSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, endBefore(endBeforeSnapshot))); diff --git a/packages/firestore/e2e/Query/orderBy.e2e.js b/packages/firestore/e2e/Query/orderBy.e2e.js index f2b3e580bc..df1943468c 100644 --- a/packages/firestore/e2e/Query/orderBy.e2e.js +++ b/packages/firestore/e2e/Query/orderBy.e2e.js @@ -166,13 +166,13 @@ describe('firestore().collection().orderBy()', function () { }); it('throws if a startAt()/startAfter() has already been set', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, query, startAt, orderBy } = + const { getFirestore, collection, doc, setDoc, getDoc, query, startAt, orderBy } = firestoreModular; const db = getFirestore(); try { const docRef = doc(db, `${COLLECTION}/startATstartAfter`); await setDoc(docRef, { foo: 'bar' }); - const snapshot = await getDocs(docRef); + const snapshot = await getDoc(docRef); query(collection(db, COLLECTION), startAt(snapshot), orderBy('foo')); return Promise.reject(new Error('Did not throw an Error.')); @@ -183,13 +183,13 @@ describe('firestore().collection().orderBy()', function () { }); it('throws if a endAt()/endBefore() has already been set', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, query, endAt, orderBy } = + const { getFirestore, collection, doc, setDoc, getDoc, query, endAt, orderBy } = firestoreModular; const db = getFirestore(); try { const docRef = doc(db, `${COLLECTION}/endAtendBefore`); await setDoc(docRef, { foo: 'bar' }); - const snapshot = await getDocs(docRef); + const snapshot = await getDoc(docRef); query(collection(db, COLLECTION), endAt(snapshot), orderBy('foo')); return Promise.reject(new Error('Did not throw an Error.')); diff --git a/packages/firestore/e2e/Query/startAfter.e2e.js b/packages/firestore/e2e/Query/startAfter.e2e.js index 0df620c1f0..2507b3ccf9 100644 --- a/packages/firestore/e2e/Query/startAfter.e2e.js +++ b/packages/firestore/e2e/Query/startAfter.e2e.js @@ -180,10 +180,10 @@ describe('firestore().collection().startAfter()', function () { }); it('throws if providing snapshot and field values', async function () { - const { getFirestore, collection, doc, getDocs, query, startAfter } = firestoreModular; + const { getFirestore, collection, doc, getDoc, query, startAfter } = firestoreModular; const db = getFirestore(); try { - const docRef = await getDocs(doc(db, `${COLLECTION}/foo`)); + const docRef = await getDoc(doc(db, `${COLLECTION}/foo`)); query(collection(db, COLLECTION), startAfter(docRef, 'baz')); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -193,10 +193,10 @@ describe('firestore().collection().startAfter()', function () { }); it('throws if provided snapshot does not exist', async function () { - const { getFirestore, collection, doc, getDocs, query, startAfter } = firestoreModular; + const { getFirestore, collection, doc, getDoc, query, startAfter } = firestoreModular; const db = getFirestore(); try { - const docRef = await getDocs(doc(db, `${COLLECTION}/idonotexist`)); + const docRef = await getDoc(doc(db, `${COLLECTION}/idonotexist`)); query(collection(db, COLLECTION), startAfter(docRef)); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -206,13 +206,13 @@ describe('firestore().collection().startAfter()', function () { }); it('throws if order used with snapshot but fields do not exist', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, query, orderBy, startAfter } = + const { getFirestore, collection, doc, setDoc, getDoc, query, orderBy, startAfter } = firestoreModular; const db = getFirestore(); try { const docRef = doc(db, `${COLLECTION}/iexist`); await setDoc(docRef, { foo: { bar: 'baz' } }); - const snap = await getDocs(docRef); + const snap = await getDoc(docRef); query(collection(db, COLLECTION), orderBy('foo.baz'), startAfter(snap)); return Promise.reject(new Error('Did not throw an Error.')); @@ -246,7 +246,7 @@ describe('firestore().collection().startAfter()', function () { }); it('starts after snapshot field values', async function () { - const { getFirestore, collection, doc, setDoc, query, startAfter, getDocs } = + const { getFirestore, collection, doc, setDoc, query, startAfter, getDocs, getDoc } = firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/startAfter/snapshotFields`); const doc1 = doc(colRef, 'doc1'); @@ -259,7 +259,7 @@ describe('firestore().collection().startAfter()', function () { setDoc(doc3, { foo: 3, bar: { value: 'c' } }), ]); - const startAfterSnapshot = await getDocs(doc2); + const startAfterSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef.orderBy('bar.value'), startAfter(startAfterSnapshot))); @@ -268,7 +268,7 @@ describe('firestore().collection().startAfter()', function () { }); it('startAfter snapshot', async function () { - const { getFirestore, collection, doc, setDoc, query, startAfter, getDocs } = + const { getFirestore, collection, doc, setDoc, query, startAfter, getDocs, getDoc } = firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/endsAt/snapshot`); const doc1 = doc(colRef, 'doc1'); @@ -281,7 +281,7 @@ describe('firestore().collection().startAfter()', function () { setDoc(doc3, { foo: 1 }), ]); - const startAfterSnapshot = await getDocs(doc2); + const startAfterSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, startAfter(startAfterSnapshot))); @@ -296,6 +296,7 @@ describe('firestore().collection().startAfter()', function () { doc, setDoc, getDocs, + getDoc, query, orderBy, startAfter, @@ -312,8 +313,8 @@ describe('firestore().collection().startAfter()', function () { setDoc(doc3, { age: 3 }), ]); - const first = await getDocs(doc1); - const last = await getDocs(doc3); + const first = await getDoc(doc1); + const last = await getDoc(doc3); const inBetween = await getDocs( query(colRef, orderBy('age', 'asc'), startAfter(first), endBefore(last)), diff --git a/packages/firestore/e2e/Query/startAt.e2e.js b/packages/firestore/e2e/Query/startAt.e2e.js index 7bdaa2e048..ade79139ea 100644 --- a/packages/firestore/e2e/Query/startAt.e2e.js +++ b/packages/firestore/e2e/Query/startAt.e2e.js @@ -167,10 +167,10 @@ describe('firestore().collection().startAt()', function () { }); it('throws if providing snapshot and field values', async function () { - const { getFirestore, collection, doc, getDocs, query, startAt } = firestoreModular; + const { getFirestore, collection, doc, getDoc, query, startAt } = firestoreModular; const db = getFirestore(); try { - const docSnapshot = await getDocs(doc(db, `${COLLECTION}/foo`)); + const docSnapshot = await getDoc(doc(db, `${COLLECTION}/foo`)); query(collection(db, COLLECTION), startAt(docSnapshot, 'baz')); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -180,10 +180,10 @@ describe('firestore().collection().startAt()', function () { }); it('throws if provided snapshot does not exist', async function () { - const { getFirestore, collection, doc, getDocs, query, startAt } = firestoreModular; + const { getFirestore, collection, doc, getDoc, query, startAt } = firestoreModular; const db = getFirestore(); try { - const docSnapshot = await getDocs(doc(db, `${COLLECTION}/idonotexist`)); + const docSnapshot = await getDoc(doc(db, `${COLLECTION}/idonotexist`)); query(collection(db, COLLECTION), startAt(docSnapshot)); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { @@ -193,14 +193,14 @@ describe('firestore().collection().startAt()', function () { }); it('throws if order used with snapshot but fields do not exist', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, query, orderBy, startAt } = + const { getFirestore, collection, doc, setDoc, getDoc, query, orderBy, startAt } = firestoreModular; const db = getFirestore(); try { const docRef = doc(db, `${COLLECTION}/iexist`); await setDoc(docRef, { foo: { bar: 'baz' } }); - const snap = await getDocs(docRef); + const snap = await getDoc(docRef); query(collection(db, COLLECTION), orderBy('foo.baz'), startAt(snap)); return Promise.reject(new Error('Did not throw an Error.')); @@ -234,7 +234,7 @@ describe('firestore().collection().startAt()', function () { }); it('starts at snapshot field values', async function () { - const { getFirestore, collection, doc, setDoc, query, orderBy, startAt, getDocs } = + const { getFirestore, collection, doc, setDoc, query, orderBy, startAt, getDocs, getDoc } = firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/startAt/snapshotFields`); const doc1 = doc(colRef, 'doc1'); @@ -247,7 +247,7 @@ describe('firestore().collection().startAt()', function () { setDoc(doc3, { foo: 3, bar: { value: 'c' } }), ]); - const startAtSnapshot = await getDocs(doc2); + const startAtSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, orderBy('bar.value'), startAt(startAtSnapshot))); @@ -257,7 +257,8 @@ describe('firestore().collection().startAt()', function () { }); it('startAt at snapshot', async function () { - const { getFirestore, collection, doc, setDoc, query, startAt, getDocs } = firestoreModular; + const { getFirestore, collection, doc, setDoc, query, startAt, getDocs, getDoc } = + firestoreModular; const colRef = collection(getFirestore(), `${COLLECTION}/endsAt/snapshot`); const doc1 = doc(colRef, 'doc1'); const doc2 = doc(colRef, 'doc2'); @@ -269,7 +270,7 @@ describe('firestore().collection().startAt()', function () { setDoc(doc3, { foo: 1 }), ]); - const startAtSnapshot = await getDocs(doc2); + const startAtSnapshot = await getDoc(doc2); const qs = await getDocs(query(colRef, startAt(startAtSnapshot))); diff --git a/packages/firestore/e2e/QuerySnapshot.e2e.js b/packages/firestore/e2e/QuerySnapshot.e2e.js index ce6b5f5dcb..c34b90606d 100644 --- a/packages/firestore/e2e/QuerySnapshot.e2e.js +++ b/packages/firestore/e2e/QuerySnapshot.e2e.js @@ -576,7 +576,7 @@ describe('firestore.QuerySnapshot', function () { }); it('returns false if not equal (expensive checks)', async function () { - const { getFirestore, collection, doc, setDoc, getDocs, updateDoc } = firestoreModular; + const { getFirestore, collection, doc, setDoc, getDoc, updateDoc } = firestoreModular; const colRef = collection( getFirestore(), @@ -592,7 +592,7 @@ describe('firestore.QuerySnapshot', function () { }); // Grab snapshot - const qs1 = await getDocs(colRef); + const qs1 = await getDoc(colRef); // Update same collection await updateDoc(docRef, { diff --git a/packages/firestore/e2e/SnapshotMetadata.e2e.js b/packages/firestore/e2e/SnapshotMetadata.e2e.js index ade28485be..343043705a 100644 --- a/packages/firestore/e2e/SnapshotMetadata.e2e.js +++ b/packages/firestore/e2e/SnapshotMetadata.e2e.js @@ -81,25 +81,25 @@ describe('firestore.SnapshotMetadata', function () { describe('modular', function () { it('.fromCache -> returns a boolean', async function () { - const { getFirestore, collection, doc, getDocs } = firestoreModular; + const { getFirestore, collection, doc, getDocs, getDoc } = firestoreModular; const db = getFirestore(); const ref1 = collection(db, COLLECTION); const ref2 = doc(db, `${COLLECTION}/idonotexist`); const colRef = await getDocs(ref1); - const docRef = await getDocs(ref2); + const docRef = await getDoc(ref2); colRef.metadata.fromCache.should.be.Boolean(); docRef.metadata.fromCache.should.be.Boolean(); }); it('.hasPendingWrites -> returns a boolean', async function () { - const { getFirestore, collection, doc, getDocs } = firestoreModular; + const { getFirestore, collection, doc, getDocs, getDoc } = firestoreModular; const db = getFirestore(); const ref1 = collection(db, COLLECTION); const ref2 = doc(db, `${COLLECTION}/idonotexist`); const colRef = await getDocs(ref1); - const docRef = await getDocs(ref2); + const docRef = await getDoc(ref2); colRef.metadata.hasPendingWrites.should.be.Boolean(); docRef.metadata.hasPendingWrites.should.be.Boolean(); }); diff --git a/packages/firestore/e2e/Transaction.e2e.js b/packages/firestore/e2e/Transaction.e2e.js index 18f06cffb3..bbeda39504 100644 --- a/packages/firestore/e2e/Transaction.e2e.js +++ b/packages/firestore/e2e/Transaction.e2e.js @@ -492,7 +492,7 @@ describe('firestore.Transaction', function () { }); it('should delete documents', async function () { - const { getFirestore, runTransaction, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, runTransaction, doc, setDoc, getDoc } = firestoreModular; const db = getFirestore(); const docRef1 = doc(db, `${COLLECTION}/transactions/transaction/delete-delete1`); await setDoc(docRef1, {}); @@ -505,10 +505,10 @@ describe('firestore.Transaction', function () { t.delete(docRef2); }); - const snapshot1 = await getDocs(docRef1); + const snapshot1 = await getDoc(docRef1); snapshot1.exists.should.eql(false); - const snapshot2 = await getDocs(docRef2); + const snapshot2 = await getDoc(docRef2); snapshot2.exists.should.eql(false); }); }); @@ -544,7 +544,7 @@ describe('firestore.Transaction', function () { }); it('should update documents', async function () { - const { getFirestore, runTransaction, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, runTransaction, doc, setDoc, getDoc } = firestoreModular; const db = getFirestore(); const value = Date.now(); @@ -572,11 +572,11 @@ describe('firestore.Transaction', function () { bar: value, }; - const snapshot1 = await getDocs(docRef1); + const snapshot1 = await getDoc(docRef1); snapshot1.exists.should.eql(true); snapshot1.data().should.eql(jet.contextify(expected)); - const snapshot2 = await getDocs(docRef2); + const snapshot2 = await getDoc(docRef2); snapshot2.exists.should.eql(true); snapshot2.data().should.eql(jet.contextify(expected)); }); @@ -638,7 +638,7 @@ describe('firestore.Transaction', function () { }); it('should set data', async function () { - const { getFirestore, runTransaction, doc, getDocs, setDoc } = firestoreModular; + const { getFirestore, runTransaction, doc, getDoc, setDoc } = firestoreModular; const db = getFirestore(); const docRef = doc(db, `${COLLECTION}/transactions/transaction/set`); await setDoc(docRef, { @@ -652,12 +652,12 @@ describe('firestore.Transaction', function () { t.set(docRef, expected); }); - const snapshot = await getDocs(docRef); + const snapshot = await getDoc(docRef); snapshot.data().should.eql(jet.contextify(expected)); }); it('should set data with merge', async function () { - const { getFirestore, runTransaction, doc, getDocs, setDoc } = firestoreModular; + const { getFirestore, runTransaction, doc, getDoc, setDoc } = firestoreModular; const db = getFirestore(); const docRef = doc(db, `${COLLECTION}/transactions/transaction/set-merge`); await setDoc(docRef, { @@ -681,12 +681,12 @@ describe('firestore.Transaction', function () { ); }); - const snapshot = await getDocs(docRef); + const snapshot = await getDoc(docRef); snapshot.data().should.eql(jet.contextify(expected)); }); it('should set data with merge fields', async function () { - const { getFirestore, runTransaction, doc, getDocs, setDoc } = firestoreModular; + const { getFirestore, runTransaction, doc, getDoc, setDoc } = firestoreModular; const db = getFirestore(); const docRef = doc(db, `${COLLECTION}/transactions/transaction/set-mergefields`); @@ -714,12 +714,12 @@ describe('firestore.Transaction', function () { ); }); - const snapshot = await getDocs(docRef); + const snapshot = await getDoc(docRef); snapshot.data().should.eql(jet.contextify(expected)); }); it('should roll back any updates that failed', async function () { - const { getFirestore, runTransaction, doc, getDocs, setDoc } = firestoreModular; + const { getFirestore, runTransaction, doc, getDoc, setDoc } = firestoreModular; const db = getFirestore(); const docRef = doc(db, `${COLLECTION}/transactions/transaction/rollback`); @@ -759,7 +759,7 @@ describe('firestore.Transaction', function () { } catch (error) { error.message.should.containEql(errorMessage); } - const result = await getDocs(docRef); + const result = await getDoc(docRef); should(result.data()).not.have.properties([prop1, prop2]); }); }); diff --git a/packages/firestore/e2e/WriteBatch/commit.e2e.js b/packages/firestore/e2e/WriteBatch/commit.e2e.js index 2e161579bf..43cc9d3278 100644 --- a/packages/firestore/e2e/WriteBatch/commit.e2e.js +++ b/packages/firestore/e2e/WriteBatch/commit.e2e.js @@ -254,7 +254,7 @@ describe('firestore.WriteBatch.commit()', function () { }); it('should set & commit', async function () { - const { getFirestore, writeBatch, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, writeBatch, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(); const lRef = doc(db, `${COLLECTION}/LON`); const nycRef = doc(db, `${COLLECTION}/NYC`); @@ -268,11 +268,7 @@ describe('firestore.WriteBatch.commit()', function () { await batch.commit(); - const [lDoc, nycDoc, sDoc] = await Promise.all([ - getDocs(lRef), - getDocs(nycRef), - getDocs(sfRef), - ]); + const [lDoc, nycDoc, sDoc] = await Promise.all([getDoc(lRef), getDoc(nycRef), getDoc(sfRef)]); lDoc.data().name.should.eql('London'); nycDoc.data().name.should.eql('New York'); @@ -281,7 +277,7 @@ describe('firestore.WriteBatch.commit()', function () { }); it('should set/merge & commit', async function () { - const { getFirestore, writeBatch, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, writeBatch, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(); const lRef = doc(db, `${COLLECTION}/LON`); const nycRef = doc(db, `${COLLECTION}/NYC`); @@ -301,11 +297,7 @@ describe('firestore.WriteBatch.commit()', function () { await batch.commit(); - const [lDoc, nycDoc, sDoc] = await Promise.all([ - getDocs(lRef), - getDocs(nycRef), - getDocs(sfRef), - ]); + const [lDoc, nycDoc, sDoc] = await Promise.all([getDoc(lRef), getDoc(nycRef), getDoc(sfRef)]); lDoc.data().name.should.eql('London'); lDoc.data().country.should.eql('UK'); @@ -318,7 +310,7 @@ describe('firestore.WriteBatch.commit()', function () { }); it('should set/mergeFields & commit', async function () { - const { getFirestore, writeBatch, doc, setDoc, FieldPath, getDocs, deleteDoc } = + const { getFirestore, writeBatch, doc, setDoc, FieldPath, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(); const lRef = doc(db, `${COLLECTION}/LON`); @@ -339,11 +331,7 @@ describe('firestore.WriteBatch.commit()', function () { await batch.commit(); - const [lDoc, nycDoc, sDoc] = await Promise.all([ - getDocs(lRef), - getDocs(nycRef), - getDocs(sfRef), - ]); + const [lDoc, nycDoc, sDoc] = await Promise.all([getDoc(lRef), getDoc(nycRef), getDoc(sfRef)]); lDoc.data().name.should.eql('London'); lDoc.data().country.should.eql('UK'); @@ -356,7 +344,7 @@ describe('firestore.WriteBatch.commit()', function () { }); it('should delete & commit', async function () { - const { getFirestore, writeBatch, doc, setDoc, getDocs } = firestoreModular; + const { getFirestore, writeBatch, doc, setDoc, getDoc } = firestoreModular; const db = getFirestore(); const lRef = doc(db, `${COLLECTION}/LON`); const nycRef = doc(db, `${COLLECTION}/NYC`); @@ -376,11 +364,7 @@ describe('firestore.WriteBatch.commit()', function () { await batch.commit(); - const [lDoc, nycDoc, sDoc] = await Promise.all([ - getDocs(lRef), - getDocs(nycRef), - getDocs(sfRef), - ]); + const [lDoc, nycDoc, sDoc] = await Promise.all([getDoc(lRef), getDoc(nycRef), getDoc(sfRef)]); lDoc.exists.should.be.False(); nycDoc.exists.should.be.False(); @@ -388,7 +372,7 @@ describe('firestore.WriteBatch.commit()', function () { }); it('should update & commit', async function () { - const { getFirestore, writeBatch, doc, setDoc, getDocs, deleteDoc } = firestoreModular; + const { getFirestore, writeBatch, doc, setDoc, getDoc, deleteDoc } = firestoreModular; const db = getFirestore(); const lRef = doc(db, `${COLLECTION}/LON`); const nycRef = doc(db, `${COLLECTION}/NYC`); @@ -408,11 +392,7 @@ describe('firestore.WriteBatch.commit()', function () { await batch.commit(); - const [lDoc, nycDoc, sDoc] = await Promise.all([ - getDocs(lRef), - getDocs(nycRef), - getDocs(sfRef), - ]); + const [lDoc, nycDoc, sDoc] = await Promise.all([getDoc(lRef), getDoc(nycRef), getDoc(sfRef)]); lDoc.data().name.should.eql('LON'); lDoc.data().country.should.eql('UK'); diff --git a/packages/firestore/e2e/firestore.e2e.js b/packages/firestore/e2e/firestore.e2e.js index 2553449a5d..92d95e11d0 100644 --- a/packages/firestore/e2e/firestore.e2e.js +++ b/packages/firestore/e2e/firestore.e2e.js @@ -443,7 +443,7 @@ describe('firestore()', function () { describe('Clear cached data persistence', function () { // NOTE: removed as it breaks emulator tests xit('should clear any cached data', async function () { - const { getFirestore, doc, setDoc, getDocsFromCache, terminate, clearPersistence } = + const { getFirestore, doc, setDoc, getDocFromCache, terminate, clearPersistence } = firestoreModular; const db = getFirestore(); @@ -456,12 +456,12 @@ describe('firestore()', function () { } catch (error) { error.code.should.equal('firestore/failed-precondition'); } - const docRef = await getDocsFromCache(ref); + const docRef = await getDocFromCache(ref); should(docRef.id).equal(id); await terminate(db); await clearPersistence(db); try { - await getDocsFromCache(ref); + await getDocFromCache(ref); return Promise.reject(new Error('Did not throw an Error.')); } catch (error) { error.code.should.equal('firestore/unavailable');