|
| 1 | +'use strict'; |
| 2 | +const expect = require('chai').expect; |
| 3 | +const sinon = require('sinon'); |
| 4 | + |
| 5 | +const RestartCommand = require('../../../lib/commands/restart'); |
| 6 | +const Instance = require('../../../lib/instance'); |
| 7 | + |
| 8 | +describe('Unit: Command > Restart', function () { |
| 9 | + it('throws error if instance is not running', function () { |
| 10 | + class TestInstance extends Instance { |
| 11 | + get running() { return false; } |
| 12 | + } |
| 13 | + let testInstance = new TestInstance(); |
| 14 | + |
| 15 | + let command = new RestartCommand({}, { |
| 16 | + getInstance: () => testInstance |
| 17 | + }); |
| 18 | + |
| 19 | + return command.run().then(() => { |
| 20 | + throw new Error('Run method should have thrown'); |
| 21 | + }).catch((error) => { |
| 22 | + expect(error.message).to.match(/instance is not currently running/); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('calls process restart method if instance is running', function () { |
| 27 | + let restartStub = sinon.stub().resolves(); |
| 28 | + class TestInstance extends Instance { |
| 29 | + get running() { return true; } |
| 30 | + get process() { return { restart: restartStub }; } |
| 31 | + } |
| 32 | + let testInstance = new TestInstance(); |
| 33 | + let loadRunEnvStub = sinon.stub(testInstance, 'loadRunningEnvironment'); |
| 34 | + let runStub = sinon.stub().resolves(); |
| 35 | + |
| 36 | + let command = new RestartCommand({ |
| 37 | + run: runStub |
| 38 | + }, { |
| 39 | + environment: 'testing', |
| 40 | + getInstance: () => testInstance |
| 41 | + }); |
| 42 | + |
| 43 | + return command.run().then(() => { |
| 44 | + expect(loadRunEnvStub.calledOnce).to.be.true; |
| 45 | + expect(loadRunEnvStub.args[0][0]).to.be.true; |
| 46 | + expect(restartStub.calledOnce).to.be.true; |
| 47 | + expect(restartStub.args[0]).to.deep.equal([process.cwd(), 'testing']); |
| 48 | + expect(runStub.calledOnce).to.be.true; |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments