Skip to content

Commit bddca6b

Browse files
committed
Update integration tests to use free functions
1 parent 7cd9eb3 commit bddca6b

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

packages/firestore/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
QuerySnapshot,
3131
Transaction,
3232
WriteBatch,
33+
loadBundle,
34+
namedQuery,
3335
setLogLevel
3436
} from './api/database';
3537
import { Blob } from './api/blob';
@@ -54,6 +56,8 @@ const firestoreNamespace = {
5456
FieldPath,
5557
FieldValue,
5658
setLogLevel,
59+
loadBundle,
60+
namedQuery,
5761
CACHE_SIZE_UNLIMITED
5862
};
5963

packages/firestore/test/integration/api/bundle.test.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ apiDescribe('Bundles', (persistence: boolean) => {
9595
return withTestDb(persistence, async db => {
9696
const progressEvents: firestore.LoadBundleTaskProgress[] = [];
9797
let completeCalled = false;
98-
const task: firestore.LoadBundleTask = db.loadBundle(bundleString(db));
98+
const task: firestore.LoadBundleTask = firestore.loadBundle(
99+
db,
100+
bundleString(db)
101+
);
99102
task.onProgress(
100103
progress => {
101104
progressEvents.push(progress);
@@ -124,12 +127,12 @@ apiDescribe('Bundles', (persistence: boolean) => {
124127
let snap = await db.collection('coll-1').get({ source: 'cache' });
125128
verifySnapEqualsTestDocs(snap);
126129

127-
snap = await (await db.namedQuery('limit'))!.get({
130+
snap = await (await firestore.namedQuery(db, 'limit'))!.get({
128131
source: 'cache'
129132
});
130133
expect(toDataArray(snap)).to.deep.equal([{ k: 'b', bar: 2 }]);
131134

132-
snap = await (await db.namedQuery('limit-to-last'))!.get({
135+
snap = await (await firestore.namedQuery(db, 'limit-to-last'))!.get({
133136
source: 'cache'
134137
});
135138
expect(toDataArray(snap)).to.deep.equal([{ k: 'a', bar: 1 }]);
@@ -138,7 +141,8 @@ apiDescribe('Bundles', (persistence: boolean) => {
138141

139142
it('load with documents and queries with promise interface', () => {
140143
return withTestDb(persistence, async db => {
141-
const fulfillProgress: firestore.LoadBundleTaskProgress = await db.loadBundle(
144+
const fulfillProgress: firestore.LoadBundleTaskProgress = await firestore.loadBundle(
145+
db,
142146
bundleString(db)
143147
);
144148

@@ -153,11 +157,12 @@ apiDescribe('Bundles', (persistence: boolean) => {
153157

154158
it('load for a second time skips', () => {
155159
return withTestDb(persistence, async db => {
156-
await db.loadBundle(bundleString(db));
160+
await firestore.loadBundle(db, bundleString(db));
157161

158162
let completeCalled = false;
159163
const progressEvents: firestore.LoadBundleTaskProgress[] = [];
160-
const task: firestore.LoadBundleTask = db.loadBundle(
164+
const task: firestore.LoadBundleTask = firestore.loadBundle(
165+
db,
161166
encoder.encode(bundleString(db))
162167
);
163168
task.onProgress(
@@ -193,7 +198,8 @@ apiDescribe('Bundles', (persistence: boolean) => {
193198
db.collection('coll-1').onSnapshot(accumulator.storeEvent);
194199
await accumulator.awaitEvent();
195200

196-
const progress = await db.loadBundle(
201+
const progress = await firestore.loadBundle(
202+
db,
197203
// Testing passing in non-string bundles.
198204
encoder.encode(bundleString(db))
199205
);
@@ -204,17 +210,18 @@ apiDescribe('Bundles', (persistence: boolean) => {
204210
// cache can only be tested in spec tests.
205211
await accumulator.assertNoAdditionalEvents();
206212

207-
let snap = await (await db.namedQuery('limit'))!.get();
213+
let snap = await (await firestore.namedQuery(db, 'limit'))!.get();
208214
expect(toDataArray(snap)).to.deep.equal([{ k: 'b', bar: 0 }]);
209215

210-
snap = await (await db.namedQuery('limit-to-last'))!.get();
216+
snap = await (await firestore.namedQuery(db, 'limit-to-last'))!.get();
211217
expect(toDataArray(snap)).to.deep.equal([{ k: 'a', bar: 0 }]);
212218
});
213219
});
214220

215221
it('loaded documents should not be GC-ed right away', () => {
216222
return withTestDb(persistence, async db => {
217-
const fulfillProgress: firestore.LoadBundleTaskProgress = await db.loadBundle(
223+
const fulfillProgress: firestore.LoadBundleTaskProgress = await firestore.loadBundle(
224+
db,
218225
bundleString(db)
219226
);
220227

@@ -235,12 +242,15 @@ apiDescribe('Bundles', (persistence: boolean) => {
235242
it('load with documents from other projects fails', () => {
236243
return withTestDb(persistence, async db => {
237244
return withAlternateTestDb(persistence, async otherDb => {
238-
await expect(otherDb.loadBundle(bundleString(db))).to.be.rejectedWith(
239-
'Tried to deserialize key from different project'
240-
);
245+
await expect(
246+
firestore.loadBundle(otherDb, bundleString(db))
247+
).to.be.rejectedWith('Tried to deserialize key from different project');
241248

242249
// Verify otherDb still functions, despite loaded a problematic bundle.
243-
const finalProgress = await otherDb.loadBundle(bundleString(otherDb));
250+
const finalProgress = await firestore.loadBundle(
251+
otherDb,
252+
bundleString(otherDb)
253+
);
244254
verifySuccessProgress(finalProgress);
245255

246256
// Read from cache. These documents do not exist in backend, so they can

0 commit comments

Comments
 (0)