UNPKG

@unito/integration-cli

Version:

Integration CLI

80 lines (79 loc) 3.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const test_1 = require("@oclif/test"); const sinon_1 = tslib_1.__importDefault(require("sinon")); const GlobalConfiguration = tslib_1.__importStar(require("../../src/resources/globalConfiguration")); const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/integrationsPlatform")); const IntegrationResource = tslib_1.__importStar(require("../../src/resources/integrations")); const IntegrationConfiguration = tslib_1.__importStar(require("../../src/resources/configuration")); const inquirer_1 = tslib_1.__importDefault(require("inquirer")); describe('encrypt', () => { beforeEach(() => { sinon_1.default.stub(IntegrationResource, 'validateIsIntegrationDirectory'); sinon_1.default.stub(IntegrationsPlatform, 'setEnvironment'); sinon_1.default.stub(IntegrationsPlatform, 'setApiKey'); sinon_1.default.stub(IntegrationsPlatform, 'encryptData').resolves({ encryptedData: 'mySuperEncryptedData' }); sinon_1.default.stub(inquirer_1.default, 'prompt').resolves({ data: 'mySuperData' }); sinon_1.default.stub(IntegrationConfiguration, 'getConfiguration').resolves({ name: 'integrationName' }); sinon_1.default.stub(IntegrationsPlatform, 'getProfile').resolves({ id: 1, createdAt: '', updatedAt: '', archivedAt: null, email: 'foo@bar.com', defaultUnitoOrganizationId: null, role: 'developer', apiKey: 'foo', termsAcceptedAt: null, }); }); afterEach(() => { sinon_1.default.restore(); }); test_1.test .stdout() .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' })) .command(['encrypt']) .it('encrypts data - default', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('Encrypted Data:'); }); test_1.test .stdout() .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' })) .command(['encrypt', '--sensitive']) .it('encrypts data - sensitive', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('Encrypted Data:'); }); test_1.test .stdout() .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKeyLocal: 'foo' })) .command(['encrypt', '--environment=local']) .it('encrypts data - local', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('Encrypted Data:'); }); test_1.test .stdout() .stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKeyStaging: 'foo' })) .command(['encrypt', '--environment', 'staging']) .it('encrypts data - staging', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('Encrypted Data:'); }); test_1.test .stdout() .stderr() .stub(GlobalConfiguration, 'read', stub => stub.returns({})) .command(['encrypt']) .exit(-1) .it('missing api key', ctx => { (0, test_1.expect)(ctx.stderr).to.contain('Your API key is not set!\nMake sure to run the login command first'); }); test_1.test .stdout() .stub(GlobalConfiguration, 'read', stub => stub.throws(new Error('boom!'))) .command(['encrypt']) .catch(ctx => { (0, test_1.expect)(ctx.message).to.equal('boom!'); }) .it('handles configuration error'); });