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()', () => {
|
2018-04-12 11:54:29 +00:00
|
|
|
describe('DocumentSnapshot', () => {
|
|
|
|
before(async () => {
|
2018-04-13 12:49:03 +00:00
|
|
|
await resetTestCollectionDoc(COL_DOC_1_PATH, COL_DOC_1());
|
2018-04-12 11:54:29 +00:00
|
|
|
});
|
|
|
|
|
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();
|
2018-04-13 10:00:42 +00:00
|
|
|
const DocumentReference = bridge.require(
|
2018-04-21 17:59:52 +00:00
|
|
|
'dist/modules/firestore/DocumentReference'
|
2018-04-13 10:00:42 +00:00
|
|
|
);
|
|
|
|
snapshot.ref.should.be.an.instanceOf(DocumentReference);
|
2018-04-12 17:13:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-13 10:50:30 +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();
|
2018-04-13 10:50:30 +00:00
|
|
|
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();
|
2018-04-13 10:50:30 +00:00
|
|
|
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();
|
2018-04-13 10:50:30 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-12 11:54:29 +00:00
|
|
|
describe('get()', () => {
|
|
|
|
it('using a dot notated path string', async () => {
|
2018-04-13 10:50:30 +00:00
|
|
|
// 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();
|
2018-04-13 10:50:30 +00:00
|
|
|
const { get } = snapshot;
|
2018-04-12 11:54:29 +00:00
|
|
|
|
|
|
|
should.equal(snapshot.get('foo'), 'bar');
|
2018-04-13 10:50:30 +00:00
|
|
|
should.equal(get('foo'), 'bar');
|
|
|
|
|
2018-04-12 11:54:29 +00:00
|
|
|
should.equal(snapshot.get('object.daz'), 123);
|
2018-04-13 10:50:30 +00:00
|
|
|
should.equal(get('object.daz'), 123);
|
|
|
|
|
2018-04-12 11:54:29 +00:00
|
|
|
should.equal(snapshot.get('nonexistent.object'), undefined);
|
2018-04-13 10:50:30 +00:00
|
|
|
should.equal(get('nonexistent.object'), undefined);
|
2018-04-12 11:54:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('using a FieldPath instance', async () => {
|
2018-04-13 12:49:03 +00:00
|
|
|
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
|
2018-04-12 11:54:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|