diff --git a/CHANGELOG.md b/CHANGELOG.md index 729f05d..c0c708c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## Change Log -### upcoming (2017/02/27 15:43 +00:00) +### v1.5.0 (2017/02/27 15:43 +00:00) +- [d5cc0dc](https://github.com/carsdotcom/bitcar/commit/d5cc0dcf588a24ca5afd0737d1aa052f61b8b0ca) 1.5.0 (@machellerogden) +- [05bd8ba](https://github.com/carsdotcom/bitcar/commit/05bd8baf9d1ae38eb1ae76348cfaae11693dd2a4) adding basic editor support (@machellerogden) - [d8cdbb1](https://github.com/carsdotcom/bitcar/commit/d8cdbb10e76f24f63f787c2f7389e093fb508e11) adding test watch (@machellerogden) - [8614f2f](https://github.com/carsdotcom/bitcar/commit/8614f2f04e863d25523338fc24efdfd015d6c1b9) more tests (@machellerogden) - [6cf9aa3](https://github.com/carsdotcom/bitcar/commit/6cf9aa3ac95f76539c3804d9ff9b7dda18b6d0d2) adding tests (@machellerogden) diff --git a/cli.js b/cli.js index ecc0fcc..ca9df70 100644 --- a/cli.js +++ b/cli.js @@ -11,8 +11,30 @@ const refresh = _.partial(lib.getSourceData, true); module.exports = cli; -function cli(options) { +function setSearchTerm(options) { let searchTerm; + if (options._ && options._[0]) { + searchTerm = options._[0]; + } else if (_.isString(options.completions)) { + searchTerm = options.completions; + } else if (_.isString(options.open)) { + searchTerm = options.open; + } else if (_.isString(options.edit)) { + searchTerm = options.edit; + } else if (_.isString(options['clone-all'])) { + searchTerm = options['clone-all']; + } else if (_.isString(options['force-latest'])) { + searchTerm = options['force-latest']; + } else if (options.completions || options['clone-all'] || options['force-latest']) { + searchTerm = '.*'; + } else { + searchTerm = '^' + _.takeRight(process.cwd().split(path.sep), 3).join(path.sep) + '$'; + } + return searchTerm; +} + +function cli(options) { + let searchTerm = setSearchTerm(options); if (options.version) { output.log(require('./package.json').version); @@ -23,26 +45,6 @@ function cli(options) { return require('./setup')(); } - if (_.isString(options.completions)) { - searchTerm = options.completions; - } else if (_.isString(options.open)) { - searchTerm = options.open; - } else if (_.isString(options.edit)) { - searchTerm = options.edit; - } else if (options['clone-all'] || options['force-latest']) { - if (_.isString(options['clone-all'])) { - searchTerm = options['clone-all']; - } else if (_.isString(options['force-latest'])) { - searchTerm = options['force-latest']; - } else { - searchTerm = '.*'; - } - } else if (options._ && options._[0]) { - searchTerm = options._[0]; - } else if (!options.completions) { - searchTerm = '^' + _.takeRight(process.cwd().split(path.sep), 3).join(path.sep) + '$'; - } - if (options.refresh) { return refresh(); } else { diff --git a/test/index.js b/test/index.js index 9d02844..aa6b3a5 100644 --- a/test/index.js +++ b/test/index.js @@ -164,7 +164,7 @@ describe('the bitcar cli', () => { }); describe('for non-existant entry', () => { it('should exit non-zero with a message of "No results."', () => { - return expect(cli({ _: [ 'doesnotexist' ] })).to.eventually.be.rejectedWith('No results.'); + return expect(cli({ _: [ 'doesnotexist' ], edit: true })).to.eventually.be.rejectedWith('No results.'); }); }); }); @@ -183,5 +183,44 @@ describe('the bitcar cli', () => { }); }); }); + describe('completions option', () => { + beforeEach(() => { + sandbox.stub(output, 'log'); + }); + describe('with a search term', () => { + describe('for existing entry', () => { + it('should find existing entry for the search term in the cache - bitcar', () => { + return cli({ _: [ ], completions: 'bitcar' }) + .then((results) => { + const resultsValidation = schemas.results.validate(results); + expect(resultsValidation.error).to.be.a('null'); + }); + }); + it('regardless of order, find existing entry for the search term in the cache - bitcar', () => { + return cli({ _: [ 'bitcar' ], completions: true }) + .then((results) => { + const resultsValidation = schemas.results.validate(results); + expect(resultsValidation.error).to.be.a('null'); + }); + }); + }); + describe('for non-existant entry', () => { + it('should exit non-zero with a message of "No results."', () => { + return expect(cli({ _: [ 'doesnotexist' ], completions: true })).to.eventually.eql([]); + }); + }); + }); + describe('without a search term', () => { + describe('when current working directory corresponds to an entry in the cache', () => { + it('should find existing entry for the search term in the cache - bitcar', () => { + return cli({ _: [ ], completions: true }) + .then((results) => { + const resultsValidation = schemas.results.validate(results); + expect(resultsValidation.error).to.be.a('null'); + }); + }); + }); + }); + }); }); diff --git a/test/schemas.js b/test/schemas.js index 300969f..f3a74b9 100644 --- a/test/schemas.js +++ b/test/schemas.js @@ -22,3 +22,5 @@ exports.result = Joi.object().keys({ html: Joi.string().required(), repoDir: Joi.string().required() }); + +exports.results = Joi.array().items([ Joi.any().allow(null), exports.result ]).min(0);