[tests][firestore] add document SnapshotError tests

This commit is contained in:
Salakar
2018-09-21 00:13:05 +01:00
parent f9e9179242
commit c75b722c53

View File

@@ -4,10 +4,14 @@ const {
COL2_DOC_1_ID,
cleanCollection,
COL2_DOC_1_PATH,
TEST_COLLECTION_NAME_DYNAMIC,
resetTestCollectionDoc,
TEST_COLLECTION_NAME_DYNAMIC,
} = TestHelpers.firestore;
function getSnapshotErrorClass() {
return jet.require('src/modules/firestore/SnapshotError');
}
describe('firestore()', () => {
describe('DocumentReference', () => {
before(async () => {
@@ -133,6 +137,34 @@ describe('firestore()', () => {
await sleep(50);
});
it('snapshot error returns instance of SnapshotError', () => {
let unsubscribe;
const { reject, resolve, promise } = Promise.defer();
const collection = firebase.firestore().doc('blocked-collection/nope');
const observer = {
next: () => {
unsubscribe();
reject(new Error('Did not error!'));
},
error: snapshotError => {
snapshotError.should.be.instanceOf(getSnapshotErrorClass());
snapshotError.code.should.be.a.String();
snapshotError.path.should.be.a.String();
snapshotError.appName.should.be.a.String();
snapshotError.message.should.be.a.String();
snapshotError.nativeErrorMessage.should.be.a.String();
snapshotError.appName.should.equal('[DEFAULT]');
snapshotError.path.should.equal('blocked-collection/nope');
snapshotError.code.should.equal('firestore/permission-denied');
resolve();
},
};
unsubscribe = collection.onSnapshot(observer);
return promise;
});
it('calls callback with the initial data and then when value changes', async () => {
await resetTestCollectionDoc(COL2_DOC_1_PATH, { name: 'doc1' });
const docRef = test2DocRef(COL2_DOC_1_ID);