@unito/integration-cli
Version:
Integration CLI
88 lines (87 loc) • 3.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const test_1 = require("@oclif/test");
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const sinon_1 = tslib_1.__importDefault(require("sinon"));
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const GlobalConfiguration = tslib_1.__importStar(require("../../src/resources/globalConfiguration"));
const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/integrationsPlatform"));
const errors_1 = require("../../src/errors");
describe('Login', () => {
beforeEach(() => {
const execSyncStub = sinon_1.default.stub(child_process_1.default, 'execSync');
execSyncStub.onCall(0).returns('1');
execSyncStub.onCall(1).returns('2');
execSyncStub.onCall(2).returns('ok');
sinon_1.default.stub(IntegrationsPlatform, 'setEnvironment');
sinon_1.default.stub(IntegrationsPlatform, 'setApiKey');
});
afterEach(() => {
sinon_1.default.restore();
});
test_1.test
.stdout()
.stub(GlobalConfiguration, 'read', stub => stub.returns({}))
.stub(inquirer_1.default, 'prompt', stub => stub.resolves({ apiKey: 'foo' }))
.stub(IntegrationsPlatform, 'getProfile', stub => stub.returns({ email: 'a@b.com' }))
.stub(GlobalConfiguration, 'write', stub => stub.returns({}))
.command(['login'])
.it('logins to the platform - default', ctx => {
(0, test_1.expect)(ctx.stdout).to.contain('Hello');
});
test_1.test
.stdout()
.stub(GlobalConfiguration, 'read', stub => stub.returns({}))
.stub(inquirer_1.default, 'prompt', stub => stub.resolves({ apiKey: 'foo' }))
.stub(IntegrationsPlatform, 'getProfile', stub => stub.returns({ email: 'a@b.com' }))
.stub(GlobalConfiguration, 'write', stub => stub.returns({}))
.command(['login', '--environment=local'])
.it('logins to the platform - local', ctx => {
(0, test_1.expect)(ctx.stdout).to.contain('Hello');
});
test_1.test
.stdout()
.stub(GlobalConfiguration, 'read', stub => stub.returns({}))
.stub(inquirer_1.default, 'prompt', stub => stub.resolves({ apiKey: 'foo' }))
.stub(IntegrationsPlatform, 'getProfile', stub => stub.returns({ email: 'a@b.com' }))
.stub(GlobalConfiguration, 'write', stub => stub.returns({}))
.command(['login', '--environment=staging'])
.it('logins to the platform - staging', ctx => {
(0, test_1.expect)(ctx.stdout).to.contain('Hello');
});
test_1.test
.stdout()
.stub(GlobalConfiguration, 'read', stub => stub.throws(new Error('boom!')))
.command(['login'])
.catch(ctx => {
(0, test_1.expect)(ctx.message).to.equal('boom!');
})
.it('handles configuration error');
test_1.test
.stdout()
.stub(GlobalConfiguration, 'read', stub => stub.returns({}))
.stub(inquirer_1.default, 'prompt', stub => stub.rejects())
.command(['login'])
.catch(ctx => {
(0, test_1.expect)(ctx.name).to.equal('Error');
})
.it('handles input error');
test_1.test
.stdout()
.stub(GlobalConfiguration, 'read', stub => stub.returns({}))
.stub(inquirer_1.default, 'prompt', stub => stub.resolves({ apiKey: 'foo' }))
.stub(IntegrationsPlatform, 'getProfile', stub => stub.rejects())
.command(['login'])
.catch(ctx => {
(0, test_1.expect)(ctx.name).to.equal('Error');
})
.it('handles platform error');
test_1.test
.stdout()
.stderr()
.stub(GlobalConfiguration, 'read', stub => stub.throws(new errors_1.ConfigurationMalformed()))
.command(['login'])
.exit(-1)
.it('handle managed exception');
});