react-native-firebase/bridge/e2e/firestore/documentSnapshot.e2e.js

110 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-04-13 12:49:03 +00:00
const {
COL_DOC_1,
COL_DOC_1_ID,
COL_DOC_1_PATH,
testCollectionDoc,
resetTestCollectionDoc,
} = TestHelpers.firestore;
2018-04-12 11:56:29 +00:00
describe('firestore()', () => {
describe('DocumentSnapshot', () => {
before(async () => {
2018-04-13 12:49:03 +00:00
await resetTestCollectionDoc(COL_DOC_1_PATH, COL_DOC_1());
});
2018-04-12 17:13:40 +00:00
describe('id', () => {
it('returns a string document id', async () => {
2018-04-13 12:49:03 +00:00
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
2018-04-12 17:13:40 +00:00
snapshot.id.should.be.a.String();
snapshot.id.should.equal(COL_DOC_1_ID);
});
});
2018-04-13 10:04:40 +00:00
describe('ref', () => {
2018-04-12 17:13:40 +00:00
it('returns a DocumentReference', async () => {
2018-04-13 12:49:03 +00:00
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const DocumentReference = bridge.require(
'dist/modules/firestore/DocumentReference'
);
snapshot.ref.should.be.an.instanceOf(DocumentReference);
2018-04-12 17:13:40 +00:00
});
});
describe('metadata', () => {
it('returns an object of meta data', async () => {
2018-04-13 12:49:03 +00:00
const { metadata } = await testCollectionDoc(COL_DOC_1_PATH).get();
metadata.should.be.an.Object();
metadata.should.have.property('hasPendingWrites');
metadata.should.have.property('fromCache');
metadata.hasPendingWrites.should.be.a.Boolean();
metadata.fromCache.should.be.a.Boolean();
});
});
describe('exists', () => {
it('returns a boolean', async () => {
2018-04-13 12:49:03 +00:00
const { exists } = await testCollectionDoc(COL_DOC_1_PATH).get();
exists.should.be.a.Boolean();
exists.should.be.true();
});
});
describe('data()', () => {
it('returns document data', async () => {
// additionally tests context binding not lost during destructuring
2018-04-13 12:49:03 +00:00
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const { data } = snapshot;
snapshot.data.should.be.a.Function();
data.should.be.a.Function();
snapshot.data().should.be.a.Object();
data().should.be.a.Object();
snapshot.data().baz.should.be.true();
data().baz.should.be.true();
});
});
describe('get()', () => {
it('using a dot notated path string', async () => {
// additionally tests context binding not lost during destructuring
2018-04-13 12:49:03 +00:00
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const { get } = snapshot;
should.equal(snapshot.get('foo'), 'bar');
should.equal(get('foo'), 'bar');
should.equal(snapshot.get('object.daz'), 123);
should.equal(get('object.daz'), 123);
should.equal(snapshot.get('nonexistent.object'), undefined);
should.equal(get('nonexistent.object'), undefined);
});
it('using a FieldPath instance', async () => {
2018-04-13 12:49:03 +00:00
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
should.equal(snapshot.get('foo'), 'bar');
should.equal(
snapshot.get(new firebase.firestore.FieldPath('foo')),
'bar'
);
should.equal(
snapshot.get(new firebase.firestore.FieldPath('object', 'daz')),
123
);
should.equal(
snapshot.get(
new firebase.firestore.FieldPath('nonexistent', 'object')
),
undefined
);
});
});
});
});