Skip to content

Commit 4aeae44

Browse files
committed
test(firestore): use modular API in modular tests to avoid deprecation
1 parent 9132149 commit 4aeae44

18 files changed

+122
-104
lines changed

packages/firestore/e2e/Bundle/namedQuery.e2e.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('firestore().namedQuery()', function () {
2323

2424
beforeEach(async function () {
2525
await wipe();
26-
return await firebase.firestore().loadBundle(getBundle());
26+
const { getFirestore, loadBundle } = firestoreModular;
27+
return await loadBundle(getFirestore(), getBundle());
2728
});
2829

2930
// FIXME named query functionality appears to have an android-only issue

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,13 @@ describe('firestore.doc().set()', function () {
353353
});
354354

355355
it('throws if mergeFields contains invalid data', function () {
356-
const { getFirestore, doc, setDoc } = firestoreModular;
356+
const { getFirestore, doc, setDoc, FieldPath } = firestoreModular;
357357
try {
358358
setDoc(
359359
doc(getFirestore(), `${COLLECTION}/baz`),
360360
{},
361361
{
362-
mergeFields: [
363-
'foo',
364-
'foo.bar',
365-
new firebase.firestore.FieldPath(COLLECTION, 'baz'),
366-
123,
367-
],
362+
mergeFields: ['foo', 'foo.bar', new FieldPath(COLLECTION, 'baz'), 123],
368363
},
369364
);
370365
return Promise.reject(new Error('Did not throw an Error.'));
@@ -408,7 +403,7 @@ describe('firestore.doc().set()', function () {
408403
});
409404

410405
it('merges specific fields', async function () {
411-
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
406+
const { getFirestore, doc, setDoc, getDoc, deleteDoc, FieldPath } = firestoreModular;
412407
const ref = doc(getFirestore(), `${COLLECTION}/merge`);
413408
const data1 = { foo: '123', bar: 123, baz: '456' };
414409
const data2 = { foo: '234', bar: 234, baz: '678' };
@@ -417,7 +412,7 @@ describe('firestore.doc().set()', function () {
417412
const snapshot1 = await getDoc(ref);
418413
snapshot1.data().should.eql(jet.contextify(data1));
419414
await setDoc(ref, data2, {
420-
mergeFields: ['bar', new firebase.firestore.FieldPath('baz')],
415+
mergeFields: ['bar', new FieldPath('baz')],
421416
});
422417
const snapshot2 = await getDoc(ref);
423418
snapshot2.data().should.eql(jet.contextify(merged));

packages/firestore/e2e/DocumentSnapshot/isEqual.e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('firestore.doc() -> snapshot.isEqual()', function () {
9191
await setDoc(docRef, { foo: 'bar' });
9292

9393
const docSnapshot1 = await getDoc(docRef);
94-
const docSnapshot2 = await doc(db, `${COLLECTION}/idonotexist`).get();
94+
const docSnapshot2 = await getDoc(doc(db, `${COLLECTION}/idonotexist`));
9595
await setDoc(docRef, { foo: 'baz' });
9696
const docSnapshot3 = await getDoc(docRef);
9797

packages/firestore/e2e/DocumentSnapshot/properties.e2e.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('firestore().doc() -> snapshot', function () {
7979
describe('modular', function () {
8080
it('.exists -> returns a boolean for exists', async function () {
8181
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
82-
const db = getFirestore(firebase.app());
82+
const db = getFirestore();
8383

8484
const ref1 = doc(db, `${COLLECTION}/exists`);
8585
const ref2 = doc(db, `${COLLECTION}/idonotexist`);
@@ -94,7 +94,7 @@ describe('firestore().doc() -> snapshot', function () {
9494

9595
it('.id -> returns the correct id', async function () {
9696
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
97-
const db = getFirestore(firebase.app());
97+
const db = getFirestore();
9898

9999
const ref1 = doc(db, `${COLLECTION}/exists`);
100100
const ref2 = doc(db, `${COLLECTION}/idonotexist`);
@@ -116,7 +116,7 @@ describe('firestore().doc() -> snapshot', function () {
116116

117117
it('.ref -> returns the correct document ref', async function () {
118118
const { getFirestore, doc, setDoc, getDoc, deleteDoc } = firestoreModular;
119-
const db = getFirestore(firebase.app());
119+
const db = getFirestore();
120120
const ref1 = doc(db, `${COLLECTION}/exists`);
121121
const ref2 = doc(db, `${COLLECTION}/idonotexist`);
122122
await setDoc(ref1, { foo: ' bar' });

packages/firestore/e2e/FieldValue.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ describe('firestore.FieldValue', function () {
392392
snapshot1.data().foo.nanoseconds.should.be.a.Number();
393393
const current = snapshot1.data().foo.nanoseconds;
394394
await Utils.sleep(100);
395-
await updateDoc(ref, { foo: firebase.firestore.FieldValue.serverTimestamp() });
396-
const snapshot2 = await ref.get();
395+
await updateDoc(ref, { foo: serverTimestamp() });
396+
const snapshot2 = await getDoc(ref);
397397
snapshot2.data().foo.nanoseconds.should.be.a.Number();
398398
should.equal(current === snapshot2.data().foo.nanoseconds, false);
399399
await deleteDoc(ref);

packages/firestore/e2e/Query/isEqual.e2e.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ describe('firestore().collection().isEqual()', function () {
151151
});
152152

153153
it('returns false when not equal (simple checks)', function () {
154+
const { getApp } = modular;
154155
const { getFirestore, collection, query, where, orderBy, limit } = firestoreModular;
155156
const db = getFirestore();
156-
const secondaryDb = getFirestore(firebase.app('secondaryFromNative'));
157+
const secondaryDb = getFirestore(getApp('secondaryFromNative'));
157158

158159
const subCol = `${COLLECTION}/isequal/simplechecks`;
159160
const queryRef = collection(db, subCol);

packages/firestore/e2e/Query/query.e2e.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ describe('FirestoreQuery/FirestoreQueryModifiers', function () {
113113

114114
try {
115115
query(
116-
collection(db, COLLECTION)
117-
.where('foo', '==', 'bar')
118-
.orderBy('bar')
119-
.orderBy('foo')
120-
.limit(1)
121-
.endAt(2),
116+
collection(db, COLLECTION),
117+
where('foo', '==', 'bar'),
118+
orderBy('bar'),
119+
orderBy('foo'),
120+
limit(1),
121+
endAt(2),
122122
);
123123
return Promise.reject(new Error('Did not throw an Error.'));
124124
} catch (error) {

packages/firestore/e2e/Query/startAfter.e2e.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe('firestore().collection().startAfter()', function () {
256256
});
257257

258258
it('starts after snapshot field values', async function () {
259-
const { getFirestore, collection, doc, setDoc, query, startAfter, getDocs, getDoc } =
259+
const { getFirestore, collection, doc, setDoc, query, startAfter, getDocs, getDoc, orderBy } =
260260
firestoreModular;
261261
const colRef = collection(getFirestore(), `${COLLECTION}/startAfter/snapshotFields`);
262262
const doc1 = doc(colRef, 'doc1');
@@ -271,7 +271,7 @@ describe('firestore().collection().startAfter()', function () {
271271

272272
const startAfterSnapshot = await getDoc(doc2);
273273

274-
const qs = await getDocs(query(colRef.orderBy('bar.value'), startAfter(startAfterSnapshot)));
274+
const qs = await getDocs(query(colRef, orderBy('bar.value'), startAfter(startAfterSnapshot)));
275275

276276
qs.docs.length.should.eql(1);
277277
qs.docs[0].id.should.eql('doc3');

packages/firestore/e2e/Query/where.and.filter.e2e.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
*/
1717
const COLLECTION = 'firestore';
1818
const { wipe } = require('../helpers');
19-
let Filter;
19+
const { Filter } = firestoreModular;
2020

2121
describe(' firestore().collection().where(AND Filters)', function () {
2222
beforeEach(async function () {
23-
Filter = firebase.firestore.Filter;
2423
return await wipe();
2524
});
2625

@@ -778,14 +777,14 @@ describe(' firestore().collection().where(AND Filters)', function () {
778777
});
779778

780779
it('allows multiple inequalities (excluding `!=`) on different paths provided', async function () {
781-
const { getFirestore, collection, query, and, where } = firestoreModular;
780+
const { getFirestore, addDoc, collection, query, and, where } = firestoreModular;
782781
const colRef = collection(getFirestore(), `${COLLECTION}/filter/different-path-inequality`);
783782

784783
const expected = { foo: { bar: 300 }, bar: 200 };
785784
await Promise.all([
786-
colRef.add({ foo: { bar: 1 }, bar: 1 }),
787-
colRef.add(expected),
788-
colRef.add(expected),
785+
addDoc(colRef, { foo: { bar: 1 }, bar: 1 }),
786+
addDoc(colRef, expected),
787+
addDoc(colRef, expected),
789788
]);
790789

791790
const snapshot = await query(
@@ -990,15 +989,16 @@ describe(' firestore().collection().where(AND Filters)', function () {
990989
});
991990

992991
it("should allow query when combining '!=' operator with any other inequality operator on a different field", async function () {
993-
const { query, where, and } = firestoreModular;
994-
const colRef = firebase
995-
.firestore()
996-
.collection(`${COLLECTION}/filter/inequality-combine-not-equal`);
992+
const { getFirestore, addDoc, collection, query, where, and } = firestoreModular;
993+
const colRef = collection(
994+
getFirestore(),
995+
`${COLLECTION}/filter/inequality-combine-not-equal`,
996+
);
997997
const expected = { foo: { bar: 300 }, bar: 200 };
998998
await Promise.all([
999-
colRef.add({ foo: { bar: 1 }, bar: 1 }),
1000-
colRef.add(expected),
1001-
colRef.add(expected),
999+
addDoc(colRef, { foo: { bar: 1 }, bar: 1 }),
1000+
addDoc(colRef, expected),
1001+
addDoc(colRef, expected),
10021002
]);
10031003

10041004
const snapshot = await query(
@@ -1368,8 +1368,8 @@ describe(' firestore().collection().where(AND Filters)', function () {
13681368
query(
13691369
colRef,
13701370
and(
1371-
where(new firebase.firestore.FieldPath('foo', 'bar'), '>', 1),
1372-
where(new firebase.firestore.FieldPath('foo', 'bar'), '<', 3),
1371+
where(new FieldPath('foo', 'bar'), '>', 1),
1372+
where(new FieldPath('foo', 'bar'), '<', 3),
13731373
),
13741374
orderBy(new FieldPath('foo', 'bar')),
13751375
),

packages/firestore/e2e/Query/where.e2e.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -659,16 +659,14 @@ describe('firestore().collection().where()', function () {
659659
});
660660

661661
it('allows multiple inequalities (excluding `!=`) on different paths provided', async function () {
662-
const { query, where } = firestoreModular;
662+
const { getFirestore, addDoc, collection, query, where } = firestoreModular;
663663

664-
const colRef = firebase
665-
.firestore()
666-
.collection(`${COLLECTION}/filter/different-path-inequality`);
664+
const colRef = collection(getFirestore(), `${COLLECTION}/filter/different-path-inequality`);
667665
const expected = { foo: { bar: 300 }, bar: 200 };
668666
await Promise.all([
669-
colRef.add({ foo: { bar: 1 }, bar: 1 }),
670-
colRef.add(expected),
671-
colRef.add(expected),
667+
addDoc(colRef, { foo: { bar: 1 }, bar: 1 }),
668+
addDoc(colRef, expected),
669+
addDoc(colRef, expected),
672670
]);
673671

674672
const snapshot = await query(
@@ -1132,16 +1130,16 @@ describe('firestore().collection().where()', function () {
11321130
});
11331131

11341132
it("should allow query when combining '!=' operator with any other inequality operator on a different field", async function () {
1135-
const { getFirestore, collection, query, where } = firestoreModular;
1133+
const { getFirestore, addDoc, collection, query, where } = firestoreModular;
11361134
const colRef = collection(
11371135
getFirestore(),
11381136
`${COLLECTION}/filter/inequality-combine-not-equal`,
11391137
);
11401138
const expected = { foo: { bar: 300 }, bar: 200 };
11411139
await Promise.all([
1142-
colRef.add({ foo: { bar: 1 }, bar: 1 }),
1143-
colRef.add(expected),
1144-
colRef.add(expected),
1140+
addDoc(colRef, { foo: { bar: 1 }, bar: 1 }),
1141+
addDoc(colRef, expected),
1142+
addDoc(colRef, expected),
11451143
]);
11461144

11471145
const snapshot = await query(colRef, where('foo.bar', '>', 123), where('bar', '!=', 1)).get();

0 commit comments

Comments
 (0)