Skip to content

Commit

Permalink
chore(test): add tests for doctor command
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Aug 11, 2017
1 parent a41855d commit 016ba10
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions test/unit/commands/doctor/command-spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
'use strict';
const expect = require('chai').expect;
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();

const modulePath = '../../../../lib/commands/doctor/index';
const errors = require('../../../../lib/errors');

// TODO: remove line once tests are implemented
require(modulePath);
describe('Unit: Commands > Doctor', function () {
it('defaults to running install checks if no check is supplied', function () {
const listrStub = sinon.stub().resolves();
const successStub = sinon.stub();
const ui = {listr: listrStub, success: successStub};

describe.skip('Unit: Commands > Doctor', function () {});
const DoctorCommand = proxyquire(modulePath, {
'./checks/install': {installChecks: true}
});
const instance = new DoctorCommand(ui, {system: true});

return instance.run({}).then(() => {
expect(listrStub.calledOnce).to.be.true;
expect(listrStub.args[0][0]).to.deep.equal({installChecks: true});
expect(listrStub.args[0][1]).to.deep.equal({
ui: ui,
system: {system: true}
});
expect(successStub.calledOnce).to.be.true;
expect(successStub.args[0][0]).to.match(/checks passed/);
});
});

it('rejects if checks category not found', function () {
const failStub = sinon.stub();
const DoctorCommand = require(modulePath);
const instance = new DoctorCommand({fail: failStub}, {system: true});

return instance.run({category: 'nonexistent'}).then(() => {
expect(false, 'error should have been thrown').to.be.true;
}).catch((error) => {
expect(error).to.not.exist;
expect(failStub.calledOnce).to.be.true;
expect(failStub.args[0][0]).to.match(/Invalid category/);
});
});

it('logs message if a doctor check fails with a SystemError', function () {
const listrStub = sinon.stub().rejects(new errors.SystemError({message: 'aaaahhhh'}));
const logStub = sinon.stub();
const DoctorCommand = require(modulePath);
const instance = new DoctorCommand({listr: listrStub, log: logStub});

return instance.run({}).then(() => {
expect(listrStub.calledOnce).to.be.true;
expect(logStub.calledTwice).to.be.true;
expect(logStub.args[0][0]).to.match(/Checks failed/);
expect(logStub.args[1][0]).to.match(/aaaahhhh/);
});
});

it('rejects if rejected error is not a system error', function () {
const listrStub = sinon.stub().rejects(new Error('aaaahhhh'));
const DoctorCommand = require(modulePath);
const instance = new DoctorCommand({listr: listrStub});

return instance.run({}).then(() => {
expect(false, 'error should have been thrown').to.be.true;
}).catch((error) => {
expect(error).to.be.an.instanceof(Error);
expect(error.message).to.equal('aaaahhhh');
});
});
});

0 comments on commit 016ba10

Please sign in to comment.