2018-04-16 16:45:45 +00:00
|
|
|
describe('firestore()', () => {
|
|
|
|
describe('Path', () => {
|
|
|
|
describe('id', () => {
|
|
|
|
it('returns the document id', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection/documentId');
|
|
|
|
path.id.should.be.equal('documentId');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null if no path', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('');
|
|
|
|
should.equal(path.id, null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isDocument', () => {
|
|
|
|
it('returns true if path is a document', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection/documentId');
|
|
|
|
path.isDocument.should.be.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false if path is a collection', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection');
|
|
|
|
path.isDocument.should.be.equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isCollection', () => {
|
|
|
|
it('returns true if path is a collection', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection');
|
|
|
|
path.isCollection.should.be.equal(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false if path is a document', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection/documentId');
|
|
|
|
path.isCollection.should.be.equal(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('relativeName', () => {
|
|
|
|
it('returns original full path', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection');
|
|
|
|
const path2 = Path.fromName('collection/documentId');
|
|
|
|
path.relativeName.should.be.equal('collection');
|
|
|
|
path2.relativeName.should.be.equal('collection/documentId');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('child()', () => {
|
|
|
|
it('returns original path joined with the provided child path', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection');
|
|
|
|
const path2 = path.child('documentId');
|
|
|
|
path.relativeName.should.be.equal('collection');
|
|
|
|
path2.relativeName.should.be.equal('collection/documentId');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('parent()', () => {
|
|
|
|
it('returns the parent of the current child path', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection/documentId');
|
|
|
|
const path2 = path.parent();
|
|
|
|
path.relativeName.should.be.equal('collection/documentId');
|
|
|
|
path2.relativeName.should.be.equal('collection');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null if no path', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('');
|
|
|
|
const path2 = path.parent();
|
|
|
|
path._parts.length.should.be.equal(0);
|
|
|
|
should.equal(path2, null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('static fromName()', () => {
|
|
|
|
it('returns a new instance from a / delimited path string', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('collection/document');
|
|
|
|
path.should.be.instanceOf(Path);
|
|
|
|
path._parts.length.should.be.equal(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a new instance from an empty string', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName('');
|
|
|
|
path.should.be.instanceOf(Path);
|
|
|
|
path._parts.length.should.be.equal(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a new instance with no args provided', async () => {
|
2018-04-21 17:59:52 +00:00
|
|
|
const Path = bridge.require('dist/modules/firestore/Path');
|
2018-04-16 16:45:45 +00:00
|
|
|
|
|
|
|
const path = Path.fromName();
|
|
|
|
path.should.be.instanceOf(Path);
|
|
|
|
path._parts.length.should.be.equal(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|