Skip to content

Commit

Permalink
feat(firestore): V9 modular APIs (#7235)
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 authored Sep 22, 2023
1 parent 5c687a8 commit 29d81c4
Show file tree
Hide file tree
Showing 68 changed files with 15,654 additions and 5,606 deletions.
159 changes: 107 additions & 52 deletions packages/firestore/e2e/Aggregate/count.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,117 @@ describe('firestore().collection().count()', function () {
return wipe();
});

it('throws if no argument provided', function () {
try {
firebase.firestore().collection(COLLECTION).startAt();
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
'Expected a DocumentSnapshot or list of field values but got undefined',
);
return Promise.resolve();
}
});
describe('v8 compatibility', function () {
it('throws if no argument provided', function () {
try {
firebase.firestore().collection(COLLECTION).startAt();
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
'Expected a DocumentSnapshot or list of field values but got undefined',
);
return Promise.resolve();
}
});

it('gets count of collection reference - unfiltered', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);
it('gets count of collection reference - unfiltered', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);
const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);

const qs = await colRef.count().get();
qs.data().count.should.eql(3);
});
it('gets countFromServer of collection reference - unfiltered', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);

const qs = await colRef.countFromServer().get();
qs.data().count.should.eql(3);
const qs = await colRef.count().get();
qs.data().count.should.eql(3);
});
it('gets countFromServer of collection reference - unfiltered', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);

const qs = await colRef.countFromServer().get();
qs.data().count.should.eql(3);
});
it('gets correct count of collection reference - where equal', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);

const qs = await colRef.where('foo', '==', 3).count().get();
qs.data().count.should.eql(1);
});
});
it('gets correct count of collection reference - where equal', async function () {
const colRef = firebase.firestore().collection(`${COLLECTION}/count/collection`);

const doc1 = colRef.doc('doc1');
const doc2 = colRef.doc('doc2');
const doc3 = colRef.doc('doc3');
await Promise.all([
doc1.set({ foo: 1, bar: { value: 1 } }),
doc2.set({ foo: 2, bar: { value: 2 } }),
doc3.set({ foo: 3, bar: { value: 3 } }),
]);

const qs = await colRef.where('foo', '==', 3).count().get();
qs.data().count.should.eql(1);

describe('modular', function () {
it('throws if no argument provided', function () {
const { getFirestore, collection, startAt, query } = firestoreModular;

try {
query(collection(getFirestore(), COLLECTION), startAt());
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql(
'Expected a DocumentSnapshot or list of field values but got undefined',
);
return Promise.resolve();
}
});

it('gets countFromServer of collection reference - unfiltered', async function () {
const { getFirestore, collection, doc, setDoc, getCountFromServer } = firestoreModular;

const colRef = collection(getFirestore(), `${COLLECTION}/count/collection`);

const doc1 = doc(colRef, 'doc1');
const doc2 = doc(colRef, 'doc2');
const doc3 = doc(colRef, 'doc3');
await Promise.all([
setDoc(doc1, { foo: 1, bar: { value: 1 } }),
setDoc(doc2, { foo: 2, bar: { value: 2 } }),
setDoc(doc3, { foo: 3, bar: { value: 3 } }),
]);

const qs = await getCountFromServer(colRef);
qs.data().count.should.eql(3);
});

it('gets correct count of collection reference - where equal', async function () {
const { getFirestore, collection, doc, setDoc, query, where, getCountFromServer } =
firestoreModular;

const colRef = collection(getFirestore(), `${COLLECTION}/count/collection`);

const doc1 = doc(colRef, 'doc1');
const doc2 = doc(colRef, 'doc2');
const doc3 = doc(colRef, 'doc3');
await Promise.all([
setDoc(doc1, { foo: 1, bar: { value: 1 } }),
setDoc(doc2, { foo: 2, bar: { value: 2 } }),
setDoc(doc3, { foo: 3, bar: { value: 3 } }),
]);

const qs = await getCountFromServer(query(colRef, where('foo', '==', 3)));
qs.data().count.should.eql(1);
});
});

// TODO
Expand Down
76 changes: 55 additions & 21 deletions packages/firestore/e2e/Bundle/loadBundle.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,62 @@ describe('firestore().loadBundle()', function () {
return await wipe();
});

it('loads the bundle contents', async function () {
const bundle = getBundle();
const progress = await firebase.firestore().loadBundle(bundle);
const query = firebase.firestore().collection(BUNDLE_COLLECTION);
const snapshot = await query.get({ source: 'cache' });

progress.taskState.should.eql('Success');
progress.documentsLoaded.should.eql(6);
snapshot.size.should.eql(6);
describe('v8 compatibility', function () {
it('loads the bundle contents', async function () {
const bundle = getBundle();
const progress = await firebase.firestore().loadBundle(bundle);
const query = firebase.firestore().collection(BUNDLE_COLLECTION);
const snapshot = await query.get({ source: 'cache' });

progress.taskState.should.eql('Success');
progress.documentsLoaded.should.eql(6);
snapshot.size.should.eql(6);
});

it('throws if invalid bundle', async function () {
try {
await firebase.firestore().loadBundle('not-a-bundle');
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
/*
* Due to inconsistent error throws between Android and iOS Firebase SDK,
* it is not able to test a specific error message.
* Android SDK throws 'invalid-arguments', while iOS SDK throws 'unknown'
*/
return Promise.resolve();
}
});
});

it('throws if invalid bundle', async function () {
try {
await firebase.firestore().loadBundle('not-a-bundle');
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
/*
* Due to inconsistent error throws between Android and iOS Firebase SDK,
* it is not able to test a specific error message.
* Android SDK throws 'invalid-arguments', while iOS SDK throws 'unknown'
*/
return Promise.resolve();
}
describe('modular', function () {
it('loads the bundle contents', async function () {
const { getFirestore, loadBundle, collection, getDocsFromCache } = firestoreModular;
const db = getFirestore();

const bundle = getBundle();
const progress = await loadBundle(db, bundle);
const query = collection(db, BUNDLE_COLLECTION);
const snapshot = await getDocsFromCache(query);

progress.taskState.should.eql('Success');
progress.documentsLoaded.should.eql(6);
snapshot.size.should.eql(6);
});

it('throws if invalid bundle', async function () {
const { getFirestore, loadBundle } = firestoreModular;

try {
await loadBundle(getFirestore(), 'not-a-bundle');
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
/*
* Due to inconsistent error throws between Android and iOS Firebase SDK,
* it is not able to test a specific error message.
* Android SDK throws 'invalid-arguments', while iOS SDK throws 'unknown'
*/
return Promise.resolve();
}
});
});
});
Loading

0 comments on commit 29d81c4

Please sign in to comment.