[tests][firestore] misc tests

This commit is contained in:
Salakar 2018-04-13 13:49:03 +01:00
parent 8abafb8cd8
commit 47774a1a4a
3 changed files with 81 additions and 18 deletions

View File

@ -1,13 +1,20 @@
const {
COL_DOC_1,
COL_DOC_1_ID,
COL_DOC_1_PATH,
testCollectionDoc,
resetTestCollectionDoc,
} = TestHelpers.firestore;
describe('firestore()', () => {
describe('DocumentSnapshot', () => {
before(async () => {
await TestHelpers.firestore.resetTestCollectionDoc();
await resetTestCollectionDoc(COL_DOC_1_PATH, COL_DOC_1());
});
describe('id', () => {
it('returns a string document id', async () => {
const { testCollectionDoc, COL_DOC_1_ID } = TestHelpers.firestore;
const snapshot = await testCollectionDoc().get();
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
snapshot.id.should.be.a.String();
snapshot.id.should.equal(COL_DOC_1_ID);
});
@ -15,8 +22,7 @@ describe('firestore()', () => {
describe('ref', () => {
it('returns a DocumentReference', async () => {
const { testCollectionDoc } = TestHelpers.firestore;
const snapshot = await testCollectionDoc().get();
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const DocumentReference = bridge.require(
'react-native-firebase/dist/modules/firestore/DocumentReference'
);
@ -26,8 +32,7 @@ describe('firestore()', () => {
describe('metadata', () => {
it('returns an object of meta data', async () => {
const { testCollectionDoc } = TestHelpers.firestore;
const { metadata } = await testCollectionDoc().get();
const { metadata } = await testCollectionDoc(COL_DOC_1_PATH).get();
metadata.should.be.an.Object();
metadata.should.have.property('hasPendingWrites');
metadata.should.have.property('fromCache');
@ -38,8 +43,7 @@ describe('firestore()', () => {
describe('exists', () => {
it('returns a boolean', async () => {
const { testCollectionDoc } = TestHelpers.firestore;
const { exists } = await testCollectionDoc().get();
const { exists } = await testCollectionDoc(COL_DOC_1_PATH).get();
exists.should.be.a.Boolean();
exists.should.be.true();
});
@ -48,8 +52,7 @@ describe('firestore()', () => {
describe('data()', () => {
it('returns document data', async () => {
// additionally tests context binding not lost during destructuring
const { testCollectionDoc } = TestHelpers.firestore;
const snapshot = await testCollectionDoc().get();
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const { data } = snapshot;
snapshot.data.should.be.a.Function();
@ -66,8 +69,7 @@ describe('firestore()', () => {
describe('get()', () => {
it('using a dot notated path string', async () => {
// additionally tests context binding not lost during destructuring
const { testCollectionDoc } = TestHelpers.firestore;
const snapshot = await testCollectionDoc().get();
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const { get } = snapshot;
should.equal(snapshot.get('foo'), 'bar');
@ -81,8 +83,7 @@ describe('firestore()', () => {
});
it('using a FieldPath instance', async () => {
const { testCollectionDoc } = TestHelpers.firestore;
const snapshot = await testCollectionDoc().get();
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
should.equal(snapshot.get('foo'), 'bar');

View File

@ -1,7 +1,14 @@
const {
COL_DOC_1,
COL_DOC_1_PATH,
testCollectionDoc,
resetTestCollectionDoc,
} = TestHelpers.firestore;
describe('firestore()', () => {
describe('FieldPath', () => {
before(async () => {
await TestHelpers.firestore.resetTestCollectionDoc();
await resetTestCollectionDoc(COL_DOC_1_PATH, COL_DOC_1());
});
it('documentId() should return a FieldPath', () => {
@ -10,8 +17,7 @@ describe('firestore()', () => {
});
it('should allow getting values via documentSnapshot.get(FieldPath)', async () => {
const { testCollectionDoc } = TestHelpers.firestore;
const snapshot = await testCollectionDoc().get();
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
should.equal(snapshot.get('foo'), 'bar');

View File

@ -0,0 +1,56 @@
const {
DOC_2,
DOC_2_PATH,
testCollectionDoc,
resetTestCollectionDoc,
} = TestHelpers.firestore;
describe('firestore()', () => {
describe('FieldValue', () => {
before(async () => {
await resetTestCollectionDoc(DOC_2_PATH, DOC_2);
});
describe('delete()', () => {
it('should delete a field', async () => {
const { data } = await testCollectionDoc(DOC_2_PATH).get();
should.equal(data().title, DOC_2.title);
console.log('after 1st get');
await testCollectionDoc(DOC_2_PATH).update({
title: firebase.firestore.FieldValue.delete(),
});
console.log('after update');
const { data: dataAfterUpdate } = await testCollectionDoc(
DOC_2_PATH
).get();
console.log('after 2nd get');
should.equal(dataAfterUpdate().title, undefined);
});
});
describe('serverTimestamp()', () => {
it('should set timestamp', async () => {
const { data } = await testCollectionDoc(DOC_2_PATH).get();
should.equal(data().creationDate, undefined);
console.log('after 1st get');
await testCollectionDoc(DOC_2_PATH).update({
creationDate: firebase.firestore.FieldValue.serverTimestamp(),
});
console.log('after update');
const { data: dataAfterUpdate } = await testCollectionDoc(
DOC_2_PATH
).get();
console.log('after 2nd get');
dataAfterUpdate().creationDate.should.be.instanceof(
bridge.context.window.Date
);
});
});
});
});