From 7ffa960f9e1c3ad762d86168c76ea0f25e0433ea Mon Sep 17 00:00:00 2001 From: Nick Balestra Date: Thu, 2 Nov 2017 11:55:42 +0000 Subject: [PATCH] src/test/tasks --- src/cli/domain/get-mocked-plugins.js | 5 +- src/cli/domain/registry.js | 6 +- src/registry/domain/authentication.js | 2 +- src/registry/middleware/file-uploads.js | 5 +- .../routes/helpers/get-components-history.js | 16 +- src/registry/routes/index.js | 9 +- src/registry/routes/static-redirector.js | 2 +- src/registry/views/static/component-info.js | 4 +- test/acceptance/registry-ui.js | 29 +- .../registry/registry-with-fallback.js | 91 +++-- test/integration/targz.js | 56 +-- test/unit/cli-domain-get-components-by-dir.js | 87 ++--- test/unit/cli-domain-get-mocked-plugins.js | 71 ++-- test/unit/cli-domain-mock.js | 42 +-- test/unit/cli-domain-registry.js | 250 +++++++------ test/unit/cli-domain-url-parser.js | 27 +- test/unit/cli-facade-mock.js | 14 +- test/unit/cli-facade-package.js | 76 ++-- test/unit/cli-facade-preview.js | 38 +- test/unit/cli-facade-registry-add.js | 5 +- test/unit/cli-facade-registry-ls.js | 17 +- test/unit/cli-facade-registry-remove.js | 7 +- test/unit/cli-validate-command.js | 8 +- test/unit/registry-domain-events-handler.js | 19 +- test/unit/registry-domain-extract-package.js | 84 +++-- test/unit/registry-domain-nested-renderer.js | 319 +++++++++-------- .../registry-domain-plugins-initialiser.js | 332 +++++++++--------- test/unit/registry-domain-require-wrapper.js | 16 +- test/unit/registry-domain-sanitiser.js | 42 ++- test/unit/registry-domain-url-builder.js | 74 ++-- test/unit/registry-domain-version-handler.js | 36 +- ...try-routes-helpers-apply-default-values.js | 59 +++- ...utes-helpers-get-available-dependencies.js | 46 +-- ...y-routes-helpers-get-components-history.js | 10 +- ...stry-routes-helpers-is-url-discoverable.js | 51 +-- test/unit/registry.js | 71 ++-- test/unit/utils-date-stringify.js | 1 - test/unit/utils-get-file-info.js | 1 - test/unit/utils-pad-zero.js | 1 - 39 files changed, 1151 insertions(+), 878 deletions(-) diff --git a/src/cli/domain/get-mocked-plugins.js b/src/cli/domain/get-mocked-plugins.js index fe9c1cb1c..bd3460420 100644 --- a/src/cli/domain/get-mocked-plugins.js +++ b/src/cli/domain/get-mocked-plugins.js @@ -62,7 +62,10 @@ const findPath = function(pathToResolve, fileName) { return undefined; } else { const getParent = function(x) { - return x.split('/').slice(0, -1).join('/'); + return x + .split('/') + .slice(0, -1) + .join('/'); }, parentDir = pathToResolve ? getParent(pathToResolve) : rootDir; diff --git a/src/cli/domain/registry.js b/src/cli/domain/registry.js index 619bf5e20..70ff78015 100644 --- a/src/cli/domain/registry.js +++ b/src/cli/domain/registry.js @@ -116,9 +116,9 @@ module.exports = function(opts) { requestsHeaders = _.extend(requestsHeaders, { Authorization: 'Basic ' + - new Buffer(options.username + ':' + options.password).toString( - 'base64' - ) + new Buffer(options.username + ':' + options.password).toString( + 'base64' + ) }); } diff --git a/src/registry/domain/authentication.js b/src/registry/domain/authentication.js index 65ca9745d..20455c6ef 100644 --- a/src/registry/domain/authentication.js +++ b/src/registry/domain/authentication.js @@ -15,7 +15,7 @@ const builtin = { message: isValid ? '' : strings.errors.registry - .CONFIGURATION_PUBLISH_BASIC_AUTH_CREDENTIALS_MISSING + .CONFIGURATION_PUBLISH_BASIC_AUTH_CREDENTIALS_MISSING }; }, middleware: function(authConfig) { diff --git a/src/registry/middleware/file-uploads.js b/src/registry/middleware/file-uploads.js index 3dd96ae33..a2212ee52 100644 --- a/src/registry/middleware/file-uploads.js +++ b/src/registry/middleware/file-uploads.js @@ -8,7 +8,10 @@ module.exports = function(req, res, next) { } const normaliseFileName = x => - x.replace('.tar.gz', '').replace(/\W+/g, '-').toLowerCase(); + x + .replace('.tar.gz', '') + .replace(/\W+/g, '-') + .toLowerCase(); const upload = multer({ limits: { diff --git a/src/registry/routes/helpers/get-components-history.js b/src/registry/routes/helpers/get-components-history.js index 6b32cc1ec..3d30d0a20 100644 --- a/src/registry/routes/helpers/get-components-history.js +++ b/src/registry/routes/helpers/get-components-history.js @@ -17,11 +17,13 @@ module.exports = history => { }); }); - return _.sortBy(result, 'publishDate').reverse().map(x => ({ - name: x.name, - version: x.version, - publishDate: !x.publishDate - ? 'Unknown' - : dateStringified(new Date(x.publishDate)) - })); + return _.sortBy(result, 'publishDate') + .reverse() + .map(x => ({ + name: x.name, + version: x.version, + publishDate: !x.publishDate + ? 'Unknown' + : dateStringified(new Date(x.publishDate)) + })); }; diff --git a/src/registry/routes/index.js b/src/registry/routes/index.js index 71fe4fc8f..a85d19722 100644 --- a/src/registry/routes/index.js +++ b/src/registry/routes/index.js @@ -18,7 +18,7 @@ module.exports = function(repository) { } const isHtmlRequest = - !!req.headers.accept && req.headers.accept.indexOf('text/html') >= 0, + !!req.headers.accept && req.headers.accept.indexOf('text/html') >= 0, baseResponse = { href: res.conf.baseUrl, ocVersion: packageInfo.version, @@ -66,9 +66,10 @@ module.exports = function(repository) { components: componentsInfo, componentsReleases, componentsList: _.map(componentsInfo, component => { - const state = !!component.oc && !!component.oc.state - ? component.oc.state - : ''; + const state = + !!component.oc && !!component.oc.state + ? component.oc.state + : ''; if (state) { stateCounts[state] = stateCounts[state] || 0; diff --git a/src/registry/routes/static-redirector.js b/src/registry/routes/static-redirector.js index 8186be428..fca9dc219 100644 --- a/src/registry/routes/static-redirector.js +++ b/src/registry/routes/static-redirector.js @@ -10,7 +10,7 @@ module.exports = function(repository) { return function(req, res) { let filePath; const clientPath = - (res.conf.prefix ? res.conf.prefix : '/') + 'oc-client/client.js', + (res.conf.prefix ? res.conf.prefix : '/') + 'oc-client/client.js', clientMapPath = (res.conf.prefix ? res.conf.prefix : '/') + 'oc-client/oc-client.min.map'; diff --git a/src/registry/views/static/component-info.js b/src/registry/views/static/component-info.js index f1f18ba63..38609b39f 100644 --- a/src/registry/views/static/component-info.js +++ b/src/registry/views/static/component-info.js @@ -11,7 +11,9 @@ oc.cmd.push(function() { }); $('.refresh-preview').click(function() { - var splitted = $('#href').val().split('?'), + var splitted = $('#href') + .val() + .split('?'), url = splitted[0], lang = $('#lang').val(); diff --git a/test/acceptance/registry-ui.js b/test/acceptance/registry-ui.js index 713e6d962..b93e489f4 100644 --- a/test/acceptance/registry-ui.js +++ b/test/acceptance/registry-ui.js @@ -6,10 +6,9 @@ const path = require('path'); const request = require('minimal-request'); describe('registry (ui interface)', () => { - let registry, result, error, headers; - const next = (done) => (e, r, d) => { + const next = done => (e, r, d) => { error = e; result = r; headers = d.response.headers; @@ -37,11 +36,14 @@ describe('registry (ui interface)', () => { after(done => registry.close(done)); describe('GET / with Accept: text/html', () => { - before((done) => { - request({ - url: 'http://localhost:3030', - headers: { accept: 'text/html' } - }, next(done)); + before(done => { + request( + { + url: 'http://localhost:3030', + headers: { accept: 'text/html' } + }, + next(done) + ); }); it('should not error', () => { @@ -55,11 +57,14 @@ describe('registry (ui interface)', () => { }); describe('GET /oc-client/~info with Accept: text/html', () => { - before((done) => { - request({ - url: 'http://localhost:3030/oc-client/~info', - headers: { accept: 'text/html' } - }, next(done)); + before(done => { + request( + { + url: 'http://localhost:3030/oc-client/~info', + headers: { accept: 'text/html' } + }, + next(done) + ); }); it('should not error', () => { diff --git a/test/acceptance/registry/registry-with-fallback.js b/test/acceptance/registry/registry-with-fallback.js index ebcc05a1e..65c713897 100644 --- a/test/acceptance/registry/registry-with-fallback.js +++ b/test/acceptance/registry/registry-with-fallback.js @@ -11,7 +11,11 @@ describe('registry', () => { let registry; let result; - function retrieveRegistryConfiguration(port, pathToComponents, fallbackRegistryUrl){ + function retrieveRegistryConfiguration( + port, + pathToComponents, + fallbackRegistryUrl + ) { return { local: true, path: path.resolve(pathToComponents), @@ -24,34 +28,47 @@ describe('registry', () => { }; } - function next(done){ - return function(e, r){ + function next(done) { + return function(e, r) { result = r; done(); }; } - before((done) => { - registry = new oc.Registry(retrieveRegistryConfiguration(3030, 'test/fixtures/components', 'http://localhost:3031')); - fallbackRegistry = new oc.Registry(retrieveRegistryConfiguration(3031, 'test/fixtures/fallback-registry-components')); + before(done => { + registry = new oc.Registry( + retrieveRegistryConfiguration( + 3030, + 'test/fixtures/components', + 'http://localhost:3031' + ) + ); + fallbackRegistry = new oc.Registry( + retrieveRegistryConfiguration( + 3031, + 'test/fixtures/fallback-registry-components' + ) + ); registry.start(() => { fallbackRegistry.start(done); }); }); - after((done) => { + after(done => { registry.close(() => { fallbackRegistry.close(done); }); }); describe('GET /welcome', () => { - - before((done) => { - request({ - url: 'http://localhost:3030/welcome', - json: true - }, next(done)); + before(done => { + request( + { + url: 'http://localhost:3030/welcome', + json: true + }, + next(done) + ); }); it('should respond with the local registry url', () => { @@ -64,16 +81,20 @@ describe('registry', () => { }); describe('GET /fallback-hello-world', () => { - - before((done) => { - request({ - url: 'http://localhost:3030/fallback-hello-world', - json: true - }, next(done)); + before(done => { + request( + { + url: 'http://localhost:3030/fallback-hello-world', + json: true + }, + next(done) + ); }); it('should respond with the fallback registry url', () => { - expect(result.href).to.eql('http://localhost:3031/fallback-hello-world'); + expect(result.href).to.eql( + 'http://localhost:3031/fallback-hello-world' + ); }); it('should respond the `Hello world!` html', () => { @@ -82,12 +103,15 @@ describe('registry', () => { }); describe('GET /fallback-hello-world/~info', () => { - - before((done) => { - request({ - url: 'http://localhost:3030/fallback-welcome-with-optional-parameters/~info', - json: true - }, next(done)); + before(done => { + request( + { + url: + 'http://localhost:3030/fallback-welcome-with-optional-parameters/~info', + json: true + }, + next(done) + ); }); it('should respond with requested component', () => { @@ -100,12 +124,15 @@ describe('registry', () => { }); describe('GET /fallback-hello-world/~preview', () => { - - before((done) => { - request({ - url: 'http://localhost:3030/fallback-welcome-with-optional-parameters/~preview', - json: true - }, next(done)); + before(done => { + request( + { + url: + 'http://localhost:3030/fallback-welcome-with-optional-parameters/~preview', + json: true + }, + next(done) + ); }); it('should respond with requested component', () => { diff --git a/test/integration/targz.js b/test/integration/targz.js index 5aa557013..2cc52284d 100644 --- a/test/integration/targz.js +++ b/test/integration/targz.js @@ -7,24 +7,28 @@ const targz = require('targz'); const _ = require('lodash'); describe('The targz dependency', () => { - describe('when compressing a folder with targz', () => { - const file = path.resolve(__dirname, '../fixtures/test.tar.gz'); - beforeEach((done) => { - const from = path.resolve(__dirname, '../fixtures/components/hello-world'); - targz.compress({ - src: from, - dest: file, - tar: { - map: function(fileName) { - return _.extend(fileName, { - name: 'hello-world/' + fileName.name - }); + beforeEach(done => { + const from = path.resolve( + __dirname, + '../fixtures/components/hello-world' + ); + targz.compress( + { + src: from, + dest: file, + tar: { + map: function(fileName) { + return _.extend(fileName, { + name: 'hello-world/' + fileName.name + }); + } } - } - }, done); + }, + done + ); }); it('should create the file', () => { @@ -32,18 +36,20 @@ describe('The targz dependency', () => { }); describe('when decompressing the created file', () => { - let error; const to = path.resolve(__dirname, '../fixtures/targz-test'); - beforeEach((done) => { - targz.decompress({ - src: file, - dest: to - }, (err) => { - error = err; - done(); - }); + beforeEach(done => { + targz.decompress( + { + src: file, + dest: to + }, + err => { + error = err; + done(); + } + ); }); it('should throw no error', () => { @@ -52,7 +58,9 @@ describe('The targz dependency', () => { it('should contain the files', () => { expect(fs.existsSync(to)).to.be.true; - expect(fs.readFileSync(path.join(to, 'hello-world/template.html')).toString()).to.be.equal('Hello world!'); + expect( + fs.readFileSync(path.join(to, 'hello-world/template.html')).toString() + ).to.be.equal('Hello world!'); }); }); }); diff --git a/test/unit/cli-domain-get-components-by-dir.js b/test/unit/cli-domain-get-components-by-dir.js index 689c317cd..5a8c604d7 100644 --- a/test/unit/cli-domain-get-components-by-dir.js +++ b/test/unit/cli-domain-get-components-by-dir.js @@ -6,8 +6,7 @@ const path = require('path'); const sinon = require('sinon'); const _ = require('lodash'); -const initialise = function(){ - +const initialise = function() { const fsMock = { readdirSync: sinon.stub(), readJsonSync: sinon.stub() @@ -16,46 +15,53 @@ const initialise = function(){ const pathMock = { extname: path.extname, join: path.join, - resolve: function(){ + resolve: function() { return _.toArray(arguments).join('/'); } }; - const GetComponentsByDir = injectr('../../src/cli/domain/get-components-by-dir.js', { - 'fs-extra': fsMock, - path: pathMock - }, { __dirname: '' }); + const GetComponentsByDir = injectr( + '../../src/cli/domain/get-components-by-dir.js', + { + 'fs-extra': fsMock, + path: pathMock + }, + { __dirname: '' } + ); const local = new GetComponentsByDir(); return { local: local, fs: fsMock }; }; -const executeComponentsListingByDir = function(local, callback){ +const executeComponentsListingByDir = function(local, callback) { return local('.', callback); }; describe('cli : domain : get-components-by-dir', () => { - describe('when getting components from dir', () => { - let error, result; - beforeEach((done) => { - + beforeEach(done => { const data = initialise(); - data.fs.readdirSync.onCall(0).returns([ - 'a-component', - 'a-not-component-dir', - 'a-file.json', - '_package', - 'no-component-but-package-json' - ]); - - data.fs.readJsonSync.onCall(0).returns({ oc: {}}); - data.fs.readJsonSync.onCall(1).throws(new Error('ENOENT: no such file or directory')); - data.fs.readJsonSync.onCall(2).throws(new Error('ENOENT: no such file or directory')); - data.fs.readJsonSync.onCall(3).returns({ oc: { packaged: true }}); + data.fs.readdirSync + .onCall(0) + .returns([ + 'a-component', + 'a-not-component-dir', + 'a-file.json', + '_package', + 'no-component-but-package-json' + ]); + + data.fs.readJsonSync.onCall(0).returns({ oc: {} }); + data.fs.readJsonSync + .onCall(1) + .throws(new Error('ENOENT: no such file or directory')); + data.fs.readJsonSync + .onCall(2) + .throws(new Error('ENOENT: no such file or directory')); + data.fs.readJsonSync.onCall(3).returns({ oc: { packaged: true } }); data.fs.readJsonSync.onCall(4).returns({}); executeComponentsListingByDir(data.local, (err, res) => { @@ -75,19 +81,16 @@ describe('cli : domain : get-components-by-dir', () => { }); describe('when reading a broken package.json', () => { - let error, result; - beforeEach((done) => { - + beforeEach(done => { const data = initialise(); - data.fs.readdirSync.onCall(0).returns([ - 'a-broken-component', - 'another-component' - ]); + data.fs.readdirSync + .onCall(0) + .returns(['a-broken-component', 'another-component']); data.fs.readJsonSync.onCall(0).throws(new Error('syntax error: fubar')); - data.fs.readJsonSync.onCall(1).returns({ oc: { }}); + data.fs.readJsonSync.onCall(1).returns({ oc: {} }); executeComponentsListingByDir(data.local, (err, res) => { error = err; @@ -106,21 +109,21 @@ describe('cli : domain : get-components-by-dir', () => { }); describe('when finds no components', () => { - let error, result; - beforeEach((done) => { - + beforeEach(done => { const data = initialise(); - data.fs.readdirSync.onCall(0).returns([ - 'a-broken-component', - 'not-a-component-dir', - 'file.json' - ]); + data.fs.readdirSync + .onCall(0) + .returns(['a-broken-component', 'not-a-component-dir', 'file.json']); data.fs.readJsonSync.onCall(0).throws(new Error('syntax error: fubar')); - data.fs.readJsonSync.onCall(1).throws(new Error('ENOENT: no such file or directory')); - data.fs.readJsonSync.onCall(2).throws(new Error('ENOENT: no such file or directory')); + data.fs.readJsonSync + .onCall(1) + .throws(new Error('ENOENT: no such file or directory')); + data.fs.readJsonSync + .onCall(2) + .throws(new Error('ENOENT: no such file or directory')); executeComponentsListingByDir(data.local, (err, res) => { error = err; diff --git a/test/unit/cli-domain-get-mocked-plugins.js b/test/unit/cli-domain-get-mocked-plugins.js index 6f758ce9f..49b41ad22 100644 --- a/test/unit/cli-domain-get-mocked-plugins.js +++ b/test/unit/cli-domain-get-mocked-plugins.js @@ -6,27 +6,29 @@ const sinon = require('sinon'); const _ = require('lodash'); describe('cli : domain : get-mocked-plugins', () => { + const dynamicPluginModule = function(a) { + return a ? 'blarg' : 'flarg'; + }, + notAFunctionModule = { foo: 'bar' }; + + let fsMock, getMockedPlugins; + + const initialise = function(fs, pathJoinStub) { + fsMock = _.extend( + { + existsSync: sinon.stub().returns(true), + readFileSync: sinon.stub().returns('file content'), + readJsonSync: sinon.stub().returns({ content: true }), + realpathSync: sinon.stub().returns('/root/'), + writeFile: sinon.stub().yields(null, 'ok') + }, + fs || {} + ); - const dynamicPluginModule = function(a){ return a ? 'blarg' : 'flarg'; }, - notAFunctionModule = { 'foo' : 'bar' }; - - let fsMock, - getMockedPlugins; - - const initialise = function(fs, pathJoinStub){ - - fsMock = _.extend({ - existsSync: sinon.stub().returns(true), - readFileSync: sinon.stub().returns('file content'), - readJsonSync: sinon.stub().returns({ content: true }), - realpathSync: sinon.stub().returns('/root/'), - writeFile: sinon.stub().yields(null, 'ok') - }, fs || {}); - - const fakePathFunc = function(){ + const fakePathFunc = function() { return _.toArray(arguments) - .map((x) => x.replace(/\.\//g, '')) - .join(''); + .map(x => x.replace(/\.\//g, '')) + .join(''); }; getMockedPlugins = injectr('../../src/cli/domain/get-mocked-plugins.js', { @@ -41,9 +43,7 @@ describe('cli : domain : get-mocked-plugins', () => { }; describe('when setting up mocked plugins', () => { - describe('when componentsDir parameter is undefined', () => { - const joinStub = sinon.stub(); beforeEach(() => { @@ -57,7 +57,6 @@ describe('cli : domain : get-mocked-plugins', () => { }); describe('when componentsDir parameter is omitted', () => { - const joinStub = sinon.stub(); beforeEach(() => { @@ -71,7 +70,6 @@ describe('cli : domain : get-mocked-plugins', () => { }); describe('when oc.json is in both root and component folder', () => { - let result; const ocJsonComponent = { registries: [], @@ -89,7 +87,10 @@ describe('cli : domain : get-mocked-plugins', () => { existsSync: sinon.stub().returns(true), readJsonSync: readMock }); - result = getMockedPlugins({ log: () => {}, warn: () => {} }, '/root/components/'); + result = getMockedPlugins( + { log: () => {}, warn: () => {} }, + '/root/components/' + ); }); it('should use components folder oc.json as default', () => { @@ -100,7 +101,6 @@ describe('cli : domain : get-mocked-plugins', () => { }); describe('when oc.json is in root folder', () => { - let result; const ocJsonComponent = { registries: [], @@ -133,7 +133,10 @@ describe('cli : domain : get-mocked-plugins', () => { existsSync: existsMock, readJsonSync: readMock }); - result = getMockedPlugins({ log: () => {}, warn: () => {} }, '/root/components/'); + result = getMockedPlugins( + { log: () => {}, warn: () => {} }, + '/root/components/' + ); }); it('should use root oc.json', () => { @@ -193,7 +196,10 @@ describe('cli : domain : get-mocked-plugins', () => { existsSync: sinon.stub().returns(true), readJsonSync: sinon.stub().returns(ocJson) }); - result = getMockedPlugins({ log: () => {}, warn: () => {} }, '/root/components/'); + result = getMockedPlugins( + { log: () => {}, warn: () => {} }, + '/root/components/' + ); }); it('should return the static plugin', () => { @@ -224,7 +230,10 @@ describe('cli : domain : get-mocked-plugins', () => { existsSync: sinon.stub().returns(true), readJsonSync: sinon.stub().returns(ocJson) }); - result = getMockedPlugins({ log: () => {}, warn: () => {} }, '/root/components/'); + result = getMockedPlugins( + { log: () => {}, warn: () => {} }, + '/root/components/' + ); }); it('should return the dynamic plugin', () => { @@ -262,8 +271,7 @@ describe('cli : domain : get-mocked-plugins', () => { }); it('should log an error', () => { - expect(logger.err.args[0][0]).to.contain( - 'Error: Cannot find module'); + expect(logger.err.args[0][0]).to.contain('Error: Cannot find module'); }); it('should omit the broken plugin from the results', () => { @@ -296,7 +304,8 @@ describe('cli : domain : get-mocked-plugins', () => { it('should log an error', () => { expect(logger.err.args[0][0]).to.contain( - 'Looks like you are trying to register a dynamic mock plugin but the file you specified is not a function'); + 'Looks like you are trying to register a dynamic mock plugin but the file you specified is not a function' + ); }); it('should omit the broken plugin from the results', () => { diff --git a/test/unit/cli-domain-mock.js b/test/unit/cli-domain-mock.js index 23ae4c8fc..7a70c166f 100644 --- a/test/unit/cli-domain-mock.js +++ b/test/unit/cli-domain-mock.js @@ -6,8 +6,7 @@ const path = require('path'); const sinon = require('sinon'); const _ = require('lodash'); -const initialise = function(){ - +const initialise = function() { const fsMock = { existsSync: sinon.stub(), lstatSync: sinon.stub(), @@ -23,35 +22,40 @@ const initialise = function(){ const pathMock = { extname: path.extname, join: path.join, - resolve: function(){ + resolve: function() { return _.toArray(arguments).join('/'); } }; - const Local = injectr('../../src/cli/domain/mock.js', { - 'fs-extra': fsMock, - path: pathMock - }, { __dirname: '' }); + const Local = injectr( + '../../src/cli/domain/mock.js', + { + 'fs-extra': fsMock, + path: pathMock + }, + { __dirname: '' } + ); const local = new Local(); return { local: local, fs: fsMock }; }; -const executeMocking = function(local, type, name, value, cb){ - return local({ - targetType: type, - targetName: name, - targetValue: value - }, cb); +const executeMocking = function(local, type, name, value, cb) { + return local( + { + targetType: type, + targetName: name, + targetValue: value + }, + cb + ); }; describe('cli : domain : mock', () => { - describe('when mocking a static plugin', () => { - let data; - beforeEach((done) => { + beforeEach(done => { data = initialise(); data.fs.readJson.yields(null, { something: 'hello' }); @@ -76,9 +80,8 @@ describe('cli : domain : mock', () => { }); describe('when mocking a static plugin using a bool value', () => { - let data; - beforeEach((done) => { + beforeEach(done => { data = initialise(); data.fs.readJson.yields(null, { something: 'hello' }); @@ -103,9 +106,8 @@ describe('cli : domain : mock', () => { }); describe('when mocking a dynamic plugin', () => { - let data; - beforeEach((done) => { + beforeEach(done => { data = initialise(); data.fs.readJson.yields(null, { something: 'hello' }); diff --git a/test/unit/cli-domain-registry.js b/test/unit/cli-domain-registry.js index e00fea58a..1047c98f8 100644 --- a/test/unit/cli-domain-registry.js +++ b/test/unit/cli-domain-registry.js @@ -4,36 +4,41 @@ const expect = require('chai').expect; const injectr = require('injectr'); const sinon = require('sinon'); -const getRegistry = function(dependencies, opts){ +const getRegistry = function(dependencies, opts) { dependencies.fs = dependencies.fs || {}; dependencies.fs.readJsonSync = sinon.stub().returns({ version: '1.2.3' }); - const Registry = injectr('../../src/cli/domain/registry.js', { - 'minimal-request': dependencies.request, - 'fs-extra': dependencies.fs, - '../../utils/put': dependencies.put, - '../domain/url-parser': dependencies.urlParser, - path: { - join: sinon.stub().returns('/hello/world') + const Registry = injectr( + '../../src/cli/domain/registry.js', + { + 'minimal-request': dependencies.request, + 'fs-extra': dependencies.fs, + '../../utils/put': dependencies.put, + '../domain/url-parser': dependencies.urlParser, + path: { + join: sinon.stub().returns('/hello/world') + } + }, + { + Buffer: Buffer, + __dirname: '/hello', + process: { + arch: 'x64', + platform: 'darwin', + version: 'v0.10.35' + } } - }, { - Buffer: Buffer, - __dirname: '/hello', - process: { - arch: 'x64', - platform: 'darwin', - version: 'v0.10.35' - } - }); + ); return new Registry(opts); }; describe('cli : domain : registry', () => { - describe('registry specified at runtime', () => { - it('should use the registry specified', () => { - const registry = getRegistry({}, { registry: 'http://myotherregistry.com'}); + const registry = getRegistry( + {}, + { registry: 'http://myotherregistry.com' } + ); registry.get((err, registries) => { expect(registries[0]).to.eql('http://myotherregistry.com'); @@ -42,16 +47,16 @@ describe('cli : domain : registry', () => { }); describe('when adding registry', () => { - describe('when registry does not end with "/"', () => { - - it('should append the slash when doing the request', (done) => { + it('should append the slash when doing the request', done => { const requestStub = sinon.stub(); requestStub.yields('err'); const registry = getRegistry({ request: requestStub }); registry.add('http://some-api.com/asd', () => { - expect(requestStub.getCall(0).args[0].url).to.eql('http://some-api.com/asd/'); + expect(requestStub.getCall(0).args[0].url).to.eql( + 'http://some-api.com/asd/' + ); done(); }); }); @@ -79,14 +84,18 @@ describe('cli : domain : registry', () => { }); describe('when publishing to registry', () => { - describe('when no credentials used', () => { - let args, putSpy; beforeEach(() => { putSpy = sinon.spy(); const registry = getRegistry({ put: putSpy }); - registry.putComponent({ route: 'http://registry.com/component/1.0.0', path: '/blabla/path' }, () => {}); + registry.putComponent( + { + route: 'http://registry.com/component/1.0.0', + path: '/blabla/path' + }, + () => {} + ); args = putSpy.args[0]; }); @@ -98,22 +107,26 @@ describe('cli : domain : registry', () => { }); it('should do the request with user-agent including cli version and node details', () => { - expect(args[2]['user-agent']).to.equal('oc-cli-1.2.3/v0.10.35-darwin-x64'); + expect(args[2]['user-agent']).to.equal( + 'oc-cli-1.2.3/v0.10.35-darwin-x64' + ); }); }); describe('when credentials used', () => { - let args, putSpy; beforeEach(() => { putSpy = sinon.spy(); const registry = getRegistry({ put: putSpy }); - registry.putComponent({ - route: 'http://registry.com/component/1.0.0', - path: '/blabla/path', - username: 'johndoe', - password: 'aPassw0rd' - }, () => {}); + registry.putComponent( + { + route: 'http://registry.com/component/1.0.0', + path: '/blabla/path', + username: 'johndoe', + password: 'aPassw0rd' + }, + () => {} + ); args = putSpy.args[0]; }); @@ -121,19 +134,22 @@ describe('cli : domain : registry', () => { expect(putSpy.called).to.be.true; expect(args[0]).to.eql('http://registry.com/component/1.0.0'); expect(args[1]).to.eql('/blabla/path'); - expect(args[2]['Authorization']).to.eql('Basic am9obmRvZTphUGFzc3cwcmQ='); + expect(args[2]['Authorization']).to.eql( + 'Basic am9obmRvZTphUGFzc3cwcmQ=' + ); }); it('should do the request with user-agent including cli version and node details', () => { - expect(args[2]['user-agent']).to.equal('oc-cli-1.2.3/v0.10.35-darwin-x64'); + expect(args[2]['user-agent']).to.equal( + 'oc-cli-1.2.3/v0.10.35-darwin-x64' + ); }); }); }); describe('when getting preview url', () => { - let err, res; - const execute = function(href, error, parsed, done){ + const execute = function(href, error, parsed, done) { const registry = getRegistry({ request: sinon.stub().yields(error, parsed), urlParser: { @@ -148,8 +164,13 @@ describe('cli : domain : registry', () => { }; describe('when href not valid', () => { - beforeEach((done) => { - execute('http://registry.com/not-existing-component', '404!!!', {}, done); + beforeEach(done => { + execute( + 'http://registry.com/not-existing-component', + '404!!!', + {}, + done + ); }); it('should show error message', () => { @@ -158,14 +179,19 @@ describe('cli : domain : registry', () => { }); describe('when href = /component', () => { - beforeEach((done) => { - execute('http://registry.com/component', null, { - href: 'http://registry.com/component', - registryUrl: 'http://registry.com/', - name: 'component', - version: '', - parameters: {} - }, done); + beforeEach(done => { + execute( + 'http://registry.com/component', + null, + { + href: 'http://registry.com/component', + registryUrl: 'http://registry.com/', + name: 'component', + version: '', + parameters: {} + }, + done + ); }); it('href should be /component/~preview/', () => { @@ -174,15 +200,19 @@ describe('cli : domain : registry', () => { }); describe('when href = /component/1.X.X', () => { - - beforeEach((done) => { - execute('http://registry.com/component/1.X.X', null, { - href: 'http://registry.com/component/1.X.X', - registryUrl: 'http://registry.com/', - name: 'component', - version: '1.X.X', - parameters: {} - }, done); + beforeEach(done => { + execute( + 'http://registry.com/component/1.X.X', + null, + { + href: 'http://registry.com/component/1.X.X', + registryUrl: 'http://registry.com/', + name: 'component', + version: '1.X.X', + parameters: {} + }, + done + ); }); it('href should be /component/1.X.X/~preview/', () => { @@ -191,70 +221,94 @@ describe('cli : domain : registry', () => { }); describe('when href = /component?hello=world', () => { - - beforeEach((done) => { - execute('http://registry.com/component?hello=world', null, { - href: 'http://registry.com/component?hello=world', - registryUrl: 'http://registry.com/', - name: 'component', - version: '', - parameters: {hello: 'world'} - }, done); + beforeEach(done => { + execute( + 'http://registry.com/component?hello=world', + null, + { + href: 'http://registry.com/component?hello=world', + registryUrl: 'http://registry.com/', + name: 'component', + version: '', + parameters: { hello: 'world' } + }, + done + ); }); it('href should be /component/~preview/?hello=world', () => { - expect(res).to.equal('http://registry.com/component/~preview/?hello=world'); + expect(res).to.equal( + 'http://registry.com/component/~preview/?hello=world' + ); }); }); describe('when href = /component/?hello=world', () => { - - beforeEach((done) => { - execute('http://registry.com/component/?hello=world', null, { - href: 'http://registry.com/component/?hello=world', - registryUrl: 'http://registry.com/', - name: 'component', - version: '', - parameters: {hello: 'world'} - }, done); + beforeEach(done => { + execute( + 'http://registry.com/component/?hello=world', + null, + { + href: 'http://registry.com/component/?hello=world', + registryUrl: 'http://registry.com/', + name: 'component', + version: '', + parameters: { hello: 'world' } + }, + done + ); }); it('href should be /component/~preview/?hello=world', () => { - expect(res).to.equal('http://registry.com/component/~preview/?hello=world'); + expect(res).to.equal( + 'http://registry.com/component/~preview/?hello=world' + ); }); }); describe('when href = /component/1.X.X?hello=world', () => { - - beforeEach((done) => { - execute('http://registry.com/component/1.X.X?hello=world', null, { - href: 'http://registry.com/component/1.X.X?hello=world', - registryUrl: 'http://registry.com/', - name: 'component', - version: '1.X.X', - parameters: {hello: 'world'} - }, done); + beforeEach(done => { + execute( + 'http://registry.com/component/1.X.X?hello=world', + null, + { + href: 'http://registry.com/component/1.X.X?hello=world', + registryUrl: 'http://registry.com/', + name: 'component', + version: '1.X.X', + parameters: { hello: 'world' } + }, + done + ); }); it('href should be /component/1.X.X/~preview/?hello=world', () => { - expect(res).to.equal('http://registry.com/component/1.X.X/~preview/?hello=world'); + expect(res).to.equal( + 'http://registry.com/component/1.X.X/~preview/?hello=world' + ); }); }); describe('when href = /component/1.X.X/?hello=world', () => { - - beforeEach((done) => { - execute('http://registry.com/component/1.X.X/?hello=world', null, { - href: 'http://registry.com/component/1.X.X/?hello=world', - registryUrl: 'http://registry.com/', - name: 'component', - version: '1.X.X', - parameters: {hello: 'world'} - }, done); + beforeEach(done => { + execute( + 'http://registry.com/component/1.X.X/?hello=world', + null, + { + href: 'http://registry.com/component/1.X.X/?hello=world', + registryUrl: 'http://registry.com/', + name: 'component', + version: '1.X.X', + parameters: { hello: 'world' } + }, + done + ); }); it('href should be /component/1.X.X/~preview/?hello=world', () => { - expect(res).to.equal('http://registry.com/component/1.X.X/~preview/?hello=world'); + expect(res).to.equal( + 'http://registry.com/component/1.X.X/~preview/?hello=world' + ); }); }); }); diff --git a/test/unit/cli-domain-url-parser.js b/test/unit/cli-domain-url-parser.js index c5656e964..ca41c53f2 100644 --- a/test/unit/cli-domain-url-parser.js +++ b/test/unit/cli-domain-url-parser.js @@ -3,9 +3,8 @@ const expect = require('chai').expect; describe('cli : domain : url-parser', () => { - let parsed; - const execute = function(url, returnVersion){ + const execute = function(url, returnVersion) { const urlParser = require('../../src/cli/domain/url-parser'); parsed = urlParser.parse({ @@ -15,7 +14,6 @@ describe('cli : domain : url-parser', () => { }; describe('when parsing http://www.registry.com/api/v2/component-name', () => { - before(() => { execute('http://www.registry.com/api/v2/component-name', ''); }); @@ -37,14 +35,18 @@ describe('cli : domain : url-parser', () => { }); it('clientHref should be http://www.registry.com/api/v2/oc-client/client.js', () => { - expect(parsed.clientHref).to.equal('http://www.registry.com/api/v2/oc-client/client.js'); + expect(parsed.clientHref).to.equal( + 'http://www.registry.com/api/v2/oc-client/client.js' + ); }); }); describe('when parsing http://www.registry.com/component-name/~1.0.0/?hello=world', () => { - before(() => { - execute('http://www.registry.com/component-name/~1.0.0/?hello=world', '~1.0.0'); + execute( + 'http://www.registry.com/component-name/~1.0.0/?hello=world', + '~1.0.0' + ); }); it('name should be component-name', () => { @@ -59,17 +61,18 @@ describe('cli : domain : url-parser', () => { expect(parsed.registryUrl).to.equal('http://www.registry.com/'); }); - it('parameters should be { hello: \'world\'}', () => { + it("parameters should be { hello: 'world'}", () => { expect(parsed.parameters).to.eql({ hello: 'world' }); }); it('clientHref should be http://www.registry.com/oc-client/client.js', () => { - expect(parsed.clientHref).to.equal('http://www.registry.com/oc-client/client.js'); + expect(parsed.clientHref).to.equal( + 'http://www.registry.com/oc-client/client.js' + ); }); }); describe('when parsing http://www.registry.com/12345/~1.0.0?hello=world', () => { - before(() => { execute('http://www.registry.com/12345/~1.0.0?hello=world', '~1.0.0'); }); @@ -86,12 +89,14 @@ describe('cli : domain : url-parser', () => { expect(parsed.registryUrl).to.equal('http://www.registry.com/'); }); - it('parameters should be { hello: \'world\'}', () => { + it("parameters should be { hello: 'world'}", () => { expect(parsed.parameters).to.eql({ hello: 'world' }); }); it('clientHref should be http://www.registry.com/oc-client/client.js', () => { - expect(parsed.clientHref).to.equal('http://www.registry.com/oc-client/client.js'); + expect(parsed.clientHref).to.equal( + 'http://www.registry.com/oc-client/client.js' + ); }); }); }); diff --git a/test/unit/cli-facade-mock.js b/test/unit/cli-facade-mock.js index 3499615cf..5de1a2a3c 100644 --- a/test/unit/cli-facade-mock.js +++ b/test/unit/cli-facade-mock.js @@ -4,22 +4,22 @@ const expect = require('chai').expect; const sinon = require('sinon'); describe('cli : facade : mock', () => { - const logSpy = {}, MockFacade = require('../../src/cli/facade/mock'), Local = require('../../src/cli/domain/local'), local = new Local(), mockFacade = new MockFacade({ local: local, logger: logSpy }); - const execute = function(){ + const execute = function() { logSpy.ok = sinon.spy(); - mockFacade({ targetType: 'plugin', targetName: 'getValue', targetValue: 'value' }, () => {}); + mockFacade( + { targetType: 'plugin', targetName: 'getValue', targetValue: 'value' }, + () => {} + ); }; describe('when mocking plugin', () => { - describe('when it succeeds', () => { - beforeEach(() => { sinon.stub(local, 'mock').yields(null, 'ok'); execute(); @@ -30,7 +30,9 @@ describe('cli : facade : mock', () => { }); it('should show a confirmation message', () => { - expect(logSpy.ok.args[0][0]).to.equal('Mock for plugin has been registered: getValue () => value'); + expect(logSpy.ok.args[0][0]).to.equal( + 'Mock for plugin has been registered: getValue () => value' + ); }); }); }); diff --git a/test/unit/cli-facade-package.js b/test/unit/cli-facade-package.js index 0e49dda58..9017519e6 100644 --- a/test/unit/cli-facade-package.js +++ b/test/unit/cli-facade-package.js @@ -5,28 +5,29 @@ const path = require('path'); const sinon = require('sinon'); describe('cli : facade : package', () => { - const logSpy = {}, Local = require('../../src/cli/domain/local'), local = new Local(), PackageFacade = require('../../src/cli/facade/package.js'), packageFacade = new PackageFacade({ local: local, logger: logSpy }); - const execute = function(compress, cb){ + const execute = function(compress, cb) { logSpy.err = sinon.stub(); logSpy.ok = sinon.stub(); logSpy.warn = sinon.stub(); - packageFacade({ - componentPath: 'test/fixtures/components/hello-world/', - compress: compress - }, () => { - cb(); - }); + packageFacade( + { + componentPath: 'test/fixtures/components/hello-world/', + compress: compress + }, + () => { + cb(); + } + ); }; describe('before packaging a component', () => { - - it('should always show a message', (done) => { + it('should always show a message', done => { sinon.stub(local, 'package').yields('the component is not valid'); execute(false, () => { local.package.restore(); @@ -36,16 +37,16 @@ describe('cli : facade : package', () => { messageWithSlashesOnPath = message.replace(re, '/'); expect(messageWithSlashesOnPath).to.include('Packaging -> '); - expect(messageWithSlashesOnPath).to.include('components/hello-world/_package'); + expect(messageWithSlashesOnPath).to.include( + 'components/hello-world/_package' + ); done(); }); }); describe('when packaging', () => { - describe('when a component is not valid', () => { - - beforeEach((done) => { + beforeEach(done => { sinon.stub(local, 'package').yields('the component is not valid'); execute(false, done); }); @@ -55,12 +56,13 @@ describe('cli : facade : package', () => { }); it('should show an error', () => { - expect(logSpy.err.args[0][0]).to.equal('An error happened when creating the package: the component is not valid'); + expect(logSpy.err.args[0][0]).to.equal( + 'An error happened when creating the package: the component is not valid' + ); }); }); describe('when a component is valid', () => { - beforeEach(() => { sinon.stub(local, 'package').yields(null, { name: 'hello-world', @@ -72,7 +74,7 @@ describe('cli : facade : package', () => { local.package.restore(); }); - it('should package and show success message', (done) => { + it('should package and show success message', done => { execute(false, () => { const warnMessage = logSpy.warn.args[0][0], okMessage = logSpy.ok.args[0][0], @@ -81,17 +83,20 @@ describe('cli : facade : package', () => { okMessageWithSlashesOnPath = okMessage.replace(re, '/'); expect(warnMessageWithSlashesOnPath).to.include('Packaging -> '); - expect(warnMessageWithSlashesOnPath).to.include('components/hello-world/_package'); + expect(warnMessageWithSlashesOnPath).to.include( + 'components/hello-world/_package' + ); expect(okMessageWithSlashesOnPath).to.include('Packaged -> '); - expect(okMessageWithSlashesOnPath).to.include('components/hello-world/_package'); + expect(okMessageWithSlashesOnPath).to.include( + 'components/hello-world/_package' + ); done(); }); }); describe('when creating tar.gz archive', () => { - - it('should not compress when option set to false', (done) => { + it('should not compress when option set to false', done => { sinon.stub(local, 'compress').yields(null); execute(false, () => { @@ -118,7 +123,7 @@ describe('cli : facade : package', () => { local.compress.restore(); }); - it('should show a message for success', (done) => { + it('should show a message for success', done => { execute(true, () => { const warnMessage = logSpy.warn.args[1][0], okMessage = logSpy.ok.args[1][0], @@ -126,17 +131,22 @@ describe('cli : facade : package', () => { warnMessageWithSlashesOnPath = warnMessage.replace(re, '/'), okMessageWithSlashesOnPath = okMessage.replace(re, '/'); - expect(warnMessageWithSlashesOnPath).to.include('Compressing -> '); - expect(warnMessageWithSlashesOnPath).to.include('components/hello-world/package.tar.gz'); + expect(warnMessageWithSlashesOnPath).to.include( + 'Compressing -> ' + ); + expect(warnMessageWithSlashesOnPath).to.include( + 'components/hello-world/package.tar.gz' + ); expect(okMessageWithSlashesOnPath).to.include('Compressed -> '); - expect(okMessageWithSlashesOnPath).to.include('components/hello-world/package.tar.gz'); + expect(okMessageWithSlashesOnPath).to.include( + 'components/hello-world/package.tar.gz' + ); done(); }); }); }); describe('when compression fails', () => { - beforeEach(() => { sinon.stub(local, 'compress').yields('error while compressing'); }); @@ -145,16 +155,22 @@ describe('cli : facade : package', () => { local.compress.restore(); }); - it('should show a message for failure', (done) => { + it('should show a message for failure', done => { execute(true, () => { const warnMessage = logSpy.warn.args[1][0], errorMessage = logSpy.err.args[0][0], re = new RegExp('\\' + path.sep, 'g'), warnMessageWithSlashesOnPath = warnMessage.replace(re, '/'); - expect(warnMessageWithSlashesOnPath).to.include('Compressing -> '); - expect(warnMessageWithSlashesOnPath).to.include('components/hello-world/package.tar.gz'); - expect(errorMessage).to.equal('An error happened when creating the package: error while compressing'); + expect(warnMessageWithSlashesOnPath).to.include( + 'Compressing -> ' + ); + expect(warnMessageWithSlashesOnPath).to.include( + 'components/hello-world/package.tar.gz' + ); + expect(errorMessage).to.equal( + 'An error happened when creating the package: error while compressing' + ); done(); }); }); diff --git a/test/unit/cli-facade-preview.js b/test/unit/cli-facade-preview.js index aee691651..5139478c4 100644 --- a/test/unit/cli-facade-preview.js +++ b/test/unit/cli-facade-preview.js @@ -5,23 +5,30 @@ const injectr = require('injectr'); const sinon = require('sinon'); describe('cli : facade : preview', () => { - let opnSpy, logSpy, registryStub; - const execute = function(error, url){ - + const execute = function(error, url) { opnSpy = sinon.spy(); - registryStub = { getComponentPreviewUrlByUrl: sinon.stub().yields(error, url)}; - logSpy = { err: sinon.spy()}; - - const PreviewFacade = injectr('../../src/cli/facade/preview.js', { opn: opnSpy }), - previewFacade = new PreviewFacade({ logger: logSpy, registry: registryStub }); - - previewFacade({ componentHref: 'http://components.com/component' }, () => {}); + registryStub = { + getComponentPreviewUrlByUrl: sinon.stub().yields(error, url) + }; + logSpy = { err: sinon.spy() }; + + const PreviewFacade = injectr('../../src/cli/facade/preview.js', { + opn: opnSpy + }), + previewFacade = new PreviewFacade({ + logger: logSpy, + registry: registryStub + }); + + previewFacade( + { componentHref: 'http://components.com/component' }, + () => {} + ); }; describe('when previewing not valid component', () => { - beforeEach(() => { execute('404!!!', {}); }); @@ -31,18 +38,21 @@ describe('cli : facade : preview', () => { }); it('should show error message', () => { - expect(logSpy.err.args[0][0]).to.equal('The specified path is not a valid component\'s url'); + expect(logSpy.err.args[0][0]).to.equal( + "The specified path is not a valid component's url" + ); }); }); describe('when previewing valid component', () => { - beforeEach(() => { execute(null, 'http://registry.com/component/~preview/'); }); it('should open /component/~preview/', () => { - expect(opnSpy.args[0][0]).to.equal('http://registry.com/component/~preview/'); + expect(opnSpy.args[0][0]).to.equal( + 'http://registry.com/component/~preview/' + ); }); }); }); diff --git a/test/unit/cli-facade-registry-add.js b/test/unit/cli-facade-registry-add.js index b8c9d5fde..2d6f1b596 100644 --- a/test/unit/cli-facade-registry-add.js +++ b/test/unit/cli-facade-registry-add.js @@ -4,21 +4,19 @@ const expect = require('chai').expect; const sinon = require('sinon'); describe('cli : facade : registry : add', () => { - const logSpy = {}, Registry = require('../../src/cli/domain/registry'), registry = new Registry(), RegistryFacade = require('../../src/cli/facade/registry-add'), registryFacade = new RegistryFacade({ registry: registry, logger: logSpy }); - const execute = function(){ + const execute = function() { logSpy.err = sinon.spy(); logSpy.ok = sinon.spy(); registryFacade({}, () => {}); }; describe('when adding a not valid registry', () => { - beforeEach(() => { sinon.stub(registry, 'add').yields('An error!!!', null); execute(); @@ -34,7 +32,6 @@ describe('cli : facade : registry : add', () => { }); describe('when adding a valid registry', () => { - beforeEach(() => { sinon.stub(registry, 'add').yields(null, 'ok!'); execute(); diff --git a/test/unit/cli-facade-registry-ls.js b/test/unit/cli-facade-registry-ls.js index 904a9ef82..dc78c57a0 100644 --- a/test/unit/cli-facade-registry-ls.js +++ b/test/unit/cli-facade-registry-ls.js @@ -4,23 +4,20 @@ const expect = require('chai').expect; const sinon = require('sinon'); describe('cli : facade : registry : ls', () => { - const logSpy = {}, Registry = require('../../src/cli/domain/registry'), registry = new Registry(), RegistryFacade = require('../../src/cli/facade/registry-ls'), registryFacade = new RegistryFacade({ registry: registry, logger: logSpy }); - const execute = function(){ + const execute = function() { logSpy.err = sinon.spy(); logSpy.ok = sinon.spy(); logSpy.warn = sinon.spy(); registryFacade({}, () => {}); }; - describe('when no registries linked to the app', () => { - beforeEach(() => { sinon.stub(registry, 'get').yields(null, []); execute(); @@ -35,14 +32,20 @@ describe('cli : facade : registry : ls', () => { }); it('should log an error', () => { - expect(logSpy.err.args[0][0]).to.equal('oc registries not found. Run "oc registry add "'); + expect(logSpy.err.args[0][0]).to.equal( + 'oc registries not found. Run "oc registry add "' + ); }); }); describe('when registries linked to the app', () => { - beforeEach(() => { - sinon.stub(registry, 'get').yields(null, ['http://www.registry.com', 'https://www.anotherregistry.com']); + sinon + .stub(registry, 'get') + .yields(null, [ + 'http://www.registry.com', + 'https://www.anotherregistry.com' + ]); execute(); }); diff --git a/test/unit/cli-facade-registry-remove.js b/test/unit/cli-facade-registry-remove.js index b2ddc17f0..fb43df1e0 100644 --- a/test/unit/cli-facade-registry-remove.js +++ b/test/unit/cli-facade-registry-remove.js @@ -4,21 +4,19 @@ const expect = require('chai').expect; const sinon = require('sinon'); describe('cli : facade : registry : remove', () => { - const logSpy = {}, Registry = require('../../src/cli/domain/registry'), registry = new Registry(), RegistryFacade = require('../../src/cli/facade/registry-remove'), registryFacade = new RegistryFacade({ registry: registry, logger: logSpy }); - const execute = function(){ + const execute = function() { logSpy.err = sinon.spy(); logSpy.ok = sinon.spy(); - registryFacade({ }, () => {}); + registryFacade({}, () => {}); }; describe('when removing a registry and having some problem removing it', () => { - beforeEach(() => { sinon.stub(registry, 'remove').yields('something bad happened!', null); execute(); @@ -34,7 +32,6 @@ describe('cli : facade : registry : remove', () => { }); describe('when removing a valid registry', () => { - beforeEach(() => { sinon.stub(registry, 'remove').yields(null, 'ok!'); execute(); diff --git a/test/unit/cli-validate-command.js b/test/unit/cli-validate-command.js index 12337a19a..1a7d402d1 100644 --- a/test/unit/cli-validate-command.js +++ b/test/unit/cli-validate-command.js @@ -17,7 +17,7 @@ describe('cli : validate-command : valid', () => { } ]; - scenarios.forEach((scenario) => { + scenarios.forEach(scenario => { describe(`given "${scenario._.join(' ')}"`, () => { it(`"${scenario._[scenario.level]}" should be a valid command`, () => { const argv = { @@ -43,7 +43,7 @@ describe('cli : validate-command : invalid', () => { } ]; - scenarios.forEach((scenario) => { + scenarios.forEach(scenario => { describe(`given "${scenario._.join(' ')}"`, () => { it(`"${scenario._[scenario.level]}" should be an invalid command`, () => { const argv = { @@ -51,7 +51,9 @@ describe('cli : validate-command : invalid', () => { }; const level = scenario.level; - expect(() => { validate(argv, level); }).to.throw(); + expect(() => { + validate(argv, level); + }).to.throw(); }); }); }); diff --git a/test/unit/registry-domain-events-handler.js b/test/unit/registry-domain-events-handler.js index f2861973d..d56aa21f3 100644 --- a/test/unit/registry-domain-events-handler.js +++ b/test/unit/registry-domain-events-handler.js @@ -4,11 +4,9 @@ const expect = require('chai').expect; const sinon = require('sinon'); describe('registry : domain : events-handler', () => { - const eventsHandler = require('../../src/registry/domain/events-handler'); describe('when requiring it multiple times', () => { - const spy = sinon.spy(); let handler2; @@ -28,13 +26,16 @@ describe('registry : domain : events-handler', () => { }); describe('when firing an event that has multiple subscribers', () => { - const spy = sinon.spy(); let c = 0; before(() => { - eventsHandler.on('fire', (payload) => { spy(++c, payload); }); - eventsHandler.on('fire', (payload) => { spy(++c, payload); }); + eventsHandler.on('fire', payload => { + spy(++c, payload); + }); + eventsHandler.on('fire', payload => { + spy(++c, payload); + }); eventsHandler.fire('fire', { hello: true }); }); @@ -54,14 +55,14 @@ describe('registry : domain : events-handler', () => { }); describe('when subscribing a request event using a not valid handler', () => { - - const execute = function(){ + const execute = function() { eventsHandler.on('request', 'this is not a function'); }; it('should throw an error', () => { - expect(execute).to.throw('Registry configuration is not valid: registry.on\'s callback must be a function'); + expect(execute).to.throw( + "Registry configuration is not valid: registry.on's callback must be a function" + ); }); }); - }); diff --git a/test/unit/registry-domain-extract-package.js b/test/unit/registry-domain-extract-package.js index abf07e8cc..7460d82f8 100644 --- a/test/unit/registry-domain-extract-package.js +++ b/test/unit/registry-domain-extract-package.js @@ -5,35 +5,49 @@ const injectr = require('injectr'); const sinon = require('sinon'); describe('registry : domain : extract-package', () => { - const decompressStub = sinon.stub(), pathResolveStub = sinon.stub(); - const extractPackage = injectr('../../src/registry/domain/extract-package.js', { - targz: { decompress: decompressStub }, - path: { resolve: pathResolveStub }, - './get-package-json-from-temp-dir': sinon.stub().yields(null, { package: 'hello' }) - }); + const extractPackage = injectr( + '../../src/registry/domain/extract-package.js', + { + targz: { decompress: decompressStub }, + path: { resolve: pathResolveStub }, + './get-package-json-from-temp-dir': sinon + .stub() + .yields(null, { package: 'hello' }) + } + ); describe('when successfully extracting package', () => { - let response; - beforeEach((done) => { + beforeEach(done => { pathResolveStub.reset(); - pathResolveStub.onCall(0).returns('/some-path/registry/temp/1478279453422.tar.gz'); - pathResolveStub.onCall(1).returns('/some-path/registry/temp/1478279453422/'); - pathResolveStub.onCall(2).returns('/some-path/registry/temp/1478279453422/_package/'); + pathResolveStub + .onCall(0) + .returns('/some-path/registry/temp/1478279453422.tar.gz'); + pathResolveStub + .onCall(1) + .returns('/some-path/registry/temp/1478279453422/'); + pathResolveStub + .onCall(2) + .returns('/some-path/registry/temp/1478279453422/_package/'); decompressStub.yields(); - extractPackage([{ - filename: '1478279453422.tar.gz', - path: '/some-path/registry/temp/1478279453422.tar.gz' - }], (err, res) => { - response = res; - done(); - }); + extractPackage( + [ + { + filename: '1478279453422.tar.gz', + path: '/some-path/registry/temp/1478279453422.tar.gz' + } + ], + (err, res) => { + response = res; + done(); + } + ); }); it('should decompress tar.gz file', () => { @@ -52,24 +66,34 @@ describe('registry : domain : extract-package', () => { }); describe('when extracting package fails', () => { - let error; - beforeEach((done) => { + beforeEach(done => { pathResolveStub.reset(); - pathResolveStub.onCall(0).returns('/some-path/registry/temp/1478279453422.tar.gz'); - pathResolveStub.onCall(1).returns('/some-path/registry/temp/1478279453422/'); - pathResolveStub.onCall(2).returns('/some-path/registry/temp/1478279453422/_package/'); + pathResolveStub + .onCall(0) + .returns('/some-path/registry/temp/1478279453422.tar.gz'); + pathResolveStub + .onCall(1) + .returns('/some-path/registry/temp/1478279453422/'); + pathResolveStub + .onCall(2) + .returns('/some-path/registry/temp/1478279453422/_package/'); decompressStub.yields('error!'); - extractPackage([{ - filename: '1478279453422.tar.gz', - path: '/some-path/registry/temp/1478279453422.tar.gz' - }], (err) => { - error = err; - done(); - }); + extractPackage( + [ + { + filename: '1478279453422.tar.gz', + path: '/some-path/registry/temp/1478279453422.tar.gz' + } + ], + err => { + error = err; + done(); + } + ); }); it('should respond with error', () => { diff --git a/test/unit/registry-domain-nested-renderer.js b/test/unit/registry-domain-nested-renderer.js index 61062ad88..9cb752774 100644 --- a/test/unit/registry-domain-nested-renderer.js +++ b/test/unit/registry-domain-nested-renderer.js @@ -5,15 +5,12 @@ const sinon = require('sinon'); const _ = require('lodash'); describe('registry : routes : helpers : nested-renderer', () => { - const NestedRenderer = require('../../src/registry/domain/nested-renderer'); - let nestedRenderer, - renderer; - - const initialise = function(rendererMocks, conf){ + let nestedRenderer, renderer; - if(_.isArray(rendererMocks)){ + const initialise = function(rendererMocks, conf) { + if (_.isArray(rendererMocks)) { renderer = sinon.stub(); _.each(rendererMocks, (rendererMock, i) => { @@ -27,51 +24,62 @@ describe('registry : routes : helpers : nested-renderer', () => { }; describe('when rendering nested component', () => { - describe('when req is not valid', () => { - describe('when componentName not valid', () => { - - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponent(); }; - expect(f).to.throw('component\'s name is not valid'); + const f = function() { + nestedRenderer.renderComponent(); + }; + expect(f).to.throw("component's name is not valid"); }); }); describe('when componentName empty', () => { - - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponent(''); }; - expect(f).to.throw('component\'s name is not valid'); + const f = function() { + nestedRenderer.renderComponent(''); + }; + expect(f).to.throw("component's name is not valid"); }); }); describe('when callback empty', () => { - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponent('my-component'); }; + const f = function() { + nestedRenderer.renderComponent('my-component'); + }; expect(f).to.throw('callback is not valid'); }); }); describe('when callback not valid', () => { - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponent('my-component', {}, 'blarg'); }; + const f = function() { + nestedRenderer.renderComponent('my-component', {}, 'blarg'); + }; expect(f).to.throw('callback is not valid'); }); }); describe('when requesting a not existent component', () => { - let error; - beforeEach((done) => { + beforeEach(done => { initialise({ status: 404, response: { @@ -79,7 +87,7 @@ describe('registry : routes : helpers : nested-renderer', () => { } }); - nestedRenderer.renderComponent('404-component', {}, (err) => { + nestedRenderer.renderComponent('404-component', {}, err => { error = err; done(); }); @@ -92,31 +100,35 @@ describe('registry : routes : helpers : nested-renderer', () => { }); describe('when req is valid', () => { - describe('when all params specified', () => { - let result, error; - beforeEach((done) => { - - initialise({ - status: 200, - response: { - html: 'Some html' - } - }, { bla: 'blabla' }); + beforeEach(done => { + initialise( + { + status: 200, + response: { + html: 'Some html' + } + }, + { bla: 'blabla' } + ); - nestedRenderer.renderComponent('my-component', { - headers: { - 'accept-language': 'en-GB', - 'accept': 'blargh' + nestedRenderer.renderComponent( + 'my-component', + { + headers: { + 'accept-language': 'en-GB', + accept: 'blargh' + }, + parameters: { a: 1234 }, + version: '1.2.X' }, - parameters: { a: 1234 }, - version: '1.2.X' - }, (err, res) => { - result = res; - error = err; - done(); - }); + (err, res) => { + result = res; + error = err; + done(); + } + ); }); it('should get the html result', () => { @@ -129,7 +141,7 @@ describe('registry : routes : helpers : nested-renderer', () => { conf: { bla: 'blabla' }, headers: { 'accept-language': 'en-GB', - 'accept': 'application/vnd.oc.rendered+json' + accept: 'application/vnd.oc.rendered+json' }, parameters: { a: 1234 }, version: '1.2.X' @@ -142,16 +154,17 @@ describe('registry : routes : helpers : nested-renderer', () => { }); describe('when minimal params specified', () => { - let result, error; - beforeEach((done) => { - - initialise({ - status: 200, - response: { - html: 'Some html' - } - }, { bla: 'blabla' }); + beforeEach(done => { + initialise( + { + status: 200, + response: { + html: 'Some html' + } + }, + { bla: 'blabla' } + ); nestedRenderer.renderComponent('my-component', (err, res) => { result = res; @@ -169,7 +182,7 @@ describe('registry : routes : helpers : nested-renderer', () => { name: 'my-component', conf: { bla: 'blabla' }, headers: { - 'accept': 'application/vnd.oc.rendered+json' + accept: 'application/vnd.oc.rendered+json' }, parameters: {}, version: '' @@ -184,51 +197,62 @@ describe('registry : routes : helpers : nested-renderer', () => { }); describe('when rendering nested components', () => { - describe('when req is not valid', () => { - describe('when components not valid', () => { - - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponents(); }; + const f = function() { + nestedRenderer.renderComponents(); + }; expect(f).to.throw('components is not valid'); }); }); describe('when components empty', () => { - - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponents([]); }; + const f = function() { + nestedRenderer.renderComponents([]); + }; expect(f).to.throw('components is not valid'); }); }); describe('when callback empty', () => { - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponents([{ name: 'my-component'}]); }; + const f = function() { + nestedRenderer.renderComponents([{ name: 'my-component' }]); + }; expect(f).to.throw('callback is not valid'); }); }); describe('when callback not valid', () => { - beforeEach(() => { initialise(); }); + beforeEach(() => { + initialise(); + }); it('should throw an error', () => { - const f = function(){ nestedRenderer.renderComponents(['my-component'], {}, 'blarg'); }; + const f = function() { + nestedRenderer.renderComponents(['my-component'], {}, 'blarg'); + }; expect(f).to.throw('callback is not valid'); }); }); describe('when requesting not existent components', () => { - let result, error; - beforeEach((done) => { + beforeEach(done => { initialise({ status: 404, response: { @@ -236,14 +260,18 @@ describe('registry : routes : helpers : nested-renderer', () => { } }); - nestedRenderer.renderComponents([ - { name: '404-component' }, - { name: 'another-not-existent-component' } - ], {}, (err, res) => { - result = res; - error = err; - done(); - }); + nestedRenderer.renderComponents( + [ + { name: '404-component' }, + { name: 'another-not-existent-component' } + ], + {}, + (err, res) => { + result = res; + error = err; + done(); + } + ); }); it('should return no error in the callback', () => { @@ -260,56 +288,59 @@ describe('registry : routes : helpers : nested-renderer', () => { }); describe('when req is valid', () => { - describe('when all params specified', () => { - let result, error; - beforeEach((done) => { - - initialise([ + beforeEach(done => { + initialise( + [ + { + status: 200, + response: { html: 'Some html' } + }, + { + status: 200, + response: { html: 'Some other html' } + } + ], + { bla: 'blabla' } + ); + + nestedRenderer.renderComponents( + [ + { + name: 'my-component', + parameters: { x: 123 }, + version: '1.2.X' + }, + { + name: 'my-other-component', + parameters: { y: 456 }, + version: '^1.4.6' + } + ], { - status: 200, - response: { html: 'Some html' } + headers: { + 'accept-language': 'en-GB', + accept: 'blargh' + }, + parameters: { + x: 456, + z: 789 + } }, - { - status: 200, - response: { html: 'Some other html' } + (err, res) => { + result = res; + error = err; + done(); } - ], { bla: 'blabla' }); - - nestedRenderer.renderComponents([{ - name: 'my-component', - parameters: { x: 123 }, - version: '1.2.X' - }, { - name: 'my-other-component', - parameters: { y: 456 }, - version: '^1.4.6' - }], { - headers: { - 'accept-language': 'en-GB', - 'accept': 'blargh' - }, - parameters: { - x: 456, - z: 789 - } - }, (err, res) => { - result = res; - error = err; - done(); - }); + ); }); it('should get the html result', () => { - expect(result).to.eql([ - 'Some html', - 'Some other html' - ]); + expect(result).to.eql(['Some html', 'Some other html']); }); it('should make correct request to renderer', () => { - expect(renderer.args.length).to.equal(2); expect(renderer.args[0][0]).to.eql({ @@ -317,7 +348,7 @@ describe('registry : routes : helpers : nested-renderer', () => { conf: { bla: 'blabla' }, headers: { 'accept-language': 'en-GB', - 'accept': 'application/vnd.oc.rendered+json' + accept: 'application/vnd.oc.rendered+json' }, parameters: { x: 123, @@ -331,7 +362,7 @@ describe('registry : routes : helpers : nested-renderer', () => { conf: { bla: 'blabla' }, headers: { 'accept-language': 'en-GB', - 'accept': 'application/vnd.oc.rendered+json' + accept: 'application/vnd.oc.rendered+json' }, parameters: { x: 456, @@ -348,43 +379,43 @@ describe('registry : routes : helpers : nested-renderer', () => { }); describe('when minimal params specified', () => { - let result, error; - beforeEach((done) => { - - initialise([{ - status: 200, - response: { html: 'Some html' } - },{ - status: 200, - response: { html: 'Some other html' } - }], { bla: 'blabla' }); - - nestedRenderer.renderComponents([ - { name: 'my-component' }, - { name: 'my-other-component' } - ], (err, res) => { - result = res; - error = err; - done(); - }); + beforeEach(done => { + initialise( + [ + { + status: 200, + response: { html: 'Some html' } + }, + { + status: 200, + response: { html: 'Some other html' } + } + ], + { bla: 'blabla' } + ); + + nestedRenderer.renderComponents( + [{ name: 'my-component' }, { name: 'my-other-component' }], + (err, res) => { + result = res; + error = err; + done(); + } + ); }); it('should get the html result', () => { - expect(result).to.eql([ - 'Some html', - 'Some other html' - ]); + expect(result).to.eql(['Some html', 'Some other html']); }); it('should make correct request to renderer', () => { - expect(renderer.args.length).to.equal(2); expect(renderer.args[0][0]).to.eql({ name: 'my-component', conf: { bla: 'blabla' }, - headers: { 'accept': 'application/vnd.oc.rendered+json' }, + headers: { accept: 'application/vnd.oc.rendered+json' }, parameters: {}, version: '' }); @@ -392,7 +423,7 @@ describe('registry : routes : helpers : nested-renderer', () => { expect(renderer.args[1][0]).to.eql({ name: 'my-other-component', conf: { bla: 'blabla' }, - headers: { 'accept': 'application/vnd.oc.rendered+json' }, + headers: { accept: 'application/vnd.oc.rendered+json' }, parameters: {}, version: '' }); diff --git a/test/unit/registry-domain-plugins-initialiser.js b/test/unit/registry-domain-plugins-initialiser.js index 1b864bcf6..029c87436 100644 --- a/test/unit/registry-domain-plugins-initialiser.js +++ b/test/unit/registry-domain-plugins-initialiser.js @@ -3,44 +3,44 @@ const expect = require('chai').expect; describe('registry : domain : plugins-initialiser', () => { - const pluginsInitialiser = require('../../src/registry/domain/plugins-initialiser'); describe('when initialising not valid plugins', () => { - describe('when plugin not registered correctly', () => { - let error; - beforeEach((done) => { - - const plugins = [{ - name: 'doSomething' - }]; + beforeEach(done => { + const plugins = [ + { + name: 'doSomething' + } + ]; - pluginsInitialiser.init(plugins, (err) => { + pluginsInitialiser.init(plugins, err => { error = err; done(); }); }); it('should error', () => { - expect(error.toString()).to.be.eql('Error: Plugin doSomething is not valid'); + expect(error.toString()).to.be.eql( + 'Error: Plugin doSomething is not valid' + ); }); }); describe('when plugin is anonymous', () => { - let error; - beforeEach((done) => { - - const plugins = [{ - register: { - register: function(){}, - execute: function(){} + beforeEach(done => { + const plugins = [ + { + register: { + register: function() {}, + execute: function() {} + } } - }]; + ]; - pluginsInitialiser.init(plugins, (err) => { + pluginsInitialiser.init(plugins, err => { error = err; done(); }); @@ -52,81 +52,85 @@ describe('registry : domain : plugins-initialiser', () => { }); describe('when plugin does not expose a register method', () => { - let error; - beforeEach((done) => { - - const plugins = [{ - name: 'doSomething', - register: { execute: function(){}} - }]; + beforeEach(done => { + const plugins = [ + { + name: 'doSomething', + register: { execute: function() {} } + } + ]; - pluginsInitialiser.init(plugins, (err) => { + pluginsInitialiser.init(plugins, err => { error = err; done(); }); }); it('should error', () => { - expect(error.toString()).to.be.eql('Error: Plugin doSomething is not valid'); + expect(error.toString()).to.be.eql( + 'Error: Plugin doSomething is not valid' + ); }); }); describe('when plugin does not expose an execute method', () => { - let error; - beforeEach((done) => { - - const plugins = [{ - name: 'doSomething', - register: { register: function(){}} - }]; + beforeEach(done => { + const plugins = [ + { + name: 'doSomething', + register: { register: function() {} } + } + ]; - pluginsInitialiser.init(plugins, (err) => { + pluginsInitialiser.init(plugins, err => { error = err; done(); }); }); it('should error', () => { - expect(error.toString()).to.be.eql('Error: Plugin doSomething is not valid'); + expect(error.toString()).to.be.eql( + 'Error: Plugin doSomething is not valid' + ); }); }); }); describe('when initialising valid plugins', () => { - let passedOptions, flag, result; - beforeEach((done) => { - - const plugins = [{ - name: 'getValue', - register: { - register: function(options, deps, cb){ - passedOptions = options; - cb(); + beforeEach(done => { + const plugins = [ + { + name: 'getValue', + register: { + register: function(options, deps, cb) { + passedOptions = options; + cb(); + }, + execute: function(key) { + return passedOptions[key]; + } }, - execute: function(key){ - return passedOptions[key]; + options: { + a: 123, + b: 456 } }, - options: { - a: 123, - b: 456 - } - }, - { - name: 'isFlagged', - register: { - register: function(options, deps, cb){ - flag = true; - cb(); - }, - execute: function(){ - return flag; + { + name: 'isFlagged', + register: { + register: function(options, deps, cb) { + flag = true; + cb(); + }, + execute: function() { + return flag; + } } } - }]; + ]; pluginsInitialiser.init(plugins, (err, res) => { result = res; @@ -135,7 +139,7 @@ describe('registry : domain : plugins-initialiser', () => { }); it('should register plugin with passed options', () => { - expect(passedOptions).to.eql({a: 123, b: 456}); + expect(passedOptions).to.eql({ a: 123, b: 456 }); }); it('should expose the functionalities using the plugin names', () => { @@ -153,34 +157,34 @@ describe('registry : domain : plugins-initialiser', () => { }); describe('when plugin specifies dependencies', () => { - let passedDeps, flag; - beforeEach((done) => { - - const plugins = [{ - name: 'isFlagged', - register: { - register: function(options, deps, cb){ - flag = true; - cb(); - }, - execute: function(){ - return flag; + beforeEach(done => { + const plugins = [ + { + name: 'isFlagged', + register: { + register: function(options, deps, cb) { + flag = true; + cb(); + }, + execute: function() { + return flag; + } } - } - }, - { - name: 'getValue', - register: { - register: function(options, deps, cb){ - passedDeps = deps; - cb(); - }, - execute: function(){}, - dependencies: ['isFlagged'] }, - options: {} - }]; + { + name: 'getValue', + register: { + register: function(options, deps, cb) { + passedDeps = deps; + cb(); + }, + execute: function() {}, + dependencies: ['isFlagged'] + }, + options: {} + } + ]; pluginsInitialiser.init(plugins, () => { done(); @@ -193,113 +197,119 @@ describe('registry : domain : plugins-initialiser', () => { }); describe('when plugins have a circular dependency', () => { - let flag, error; - beforeEach((done) => { - - const plugins = [{ - name: 'getValue', - register: { - register: function(options, deps, cb){ - cb(); + beforeEach(done => { + const plugins = [ + { + name: 'getValue', + register: { + register: function(options, deps, cb) { + cb(); + }, + execute: function() {}, + dependencies: ['isFlagged'] }, - execute: function(){}, - dependencies: ['isFlagged'] + options: {} }, - options: {} - }, - { - name: 'isFlagged', - register: { - register: function(options, deps, cb){ - flag = true; - cb(); - }, - execute: function(){ - return flag; - }, - dependencies: ['getValue'] + { + name: 'isFlagged', + register: { + register: function(options, deps, cb) { + flag = true; + cb(); + }, + execute: function() { + return flag; + }, + dependencies: ['getValue'] + } } - }]; + ]; - pluginsInitialiser.init(plugins, (err) => { + pluginsInitialiser.init(plugins, err => { error = err; done(); }); }); it('should throw an error', () => { - expect(error.toString()).to.eql('Error: Dependency Cycle Found: getValue -> isFlagged -> getValue'); + expect(error.toString()).to.eql( + 'Error: Dependency Cycle Found: getValue -> isFlagged -> getValue' + ); }); }); describe('when plugin depends on a plugin that is not registered', () => { - let error; - beforeEach((done) => { - - const plugins = [{ - name: 'getValue', - register: { - register: function(options, deps, cb){ - cb(); + beforeEach(done => { + const plugins = [ + { + name: 'getValue', + register: { + register: function(options, deps, cb) { + cb(); + }, + execute: function() {}, + dependencies: ['isFlagged'] }, - execute: function(){}, - dependencies: ['isFlagged'] - }, - options: {} - }]; + options: {} + } + ]; - pluginsInitialiser.init(plugins, (err) => { + pluginsInitialiser.init(plugins, err => { error = err; done(); }); }); it('should throw an error', () => { - expect(error.toString()).to.eql('Error: unknown plugin dependency: isFlagged'); + expect(error.toString()).to.eql( + 'Error: unknown plugin dependency: isFlagged' + ); }); }); describe('when plugin chain requires multiple passes', () => { - let flag, result; - beforeEach((done) => { - - const plugins = [{ - name: 'doSomething', - register: { - register: function(options, deps, cb){ - cb(); + beforeEach(done => { + const plugins = [ + { + name: 'doSomething', + register: { + register: function(options, deps, cb) { + cb(); + }, + execute: function() { + return true; + }, + dependencies: ['getValue'] }, - execute: function(){ return true; }, - dependencies: ['getValue'] + options: {} }, - options: {} - }, - { - name: 'getValue', - register: { - register: function(options, deps, cb){ - cb(); + { + name: 'getValue', + register: { + register: function(options, deps, cb) { + cb(); + }, + execute: function() {}, + dependencies: ['isFlagged'] }, - execute: function(){}, - dependencies: ['isFlagged'] + options: {} }, - options: {} - }, - { - name: 'isFlagged', - register: { - register: function(options, deps, cb){ - flag = true; - cb(); - }, - execute: function(){ - return flag; + { + name: 'isFlagged', + register: { + register: function(options, deps, cb) { + flag = true; + cb(); + }, + execute: function() { + return flag; + } } } - }]; + ]; pluginsInitialiser.init(plugins, (err, res) => { result = res; diff --git a/test/unit/registry-domain-require-wrapper.js b/test/unit/registry-domain-require-wrapper.js index 62e974ae4..f28edec2b 100644 --- a/test/unit/registry-domain-require-wrapper.js +++ b/test/unit/registry-domain-require-wrapper.js @@ -4,24 +4,25 @@ const expect = require('chai').expect; const vm = require('vm'); describe('registry : domain : require-wrapper', () => { - const RequireWrapper = require('../../src/registry/domain/require-wrapper'); describe('when using the require wrapper in a clear context', () => { - let result, error; const execute = (dependencies, script) => { - const context = { require: RequireWrapper(dependencies), result: null, console }; + const context = { + require: RequireWrapper(dependencies), + result: null, + console + }; try { vm.runInNewContext(script, context); result = context.result; - } catch(e){ + } catch (e) { error = e; } }; describe('when requiring a dependency', () => { - before(() => { const script = `var _ = require('lodash'); result = _.first([5, 4, 3, 2, 1]);`; execute(['lodash'], script); @@ -33,7 +34,6 @@ describe('registry : domain : require-wrapper', () => { }); describe('when requiring an unrecognised dependency', () => { - before(() => { const script = `var someModule = require('some-module'); result = someModule.someFunction('John Doe');`; execute([], script); @@ -48,7 +48,6 @@ describe('registry : domain : require-wrapper', () => { }); describe('when requiring a core dependency', () => { - before(() => { const script = `var url = require('url'); result = url.parse('www.google.com').href;`; execute(['url'], script); @@ -60,7 +59,6 @@ describe('registry : domain : require-wrapper', () => { }); describe('when requiring an unvetted core dependency', () => { - before(() => { const script = `var url = require('url'); result = url.parse('www.google.com').href;`; execute(['querystring'], script); @@ -75,7 +73,6 @@ describe('registry : domain : require-wrapper', () => { }); describe('when requiring a dependency with a relative path', () => { - before(() => { const script = `var _ = require('lodash/lodash'); result = _.first([5, 4, 3, 2, 1]);`; execute(['lodash'], script); @@ -87,7 +84,6 @@ describe('registry : domain : require-wrapper', () => { }); describe('when requiring a dependency with a relative path that does not exist', () => { - before(() => { const script = `var _ = require('lodash/foo'); result = _.first([5, 4, 3, 2, 1]);`; execute(['lodash'], script); diff --git a/test/unit/registry-domain-sanitiser.js b/test/unit/registry-domain-sanitiser.js index be09aa068..f4195fb48 100644 --- a/test/unit/registry-domain-sanitiser.js +++ b/test/unit/registry-domain-sanitiser.js @@ -3,17 +3,15 @@ const expect = require('chai').expect; describe('registry : domain : sanitiser', () => { - const sanitiser = require('../../src/registry/domain/sanitiser'); - describe('when sanitising component\'s request parameters', () => { - - const sanitise = function(a,b){ return sanitiser.sanitiseComponentParameters(a,b); }; + describe("when sanitising component's request parameters", () => { + const sanitise = function(a, b) { + return sanitiser.sanitiseComponentParameters(a, b); + }; describe('when component has boolean parameter', () => { - it('should convert string to boolean when true', () => { - const componentParameters = { isTrue: { type: 'boolean', @@ -23,13 +21,15 @@ describe('registry : domain : sanitiser', () => { }; const requestParameters = { isTrue: 'true' }, - sanitisedParameters = sanitise(requestParameters, componentParameters); + sanitisedParameters = sanitise( + requestParameters, + componentParameters + ); expect(sanitisedParameters).to.eql({ isTrue: true }); }); it('should convert string to boolean when true', () => { - const componentParameters = { isTrue: { type: 'boolean', @@ -39,16 +39,17 @@ describe('registry : domain : sanitiser', () => { }; const requestParameters = { isTrue: 'false' }, - sanitisedParameters = sanitise(requestParameters, componentParameters); + sanitisedParameters = sanitise( + requestParameters, + componentParameters + ); expect(sanitisedParameters).to.eql({ isTrue: false }); }); }); describe('when component has string parameter', () => { - it('should convert null to empty', () => { - const componentParameters = { myString: { type: 'string', @@ -58,16 +59,17 @@ describe('registry : domain : sanitiser', () => { }; const requestParameters = { myString: null }, - sanitisedParameters = sanitise(requestParameters, componentParameters); + sanitisedParameters = sanitise( + requestParameters, + componentParameters + ); expect(sanitisedParameters).to.eql({ myString: '' }); }); }); describe('when component has number parameter', () => { - it('should convert string to number', () => { - const componentParameters = { age: { type: 'number', @@ -77,19 +79,23 @@ describe('registry : domain : sanitiser', () => { }; const requestParameters = { age: '123' }, - sanitisedParameters = sanitise(requestParameters, componentParameters); + sanitisedParameters = sanitise( + requestParameters, + componentParameters + ); expect(sanitisedParameters).to.eql({ age: 123 }); }); }); describe('when component have not defined optional parameter', () => { - it('should keep the parameter as it is', () => { - const componentParameters = {}, requestParameters = { age: 123 }, - sanitisedParameters = sanitise(requestParameters, componentParameters); + sanitisedParameters = sanitise( + requestParameters, + componentParameters + ); expect(sanitisedParameters).to.eql({ age: 123 }); }); diff --git a/test/unit/registry-domain-url-builder.js b/test/unit/registry-domain-url-builder.js index 1c4d5b96d..290e16f38 100644 --- a/test/unit/registry-domain-url-builder.js +++ b/test/unit/registry-domain-url-builder.js @@ -3,34 +3,36 @@ const expect = require('chai').expect; describe('registry : domain : url-builder', () => { - const urlBuilder = require('../../src/registry/domain/url-builder'); let builtUrl; describe('when building component url', () => { - const execute = function(component, baseUrl){ + const execute = function(component, baseUrl) { builtUrl = urlBuilder.component(component, baseUrl); }; describe('when building component with just component name', () => { - before(() => { execute('component-name', 'http://www.registry.com/api/v2/'); }); it('should be baseUrl/componentName', () => { - expect(builtUrl).to.equal('http://www.registry.com/api/v2/component-name'); + expect(builtUrl).to.equal( + 'http://www.registry.com/api/v2/component-name' + ); }); }); describe('when building component with version', () => { - before(() => { - execute({ - name: 'component', - version: '~1.2.3' - }, 'http://registry.com'); + execute( + { + name: 'component', + version: '~1.2.3' + }, + 'http://registry.com' + ); }); it('should be baseUrl/componentName/version', () => { @@ -39,99 +41,109 @@ describe('registry : domain : url-builder', () => { }); describe('when building component with query string parameters', () => { - const component = { name: 'hello-world', version: '1.X.X' }; describe('when building component with number parameter', () => { - before(() => { component.parameters = { age: 23 }; execute(component, 'http://oc-registry.net'); }); it('should be baseUrl/componentName/version/?param=123', () => { - expect(builtUrl).to.equal('http://oc-registry.net/hello-world/1.X.X?age=23'); + expect(builtUrl).to.equal( + 'http://oc-registry.net/hello-world/1.X.X?age=23' + ); }); }); describe('when building component with url parameter', () => { - before(() => { - component.parameters = { returnUrl: 'http://www.website.com/?q=blabla&q2=hello' }; + component.parameters = { + returnUrl: 'http://www.website.com/?q=blabla&q2=hello' + }; execute(component, 'http://oc-registry.org'); }); it('should be baseUrl/componentName/version/?param=encodedUrl', () => { - expect(builtUrl).to.equal('http://oc-registry.org/hello-world/1.X.X?returnUrl=http%3A%2F%2Fwww.website.com%2F%3Fq%3Dblabla%26q2%3Dhello'); + expect(builtUrl).to.equal( + 'http://oc-registry.org/hello-world/1.X.X?returnUrl=http%3A%2F%2Fwww.website.com%2F%3Fq%3Dblabla%26q2%3Dhello' + ); }); }); }); }); describe('when building component preview url', () => { - const execute = function(component, baseUrl){ + const execute = function(component, baseUrl) { builtUrl = urlBuilder.componentPreview(component, baseUrl); }; describe('when building url with just component name', () => { - before(() => { execute('component-name', 'http://www.registry.com/api/v2/'); }); it('should be baseUrl/componentName', () => { - expect(builtUrl).to.equal('http://www.registry.com/api/v2/component-name/~preview/'); + expect(builtUrl).to.equal( + 'http://www.registry.com/api/v2/component-name/~preview/' + ); }); }); describe('when building url with version', () => { - before(() => { - execute({ - name: 'component', - version: '~1.2.3' - }, 'http://registry.com'); + execute( + { + name: 'component', + version: '~1.2.3' + }, + 'http://registry.com' + ); }); it('should be baseUrl/componentName/version', () => { - expect(builtUrl).to.equal('http://registry.com/component/~1.2.3/~preview/'); + expect(builtUrl).to.equal( + 'http://registry.com/component/~1.2.3/~preview/' + ); }); }); describe('when building url with query string parameters', () => { - const component = { name: 'hello-world', version: '1.X.X' }; describe('when building component with number parameter', () => { - before(() => { component.parameters = { age: 23 }; execute(component, 'http://oc-registry.net'); }); it('should be baseUrl/componentName/version/?param=123', () => { - expect(builtUrl).to.equal('http://oc-registry.net/hello-world/1.X.X/~preview/?age=23'); + expect(builtUrl).to.equal( + 'http://oc-registry.net/hello-world/1.X.X/~preview/?age=23' + ); }); }); describe('when building component with url parameter', () => { - before(() => { - component.parameters = { returnUrl: 'http://www.website.com/?q=blabla&q2=hello' }; + component.parameters = { + returnUrl: 'http://www.website.com/?q=blabla&q2=hello' + }; execute(component, 'http://oc-registry.org'); }); it('should be baseUrl/componentName/version/?param=encodedUrl', () => { - expect(builtUrl).to.equal('http://oc-registry.org/hello-world/1.X.X/~preview/?returnUrl=http%3A%2F%2Fwww.website.com%2F%3Fq%3Dblabla%26q2%3Dhello'); + expect(builtUrl).to.equal( + 'http://oc-registry.org/hello-world/1.X.X/~preview/?returnUrl=http%3A%2F%2Fwww.website.com%2F%3Fq%3Dblabla%26q2%3Dhello' + ); }); }); }); }); - }); diff --git a/test/unit/registry-domain-version-handler.js b/test/unit/registry-domain-version-handler.js index 096557133..0c17901aa 100644 --- a/test/unit/registry-domain-version-handler.js +++ b/test/unit/registry-domain-version-handler.js @@ -3,15 +3,14 @@ const expect = require('chai').expect; describe('registry : domain : version-handler', () => { - const versionHandler = require('../../src/registry/domain/version-handler'); describe('when getting component', () => { - - const get = function(a,b){ return versionHandler.getAvailableVersion(a, b); }; + const get = function(a, b) { + return versionHandler.getAvailableVersion(a, b); + }; describe('when versions not available', () => { - const availableVersions = []; it('should return an undefined when a version is specified', () => { @@ -26,7 +25,6 @@ describe('registry : domain : version-handler', () => { }); describe('when versions available', () => { - const availableVersions = ['1.0.0', '1.0.1', '1.2.3', '2.0.0']; it('should return the latest when a version is not specified', () => { @@ -66,8 +64,12 @@ describe('registry : domain : version-handler', () => { }); }); describe('when only pre release versions available', () => { - - const availableVersions = ['1.0.0-120', '1.0.1-121', '2.0.1-122', '2.0.1-123']; + const availableVersions = [ + '1.0.0-120', + '1.0.1-121', + '2.0.1-122', + '2.0.1-123' + ]; it('should return the latest when a version is not specified', () => { expect(get(undefined, availableVersions)).to.equal('2.0.1-123'); @@ -84,11 +86,15 @@ describe('registry : domain : version-handler', () => { it('should return the version specified', () => { expect(get('1.0.1-121', availableVersions)).to.equal('1.0.1-121'); }); - }); describe('when mix of release and pre-release versions available', () => { - - const availableVersions = ['1.0.0', '1.0.1-121', '1.0.1', '2.0.1-122', '2.0.1-123']; + const availableVersions = [ + '1.0.0', + '1.0.1-121', + '1.0.1', + '2.0.1-122', + '2.0.1-123' + ]; it('should return the latest release version when a version is not specified', () => { expect(get(undefined, availableVersions)).to.equal('1.0.1'); @@ -101,18 +107,17 @@ describe('registry : domain : version-handler', () => { it('should return the version specified', () => { expect(get('1.0.1-121', availableVersions)).to.equal('1.0.1-121'); }); - }); - }); describe('when publishing component', () => { - const existingVersions = ['1.0.0', '1.0.1', '1.0.3', '1.1.0', '2.0.0'], - validate = function(a, b){ return versionHandler.validateNewVersion(a, b); }; + validate = function(a, b) { + return versionHandler.validateNewVersion(a, b); + }; describe('when version already exists', () => { - it('shouldn\'t be valid', () => { + it("shouldn't be valid", () => { expect(validate('1.0.3', existingVersions)).to.be.false; }); }); @@ -134,6 +139,5 @@ describe('registry : domain : version-handler', () => { expect(validate('1.0.2', existingVersions)).to.be.true; }); }); - }); }); diff --git a/test/unit/registry-routes-helpers-apply-default-values.js b/test/unit/registry-routes-helpers-apply-default-values.js index 6559d2f58..c6261d553 100644 --- a/test/unit/registry-routes-helpers-apply-default-values.js +++ b/test/unit/registry-routes-helpers-apply-default-values.js @@ -3,14 +3,13 @@ const expect = require('chai').expect; describe('registry : routes : helpers : apply-default-values', () => { - let parameters; const applyDefaultValues = require('../../src/registry/routes/helpers/apply-default-values'); const apply = function(a, b) { return applyDefaultValues(a, b); }; - describe('when component deesn\'t have optional parameters', () => { + describe("when component deesn't have optional parameters", () => { const componentParameters = { mandatory: { type: 'string', @@ -43,9 +42,12 @@ describe('registry : routes : helpers : apply-default-values', () => { } }; - describe('when request doesn\'t specify values of optional parameters', () => { + describe("when request doesn't specify values of optional parameters", () => { before(() => { - parameters = apply({ mandatory: 'request value' }, componentParameters); + parameters = apply( + { mandatory: 'request value' }, + componentParameters + ); }); it('should return requestParameters', () => { @@ -77,44 +79,73 @@ describe('registry : routes : helpers : apply-default-values', () => { describe('when request specify values of optional parameters', () => { before(() => { - parameters = apply({ mandatory: 'request value', optional: 'custom value', optional2: true }, componentParameters); + parameters = apply( + { + mandatory: 'request value', + optional: 'custom value', + optional2: true + }, + componentParameters + ); }); it('should return requestParameters', () => { - expect(parameters).to.eql({ mandatory: 'request value', optional: 'custom value', optional2: true }); + expect(parameters).to.eql({ + mandatory: 'request value', + optional: 'custom value', + optional2: true + }); }); }); describe('when request specify values of some optional parameters', () => { before(() => { - parameters = apply({ mandatory: 'request value', optional: 'custom value' }, componentParameters); + parameters = apply( + { mandatory: 'request value', optional: 'custom value' }, + componentParameters + ); }); it('should return requestParameters', () => { - expect(parameters).to.eql({ mandatory: 'request value', optional: 'custom value', optional2: false }); + expect(parameters).to.eql({ + mandatory: 'request value', + optional: 'custom value', + optional2: false + }); }); }); - describe('when request doesn\'t specify values of optional parameters', () => { - + describe("when request doesn't specify values of optional parameters", () => { describe('when string parameter is undefined', () => { before(() => { - parameters = apply({ mandatory: 'request value' }, componentParameters); + parameters = apply( + { mandatory: 'request value' }, + componentParameters + ); }); it('should return requestParameters with default values of optional parameters', () => { - expect(parameters).to.eql({ mandatory: 'request value', optional: 'default value of optional parameter', optional2: false + expect(parameters).to.eql({ + mandatory: 'request value', + optional: 'default value of optional parameter', + optional2: false }); }); }); describe('when string parameter is null', () => { before(() => { - parameters = apply({ mandatory: 'request value', optional: null }, componentParameters); + parameters = apply( + { mandatory: 'request value', optional: null }, + componentParameters + ); }); it('should return requestParameters with default values of optional parameters', () => { - expect(parameters).to.eql({ mandatory: 'request value', optional: 'default value of optional parameter', optional2: false + expect(parameters).to.eql({ + mandatory: 'request value', + optional: 'default value of optional parameter', + optional2: false }); }); }); diff --git a/test/unit/registry-routes-helpers-get-available-dependencies.js b/test/unit/registry-routes-helpers-get-available-dependencies.js index b75727ae1..eaed74944 100644 --- a/test/unit/registry-routes-helpers-get-available-dependencies.js +++ b/test/unit/registry-routes-helpers-get-available-dependencies.js @@ -4,32 +4,36 @@ const expect = require('chai').expect; const injectr = require('injectr'); describe('registry : routes : helpers : get-available-dependencies', () => { - - const getAvailableDependencies = injectr('../../src/registry/routes/helpers/get-available-dependencies.js', { - 'builtin-modules': ['url'], - '../../domain/require-wrapper': () => (pathToPackageJson) => ({ - version: '1.2.3', - homepage: `https://${pathToPackageJson.split('\/')[0]}.com/` - }) - }); + const getAvailableDependencies = injectr( + '../../src/registry/routes/helpers/get-available-dependencies.js', + { + 'builtin-modules': ['url'], + '../../domain/require-wrapper': () => pathToPackageJson => ({ + version: '1.2.3', + homepage: `https://${pathToPackageJson.split('/')[0]}.com/` + }) + } + ); describe('happy path', () => { - let result; - before(() => result = getAvailableDependencies(['moment', 'url'])); + before(() => (result = getAvailableDependencies(['moment', 'url']))); it('should map to structured view-model', () => { - expect(result).to.eql([{ - core: false, - name: 'moment', - version: '1.2.3', - link: 'https://moment.com/' - }, { - core: true, - name: 'url', - version: false, - link: 'https://nodejs.org/api/url.html' - }]); + expect(result).to.eql([ + { + core: false, + name: 'moment', + version: '1.2.3', + link: 'https://moment.com/' + }, + { + core: true, + name: 'url', + version: false, + link: 'https://nodejs.org/api/url.html' + } + ]); }); }); }); diff --git a/test/unit/registry-routes-helpers-get-components-history.js b/test/unit/registry-routes-helpers-get-components-history.js index 3d0c64e3e..6bd242f1a 100644 --- a/test/unit/registry-routes-helpers-get-components-history.js +++ b/test/unit/registry-routes-helpers-get-components-history.js @@ -3,12 +3,10 @@ const expect = require('chai').expect; describe('registry : routes : helpers : get-components-history', () => { - const getComponentsHistory = require('../../src/registry/routes/helpers/get-components-history'); const ds = require('../../src/utils/date-stringify'); describe('when components details are provided', () => { - const details = { lastEdit: 1491478634575, components: { @@ -39,7 +37,9 @@ describe('registry : routes : helpers : get-components-history', () => { describe('composing the single history object', () => { it('should return the publish date of a component', () => { - expect(componentsHistory[0].publishDate).to.equal(ds(new Date(1491402224345))); + expect(componentsHistory[0].publishDate).to.equal( + ds(new Date(1491402224345)) + ); }); it('should return the version of a component', () => { @@ -53,7 +53,9 @@ describe('registry : routes : helpers : get-components-history', () => { describe('sorting the entries by date', () => { it('should return the publish date of a component', () => { - expect(new Date(componentsHistory[0].publishDate)).to.be.above(new Date(componentsHistory[1].publishDate)); + expect(new Date(componentsHistory[0].publishDate)).to.be.above( + new Date(componentsHistory[1].publishDate) + ); }); }); }); diff --git a/test/unit/registry-routes-helpers-is-url-discoverable.js b/test/unit/registry-routes-helpers-is-url-discoverable.js index d6386e217..5dc88e965 100644 --- a/test/unit/registry-routes-helpers-is-url-discoverable.js +++ b/test/unit/registry-routes-helpers-is-url-discoverable.js @@ -4,20 +4,22 @@ const expect = require('chai').expect; const injectr = require('injectr'); describe('registry : routes : helpers : is-url-discoverable', () => { - describe('when url responds with application/json', () => { - let result; - before((done) => { - const isDiscoverable = injectr('../../src/registry/routes/helpers/is-url-discoverable.js', { - 'minimal-request': (req, cb) => cb(null, '{}', { - response: { - headers: { - 'content-type': 'application/json; charset=utf-8' - } - } - }) - }); + before(done => { + const isDiscoverable = injectr( + '../../src/registry/routes/helpers/is-url-discoverable.js', + { + 'minimal-request': (req, cb) => + cb(null, '{}', { + response: { + headers: { + 'content-type': 'application/json; charset=utf-8' + } + } + }) + } + ); isDiscoverable('https://baseurl.company.com/', (err, res) => { result = res; @@ -31,18 +33,21 @@ describe('registry : routes : helpers : is-url-discoverable', () => { }); describe('when url responds with text/html', () => { - let result; - before((done) => { - const isDiscoverable = injectr('../../src/registry/routes/helpers/is-url-discoverable.js', { - 'minimal-request': (req, cb) => cb(null, '{}', { - response: { - headers: { - 'content-type': 'text/html; charset=utf-8' - } - } - }) - }); + before(done => { + const isDiscoverable = injectr( + '../../src/registry/routes/helpers/is-url-discoverable.js', + { + 'minimal-request': (req, cb) => + cb(null, '{}', { + response: { + headers: { + 'content-type': 'text/html; charset=utf-8' + } + } + }) + } + ); isDiscoverable('https://baseurl.company.com/', (err, res) => { result = res; diff --git a/test/unit/registry.js b/test/unit/registry.js index d460c9e5f..f83a72b92 100644 --- a/test/unit/registry.js +++ b/test/unit/registry.js @@ -5,14 +5,13 @@ const injectr = require('injectr'); const sinon = require('sinon'); describe('registry', () => { - const repositoryInitStub = sinon.stub(); const deps = { './app-start': sinon.stub(), './domain/events-handler': {}, - 'express': sinon.stub(), - 'http': { + express: sinon.stub(), + http: { createServer: sinon.stub() }, './middleware': { bind: sinon.stub() }, @@ -30,13 +29,16 @@ describe('registry', () => { const Registry = injectr('../../src/registry/index.js', deps); describe('when instanciated', () => { - describe('when options are not valid', () => { - let init; beforeEach(() => { - deps['./domain/validators'].validateRegistryConfiguration.returns({ isValid: false, message: 'blargh' }); - init = function(){ Registry({}); }; + deps['./domain/validators'].validateRegistryConfiguration.returns({ + isValid: false, + message: 'blargh' + }); + init = function() { + Registry({}); + }; }); it('should throw an error', () => { @@ -45,10 +47,11 @@ describe('registry', () => { }); describe('when options are valid', () => { - let registry; beforeEach(() => { - deps['./domain/validators'].validateRegistryConfiguration.returns({ isValid: true }); + deps['./domain/validators'].validateRegistryConfiguration.returns({ + isValid: true + }); deps.express.returns('express instance'); deps['./domain/options-sanitiser'].returns({ port: 3000 }); registry = new Registry({}); @@ -70,13 +73,11 @@ describe('registry', () => { }); describe('when starting it', () => { - describe('when plugins initialiser fails', () => { - let error; - beforeEach((done) => { + beforeEach(done => { deps['./domain/plugins-initialiser'].init.yields('error!'); - registry.start((err) => { + registry.start(err => { error = err; done(); }); @@ -88,15 +89,13 @@ describe('registry', () => { }); describe('when plugins initialiser succeeds', () => { - describe('when repository initialisation fails', () => { - let error; - beforeEach((done) => { + beforeEach(done => { deps['./domain/plugins-initialiser'].init.yields(null, 'ok'); repositoryInitStub.yields('nope'); - registry.start((err) => { + registry.start(err => { error = err; done(); }); @@ -108,16 +107,14 @@ describe('registry', () => { }); describe('when repository initialisation succeeds', () => { - describe('when app fails to start', () => { - let error; - beforeEach((done) => { + beforeEach(done => { deps['./domain/plugins-initialiser'].init.yields(null, 'ok'); repositoryInitStub.yields(null, 'ok'); - deps['./app-start'].yields({ msg: 'I got a problem'}); + deps['./app-start'].yields({ msg: 'I got a problem' }); - registry.start((err) => { + registry.start(err => { error = err; done(); }); @@ -129,11 +126,9 @@ describe('registry', () => { }); describe('when app starts', () => { - describe('when http listener errors', () => { - let error; - beforeEach((done) => { + beforeEach(done => { deps['./domain/plugins-initialiser'].init.yields(null, 'ok'); repositoryInitStub.yields(null, 'ok'); deps['./app-start'].yields(null, 'ok'); @@ -143,7 +138,7 @@ describe('registry', () => { on: sinon.stub() }); - registry.start((err) => { + registry.start(err => { error = err; done(); }); @@ -155,9 +150,8 @@ describe('registry', () => { }); describe('when http listener succeeds', () => { - let error, result; - beforeEach((done) => { + beforeEach(done => { deps['./domain/plugins-initialiser'].init.yields(null, 'ok'); repositoryInitStub.yields(null, 'ok'); deps['./app-start'].yields(null, 'ok'); @@ -185,14 +179,16 @@ describe('registry', () => { }); it('should emit a start event', () => { - expect(deps['./domain/events-handler'].fire.args[0]).to.eql(['start', {}]); + expect(deps['./domain/events-handler'].fire.args[0]).to.eql([ + 'start', + {} + ]); }); }); describe('when http listener emits an error before the listener to start', () => { - let error; - beforeEach((done) => { + beforeEach(done => { deps['./domain/plugins-initialiser'].init.yields(null, 'ok'); repositoryInitStub.yields(null, 'ok'); deps['./app-start'].yields(null, 'ok'); @@ -203,7 +199,7 @@ describe('registry', () => { on: sinon.stub().yields('I failed for some reason') }); - registry.start((err) => { + registry.start(err => { error = err; done(); }); @@ -214,10 +210,13 @@ describe('registry', () => { }); it('should emit an error event', () => { - expect(deps['./domain/events-handler'].fire.args[0]).to.eql(['error', { - code: 'EXPRESS_ERROR', - message: 'I failed for some reason' - }]); + expect(deps['./domain/events-handler'].fire.args[0]).to.eql([ + 'error', + { + code: 'EXPRESS_ERROR', + message: 'I failed for some reason' + } + ]); }); }); }); diff --git a/test/unit/utils-date-stringify.js b/test/unit/utils-date-stringify.js index 6e35b4356..e5a25aeec 100644 --- a/test/unit/utils-date-stringify.js +++ b/test/unit/utils-date-stringify.js @@ -4,7 +4,6 @@ const expect = require('chai').expect; const sinon = require('sinon'); describe('utils : dateStringify', () => { - const dateStringified = require('../../src/utils/date-stringify'); describe('when the date is provided', () => { diff --git a/test/unit/utils-get-file-info.js b/test/unit/utils-get-file-info.js index ce142a738..2ce392e85 100644 --- a/test/unit/utils-get-file-info.js +++ b/test/unit/utils-get-file-info.js @@ -3,7 +3,6 @@ const expect = require('chai').expect; describe('utils : getFileInfo', () => { - const getFileInfo = require('../../src/utils/get-file-info'); describe('when extension is .js', () => { diff --git a/test/unit/utils-pad-zero.js b/test/unit/utils-pad-zero.js index 44ec1074a..8f7ff201c 100644 --- a/test/unit/utils-pad-zero.js +++ b/test/unit/utils-pad-zero.js @@ -3,7 +3,6 @@ const expect = require('chai').expect; describe('utils : padZero', () => { - const padZero = require('../../src/utils/pad-zero'); describe('when the correct parameters are provided', () => {