[tests][firestore] misc tests
This commit is contained in:
parent
8abafb8cd8
commit
47774a1a4a
|
@ -1,13 +1,20 @@
|
||||||
|
const {
|
||||||
|
COL_DOC_1,
|
||||||
|
COL_DOC_1_ID,
|
||||||
|
COL_DOC_1_PATH,
|
||||||
|
testCollectionDoc,
|
||||||
|
resetTestCollectionDoc,
|
||||||
|
} = TestHelpers.firestore;
|
||||||
|
|
||||||
describe('firestore()', () => {
|
describe('firestore()', () => {
|
||||||
describe('DocumentSnapshot', () => {
|
describe('DocumentSnapshot', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await TestHelpers.firestore.resetTestCollectionDoc();
|
await resetTestCollectionDoc(COL_DOC_1_PATH, COL_DOC_1());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('id', () => {
|
describe('id', () => {
|
||||||
it('returns a string document id', async () => {
|
it('returns a string document id', async () => {
|
||||||
const { testCollectionDoc, COL_DOC_1_ID } = TestHelpers.firestore;
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const snapshot = await testCollectionDoc().get();
|
|
||||||
snapshot.id.should.be.a.String();
|
snapshot.id.should.be.a.String();
|
||||||
snapshot.id.should.equal(COL_DOC_1_ID);
|
snapshot.id.should.equal(COL_DOC_1_ID);
|
||||||
});
|
});
|
||||||
|
@ -15,8 +22,7 @@ describe('firestore()', () => {
|
||||||
|
|
||||||
describe('ref', () => {
|
describe('ref', () => {
|
||||||
it('returns a DocumentReference', async () => {
|
it('returns a DocumentReference', async () => {
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const snapshot = await testCollectionDoc().get();
|
|
||||||
const DocumentReference = bridge.require(
|
const DocumentReference = bridge.require(
|
||||||
'react-native-firebase/dist/modules/firestore/DocumentReference'
|
'react-native-firebase/dist/modules/firestore/DocumentReference'
|
||||||
);
|
);
|
||||||
|
@ -26,8 +32,7 @@ describe('firestore()', () => {
|
||||||
|
|
||||||
describe('metadata', () => {
|
describe('metadata', () => {
|
||||||
it('returns an object of meta data', async () => {
|
it('returns an object of meta data', async () => {
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const { metadata } = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const { metadata } = await testCollectionDoc().get();
|
|
||||||
metadata.should.be.an.Object();
|
metadata.should.be.an.Object();
|
||||||
metadata.should.have.property('hasPendingWrites');
|
metadata.should.have.property('hasPendingWrites');
|
||||||
metadata.should.have.property('fromCache');
|
metadata.should.have.property('fromCache');
|
||||||
|
@ -38,8 +43,7 @@ describe('firestore()', () => {
|
||||||
|
|
||||||
describe('exists', () => {
|
describe('exists', () => {
|
||||||
it('returns a boolean', async () => {
|
it('returns a boolean', async () => {
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const { exists } = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const { exists } = await testCollectionDoc().get();
|
|
||||||
exists.should.be.a.Boolean();
|
exists.should.be.a.Boolean();
|
||||||
exists.should.be.true();
|
exists.should.be.true();
|
||||||
});
|
});
|
||||||
|
@ -48,8 +52,7 @@ describe('firestore()', () => {
|
||||||
describe('data()', () => {
|
describe('data()', () => {
|
||||||
it('returns document data', async () => {
|
it('returns document data', async () => {
|
||||||
// additionally tests context binding not lost during destructuring
|
// additionally tests context binding not lost during destructuring
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const snapshot = await testCollectionDoc().get();
|
|
||||||
const { data } = snapshot;
|
const { data } = snapshot;
|
||||||
|
|
||||||
snapshot.data.should.be.a.Function();
|
snapshot.data.should.be.a.Function();
|
||||||
|
@ -66,8 +69,7 @@ describe('firestore()', () => {
|
||||||
describe('get()', () => {
|
describe('get()', () => {
|
||||||
it('using a dot notated path string', async () => {
|
it('using a dot notated path string', async () => {
|
||||||
// additionally tests context binding not lost during destructuring
|
// additionally tests context binding not lost during destructuring
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const snapshot = await testCollectionDoc().get();
|
|
||||||
const { get } = snapshot;
|
const { get } = snapshot;
|
||||||
|
|
||||||
should.equal(snapshot.get('foo'), 'bar');
|
should.equal(snapshot.get('foo'), 'bar');
|
||||||
|
@ -81,8 +83,7 @@ describe('firestore()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('using a FieldPath instance', async () => {
|
it('using a FieldPath instance', async () => {
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const snapshot = await testCollectionDoc().get();
|
|
||||||
|
|
||||||
should.equal(snapshot.get('foo'), 'bar');
|
should.equal(snapshot.get('foo'), 'bar');
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
|
const {
|
||||||
|
COL_DOC_1,
|
||||||
|
COL_DOC_1_PATH,
|
||||||
|
testCollectionDoc,
|
||||||
|
resetTestCollectionDoc,
|
||||||
|
} = TestHelpers.firestore;
|
||||||
|
|
||||||
describe('firestore()', () => {
|
describe('firestore()', () => {
|
||||||
describe('FieldPath', () => {
|
describe('FieldPath', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await TestHelpers.firestore.resetTestCollectionDoc();
|
await resetTestCollectionDoc(COL_DOC_1_PATH, COL_DOC_1());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('documentId() should return a FieldPath', () => {
|
it('documentId() should return a FieldPath', () => {
|
||||||
|
@ -10,8 +17,7 @@ describe('firestore()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow getting values via documentSnapshot.get(FieldPath)', async () => {
|
it('should allow getting values via documentSnapshot.get(FieldPath)', async () => {
|
||||||
const { testCollectionDoc } = TestHelpers.firestore;
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
||||||
const snapshot = await testCollectionDoc().get();
|
|
||||||
|
|
||||||
should.equal(snapshot.get('foo'), 'bar');
|
should.equal(snapshot.get('foo'), 'bar');
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue