UNPKG

@unito/integration-cli

Version:

Integration CLI

85 lines (84 loc) 4.1 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 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 integrations_1 = require("../helpers/integrations"); describe('activity', () => { const integration = (0, integrations_1.generateIntegration)(); let getIntegrationEventsStub; beforeEach(() => { sinon_1.default.stub(IntegrationResource, 'validateIsIntegrationDirectory'); sinon_1.default.stub(IntegrationsPlatform, 'setEnvironment'); sinon_1.default.stub(IntegrationsPlatform, 'setApiKey'); getIntegrationEventsStub = sinon_1.default.stub(IntegrationsPlatform, 'getIntegrationEvents').resolves([ { date: '1', text: 'This is a foo', title: 'foo', tags: ['a', 'b', 'c'] }, { date: '2', text: 'This is a bar', title: 'bar', tags: ['x', 'y', 'z'] }, ]); sinon_1.default.stub(IntegrationConfiguration, 'getConfiguration').resolves({ name: 'foo' }); }); afterEach(() => { sinon_1.default.restore(); }); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.resolves(integration)) .command(['activity']) .it('displays activity', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('foo'); (0, test_1.expect)(ctx.stdout).to.contains('bar'); }); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.resolves(integration)) .command(['activity', '--number', '1']) .it('displays only specified number of activity entries', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('foo'); (0, test_1.expect)(ctx.stdout).to.contains('bar'); sinon_1.default.assert.calledWithExactly(getIntegrationEventsStub, 1, { $from: undefined, limit: 1 }); }); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.resolves(integration)) .command(['activity', '--environment', 'staging']) .it('displays activity - staging', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('foo'); (0, test_1.expect)(ctx.stdout).to.contains('bar'); }); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.resolves(integration)) .command(['activity', '--environment', 'local']) .it('displays activity - local', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('foo'); (0, test_1.expect)(ctx.stdout).to.contains('bar'); }); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.throws(new Error())) .command(['activity']) .catch(error => { (0, test_1.expect)(error.message).to.equal('EEXIT: -1'); }) .it('handles unpublished integration'); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.resolves(integration)) .command(['activity', '--follow']) .it('displays activity - follow', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('foo'); (0, test_1.expect)(ctx.stdout).to.contains('bar'); }); test_1.test .stdout() .stub(IntegrationsPlatform, 'getIntegrationByName', stub => stub.resolves(integration)) .command(['activity', '--follow', '--number', '1']) .it('displays activity - follow', ctx => { (0, test_1.expect)(ctx.stdout).to.contains('foo'); (0, test_1.expect)(ctx.stdout).to.contains('bar'); sinon_1.default.assert.calledWithExactly(getIntegrationEventsStub, 1, { $from: undefined, limit: 1 }); }); });