[tests][firestore] Add test cases for limit with onSnapshot

This commit is contained in:
Chris Bianca 2017-11-07 13:15:16 +00:00
parent cd911d2442
commit e6ea5348ff
2 changed files with 44 additions and 9 deletions

View File

@ -500,9 +500,12 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft
}); });
}); });
}); });
});
it('correctly handles limit', async () => { context('limit', () => {
const collectionTests = firebase.native.firestore().collection('collection-tests2'); let collectionTests;
before(async () => {
collectionTests = firebase.native.firestore().collection('collection-tests2');
await Promise.all([ await Promise.all([
collectionTests.doc('col1').set(COL_1), collectionTests.doc('col1').set(COL_1),
collectionTests.doc('col2').set({ ...COL_1, daz: 234 }), collectionTests.doc('col2').set({ ...COL_1, daz: 234 }),
@ -510,7 +513,9 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft
collectionTests.doc('col4').set({ ...COL_1, daz: 234 }), collectionTests.doc('col4').set({ ...COL_1, daz: 234 }),
collectionTests.doc('col5').set({ ...COL_1, daz: 234 }), collectionTests.doc('col5').set({ ...COL_1, daz: 234 }),
]); ]);
});
it('correctly works with get()', async () => {
return collectionTests.limit(3) return collectionTests.limit(3)
.get() .get()
.then((querySnapshot) => { .then((querySnapshot) => {
@ -518,6 +523,33 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft
return cleanCollection(collectionTests); return cleanCollection(collectionTests);
}); });
}); });
it('correctly works with onSnapshot()', async () => {
const collectionRef = collectionTests.limit(3);
const callback = sinon.spy();
// Test
let unsubscribe;
await new Promise((resolve2) => {
unsubscribe = collectionRef.onSnapshot((snapshot) => {
callback(snapshot.size);
resolve2();
});
});
// Assertions
callback.should.be.calledWith(3);
// Tear down
unsubscribe();
});
after(() => {
return cleanCollection(collectionTests);
});
}); });
context('cursors', () => { context('cursors', () => {
@ -526,10 +558,10 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft
collectionTests = firebase.native.firestore().collection('collection-tests2'); collectionTests = firebase.native.firestore().collection('collection-tests2');
await Promise.all([ await Promise.all([
collectionTests.doc('col1').set({ ...COL_1, foo: 'bar0' }), collectionTests.doc('col1').set({ ...COL_1, foo: 'bar0' }),
collectionTests.doc('col2').set({ ...COL_1, foo: 'bar1', daz: 234, timestamp: new Date(2017, 2, 11, 10, 0, 0) }), collectionTests.doc('col2').set({ ...COL_1, foo: 'bar1', daz: 234, object: { daz: 234 }, timestamp: new Date(2017, 2, 11, 10, 0, 0) }),
collectionTests.doc('col3').set({ ...COL_1, foo: 'bar2', daz: 345, timestamp: new Date(2017, 2, 12, 10, 0, 0) }), collectionTests.doc('col3').set({ ...COL_1, foo: 'bar2', daz: 345, object: { daz: 345 }, timestamp: new Date(2017, 2, 12, 10, 0, 0) }),
collectionTests.doc('col4').set({ ...COL_1, foo: 'bar3', daz: 456, timestamp: new Date(2017, 2, 13, 10, 0, 0) }), collectionTests.doc('col4').set({ ...COL_1, foo: 'bar3', daz: 456, object: { daz: 456 }, timestamp: new Date(2017, 2, 13, 10, 0, 0) }),
collectionTests.doc('col5').set({ ...COL_1, foo: 'bar4', daz: 567, timestamp: new Date(2017, 2, 14, 10, 0, 0) }), collectionTests.doc('col5').set({ ...COL_1, foo: 'bar4', daz: 567, object: { daz: 567 }, timestamp: new Date(2017, 2, 14, 10, 0, 0) }),
]); ]);
}); });
@ -739,8 +771,8 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft
context('onSnapshot()', () => { context('onSnapshot()', () => {
it('gets called correctly', async () => { it('gets called correctly', async () => {
const collectionRef = collectionTests.orderBy('timestamp').endAt(new Date(2017, 2, 12, 10, 0, 0)); const collectionRef = collectionTests.orderBy('object.daz').endAt(345);
const newDocValue = { ...COL_1, foo: 'updated' }; const newDocValue = { ...COL_1, object: { daz: 346 } };
const callback = sinon.spy(); const callback = sinon.spy();
@ -765,7 +797,7 @@ function collectionReferenceTests({ describe, it, context, firebase, before, aft
// Assertions // Assertions
callback.should.be.calledWith([123, 234, 345]); callback.should.be.calledWith([234, 345]);
callback.should.be.calledTwice(); callback.should.be.calledTwice();
// Tear down // Tear down

View File

@ -16,6 +16,9 @@ export const COL_1 = {
gaz: 12.1234567, gaz: 12.1234567,
geopoint: new firebase.native.firestore.GeoPoint(0, 0), geopoint: new firebase.native.firestore.GeoPoint(0, 0),
naz: null, naz: null,
object: {
daz: 123,
},
timestamp: new Date(2017, 2, 10, 10, 0, 0), timestamp: new Date(2017, 2, 10, 10, 0, 0),
}; };