@unito/integration-cli
Version:
Integration CLI
228 lines (227 loc) • 12.2 kB
JavaScript
;
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 child_process_1 = tslib_1.__importDefault(require("child_process"));
const IntegrationDebugger = tslib_1.__importStar(require("@unito/integration-debugger/dist/src/resources/configuration"));
const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/integrationsPlatform"));
const IntegrationsPlatformResource = tslib_1.__importStar(require("../../src/resources/integrationsPlatform"));
const ConfigurationResource = tslib_1.__importStar(require("../../src/resources/configuration"));
const IntegrationResource = tslib_1.__importStar(require("../../src/resources/integrations"));
const CredentialResource = tslib_1.__importStar(require("../../src/resources/credentials"));
const DecryptionResource = tslib_1.__importStar(require("../../src/resources/decryption"));
const styles_1 = require("../helpers/styles");
describe('Dev', () => {
const debuggerConfiguration = {
...IntegrationDebugger.getDefaultConfiguration(),
credentialPayload: {
key: 'value',
encryptedToken: `decrypted-me`,
},
};
const cliConfiguration = {
name: 'a',
baseUrl: 'b',
secrets: {
secret: 'encryptedSecret',
},
testAccounts: {
development: {
key: 'value',
encryptedToken: `${ConfigurationResource.ENCRYPTION_PREFIX}decrypt-me`,
},
},
};
let execSyncStub;
let spawnStub;
beforeEach(() => {
process.env.NODE_MODULES_FOLDER = '/path/to/node_modules';
sinon_1.default.stub(IntegrationsPlatform, 'decryptData').resolves({ decryptedData: 'decrypted-me' });
sinon_1.default.stub(IntegrationsPlatformResource, 'validateAuthenticated');
sinon_1.default.stub(IntegrationDebugger, 'readConfiguration').resolves(debuggerConfiguration);
execSyncStub = sinon_1.default.stub(child_process_1.default, 'execSync');
spawnStub = sinon_1.default.stub(child_process_1.default, 'spawn').returns({ on: (..._args) => { } });
});
afterEach(() => {
process.env.NODE_MODULES_FOLDER = undefined;
sinon_1.default.restore();
});
test_1.test
.stdout()
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.command(['dev'])
.it('launches the debugger', () => {
(0, test_1.expect)(execSyncStub.getCall(0).args.at(0).split(' ').slice(0, 2)).to.deep.equal(['npm', 'install']);
(0, test_1.expect)(spawnStub.getCall(0).args.at(0).split(' ').slice(0, 2)).to.deep.equal(['node']);
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns(cliConfiguration))
.command(['dev'])
.it('decrypts credentials', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"key":"value","encryptedToken":"decrypted-me","unitoCredentialId":"development","unitoUserId":"development"}');
});
test_1.test
.stdout()
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.command(['dev'])
.it('decrypt secrets correctly', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--secrets-payload={"secret":"encryptedSecret"}');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.throws(new Error('boom!')))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.command(['dev'])
.catch(ctx => {
(0, test_1.expect)(ctx.message).to.equal('boom!');
})
.it('handle exception');
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.command(['dev', '--verbose'])
.it('verbose mode', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--verbose');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.command(['dev', '--crawlMode=sample'])
.it('crawlMode - sample', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--operation-collection-items-per-page=10');
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--operation-collection-follow-next-pages=false');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.command(['dev', '--crawlMode=single'])
.it('crawlMode - single', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--operation-collection-items-per-page=1');
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--operation-collection-follow-next-pages=false');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.command(['dev', '--checks', 'foo,bar'])
.it('checks', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--checks=foo,bar');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({ ...cliConfiguration, graphRelativeUrl: 'foo' }))
.command(['dev'])
.it('overrides --graph-relative-url', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--graph-relative-url=foo');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
...cliConfiguration,
credentialAccountRelativeUrl: 'foo',
}))
.command(['dev'])
.it('overrides --credential-account-relative-url', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-account-relative-url=foo');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
...cliConfiguration,
webhookParsingRelativeUrl: 'foo',
}))
.command(['dev'])
.it('overrides --webhook-parsing-relative-url', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--webhook-parsing-relative-url=foo');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
...cliConfiguration,
webhookSubscriptionsRelativeUrl: 'foo',
}))
.command(['dev'])
.it('overrides --webhook-subscriptions-relative-url', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--webhook-subscriptions-relative-url=foo');
});
test_1.test
.stdout()
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
...cliConfiguration,
webhookAcknowledgeRelativeUrl: 'bar',
}))
.command(['dev'])
.it('overrides --webhook-acknowledge-relative-url', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--webhook-acknowledge-relative-url=bar');
});
test_1.test
.stdout()
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(CredentialResource, 'fetchCredential', stub => stub.resolves({ payload: { from: 'credential' }, id: '123', unitoUserId: '456' }))
.command(['dev', '--credential-id=123'])
.it('credential-id', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"from":"credential","unitoCredentialId":"123","unitoUserId":"456"}');
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--read-only');
});
test_1.test
.stdout()
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({}))
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(CredentialResource, 'fetchCredential', stub => stub.resolves({ payload: { from: 'credential' }, id: '123', unitoUserId: '456' }))
.command(['dev', '--credential-id=123', '--no-read-only'])
.it('credential-id && read-only', () => {
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"from":"credential","unitoCredentialId":"123","unitoUserId":"456"}');
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.not.include('--read-only');
});
test_1.test
.stdout()
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(CredentialResource, 'fetchCredential', stub => stub.resolves({ payload: { from: 'credential' }, id: '123', unitoUserId: '456' }))
.stub(DecryptionResource, 'decryptEntries', stub => stub
.onFirstCall()
.resolves({ successful: {}, failed: [] })
.onSecondCall()
.resolves({ successful: {}, failed: [] })
.onThirdCall()
.resolves({ successful: { success: 'a' }, failed: ['failure'] }))
.command(['dev'])
.it('environment variables', ctx => {
(0, test_1.expect)(ctx.stdout).to.contain((0, styles_1.uncolorize)('Could not decrypt the environment variable failure.'));
(0, test_1.expect)(spawnStub.getCall(0).args.at(2).env.success).to.equal('a');
(0, test_1.expect)(spawnStub.getCall(0).args.at(2).env.failure).to.be.undefined;
});
test_1.test
.stdout()
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
.stub(CredentialResource, 'fetchCredential', stub => stub.resolves({ payload: { from: 'credential' }, unitoCredentialId: '123', unitoUserId: '456' }))
.stub(DecryptionResource, 'decryptEntries', stub => stub
.onFirstCall()
.resolves({ successful: {}, failed: [] })
.onSecondCall()
.resolves({ successful: {}, failed: [] })
.onThirdCall()
.resolves({ successful: { success: 'a' }, failed: ['failure'] }))
.env({ failure: 'b' })
.command(['dev'])
.it('override environment variables', ctx => {
(0, test_1.expect)(ctx.stdout).to.not.contain((0, styles_1.uncolorize)('Could not decrypt the environment variable failure.'));
(0, test_1.expect)(spawnStub.getCall(0).args.at(2).env.success).to.equal('a');
(0, test_1.expect)(spawnStub.getCall(0).args.at(2).env.failure).to.equal('b');
});
});