if (!createClientStub.calledOnce || !createClientStub.calledWith(expectedOptions)) { throw new Error('Client was not created with correct options') if (!uploadFileStub.calledOnce || !uploadFileStub.calledWith(expectedOptions)) { throw new Error('uploadFile was not called with correct options') if (!path.calledOnce || !path.calledWith('path', job)) { throw new Error('Path function was not called')
it('Removes http config', function () { const sudoExp = new RegExp(/(available|enabled)\/ghost\.dev\.conf/); const {exists, inst, restartNginx, ui} = stub(); exists.callsFake(val => !testEs(val)); return inst.uninstall(instance).then(() => { expect(ui.sudo.calledTwice).to.be.true; expect(ui.sudo.args[0][0]).to.match(sudoExp); expect(ui.sudo.args[1][0]).to.match(sudoExp); expect(restartNginx.calledOnce).to.be.true; }); });
it('isSupported fn', function () { const shell = sinon.stub(execa, 'shellSync'); const inst = new Nginx({}, {}, {}, '/some/dir'); expect(inst.isSupported()).to.be.true; expect(shell.calledOnce).to.be.true; shell.reset(); shell.throws(new Error()); expect(inst.isSupported()).to.be.false; expect(shell.calledOnce).to.be.true; });
it('returns parseOptions if prompt is false', function () { const {configure, parseOptions, getPrompts} = fake(); return configure({}, {config: true}, {prompt: true}, 'development', false).then(() => { expect(parseOptions.calledOnce).to.be.true; expect(getPrompts.called).to.be.false; expect(parseOptions.args[0]).to.deep.equal([ {config: true}, 'development', {prompt: true} ]); }); });
it('constructs instance', function () { const instanceStub = sinon.stub().returns({instance: true}); const ConfigCommand = require(modulePath); const config = new ConfigCommand({}, {getInstance: instanceStub}); expect(instanceStub.calledOnce).to.be.true; expect(config.instance).to.deep.equal({instance: true}); });
it('skips if GHOST_CLI_PRE_CHECKS env var is false', function () { const homedir = sinon.stub(os, 'homedir').returns('/home/ghost'); const exists = sinon.stub(fs, 'existsSync').returns(true); process.env.GHOST_CLI_PRE_CHECKS = 'false'; return getTasks({}, {}, {platform: {linux: true}}).then(([,task]) => { expect(task.enabled()).to.be.false; expect(homedir.calledOnce).to.be.true; expect(exists.calledOnce).to.be.true; }); });
it('fails when config.js present', function () { const existsStub = sinon.stub(fs, 'existsSync'); existsStub.withArgs(sinon.match(/config\.js/)).returns(true); const errorStub = sinon.stub(console, 'error'); expect(checkValidInstall('test')).to.equal(false); expect(existsStub.calledOnce).to.be.true; expect(errorStub.calledOnce).to.be.true; expect(existsStub.args[0][0]).to.match(/config\.js/); expect(errorStub.args[0][0]).to.match(/Ghost-CLI only works with Ghost versions >= 1\.0\.0/); });
it('sets config url to new port if port is different then what url is set to', function () { const parseOptions = fake(); const config = new Config('config.json'); const saveStub = sinon.stub(config, 'save'); config.set('url', 'http://localhost:2368'); config.set('server.port', 2369); return parseOptions(config, 'development', {}).then(() => { expect(config.get('url')).to.equal('http://localhost:2369/'); expect(config.get('server.port')).to.equal(2369); expect(saveStub.calledOnce).to.be.true; }); });
it('skips checking parent folder permissions if local process manager is used', function () { const accessStub = sinon.stub(fs, 'access').resolves(); const checkDirectoryStub = sinon.stub().resolves(); const installFolderPermissions = proxyquire(modulePath, { './check-directory': checkDirectoryStub }).task; return installFolderPermissions({instance: {process: {name: 'local'}}}).then(() => { expect(accessStub.calledOnce).to.be.true; expect(checkDirectoryStub.called).to.be.false; }); });
it('doesn\'t filter if no categories passed', function () { return instance.run({skipInstanceCheck: true}).then(() => { expect(listrStub.calledOnce).to.be.true; expect(hookStub.calledOnce).to.be.true; const tasks = listrStub.args[0][0]; expect(tasks).to.be.an('array'); expect(tasks.length).to.equal(3); }); });
it('success works', function () { const successStub = sinon.stub(process, 'send'); const LocalProcess = require(modulePath); const instance = new LocalProcess({}, {}, {}); instance.success(); expect(successStub.calledOnce).to.be.true; expect(successStub.calledWithExactly({started: true})).to.be.true; });
it('appends sbin to path if platform is linux', function () { const execaStub = sinon.stub(execa, 'shell').resolves(); const ctx = {system: {platform: {linux: true}}}; return mysqlCheck.task(ctx).then(() => { expect(execaStub.calledOnce).to.be.true; expect(execaStub.args[0][1].env).to.exist; expect(execaStub.args[0][1].env.PATH).to.match(/^\/usr\/sbin:/); }); });
it('isInstalled checks if /etc/letsencrypt/acme.sh exists', function () { const existsStub = sinon.stub().returns(true); const acme = proxyquire(modulePath, { 'fs-extra': {existsSync: existsStub} }); const result = acme.isInstalled(); expect(result).to.be.true; expect(existsStub.calledOnce).to.be.true; expect(existsStub.calledWithExactly('/etc/letsencrypt/acme.sh')).to.be.true; });
it('skips checking parent folder permissions if os is not linux', function () { const accessStub = sinon.stub(fs, 'access').resolves(); const checkDirectoryStub = sinon.stub().resolves(); const installFolderPermissions = proxyquire(modulePath, { './check-directory': checkDirectoryStub }).task; const ctx = {system: {platform: {linux: false}}}; return installFolderPermissions(ctx).then(() => { expect(accessStub.calledOnce).to.be.true; expect(checkDirectoryStub.called).to.be.false; }); });
it('filters with multiple categories passed', function () { return instance.run({skipInstanceCheck: true, categories: ['install', 'start']}).then(() => { expect(listrStub.calledOnce).to.be.true; expect(hookStub.calledOnce).to.be.true; const tasks = listrStub.args[0][0]; expect(tasks).to.be.an('array'); expect(tasks.length).to.equal(3); }); });