@unito/integration-cli
Version:
Integration CLI
88 lines (87 loc) • 4.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const sinon_1 = tslib_1.__importDefault(require("sinon"));
const path_1 = tslib_1.__importDefault(require("path"));
const errors_1 = require("../src/errors");
const configuration_1 = require("../src/resources/configuration");
const publish_1 = tslib_1.__importDefault(require("../src/commands/publish"));
describe('handleError', () => {
class DummyCommand extends publish_1.default {
logToStderr = () => { };
}
let command;
let stdErrStub;
beforeEach(() => {
command = new DummyCommand([], {});
stdErrStub = sinon_1.default.stub(command, 'logToStderr');
});
afterEach(() => {
sinon_1.default.restore();
});
it('handles NoIntegrationFoundError', () => {
const error = new errors_1.NoIntegrationFoundError();
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
(0, strict_1.default)(stdErrStub.calledTwice);
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('Your directory does not seem to contain an integration :('));
(0, strict_1.default)(stdErrStub.secondCall.args[0].includes('Make sure you are in the right directory'));
});
it('handles NoConfigurationFileError', () => {
const error = new errors_1.NoConfigurationFileError();
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
(0, strict_1.default)(stdErrStub.calledTwice);
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('This command requires a configuration file for your integration :('));
strict_1.default.equal(stdErrStub.secondCall.args[0], `This file should be located at ${chalk_1.default.yellowBright(path_1.default.relative(process.cwd(), (0, configuration_1.getConfigurationPath)()))}.`);
});
it('should return false for unrecognized error', () => {
const error = new Error('Unrecognized error');
const handled = (0, errors_1.handleError)(command, error);
strict_1.default.equal(handled, false);
strict_1.default.equal(stdErrStub.called, false);
});
it('handles ConfigurationInvalid', () => {
const error = new errors_1.ConfigurationInvalid('VAR_NAME', 'details', 'prettyDetails');
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
(0, strict_1.default)(stdErrStub.calledThrice);
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright(`Your ${chalk_1.default.yellowBright(path_1.default.basename((0, configuration_1.getConfigurationPath)()))} is invalid!`));
strict_1.default.equal(stdErrStub.thirdCall.args[0], 'prettyDetails');
});
it('handles NoRefreshTokenError', () => {
const error = new errors_1.NoRefreshTokenError();
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
(0, strict_1.default)(stdErrStub.calledOnce);
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('No refresh token found in your configuration file'));
});
it('handles FailedToRetrieveAccessTokenError', () => {
const error = new errors_1.FailedToRetrieveAccessTokenError('Credentials invalid');
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
(0, strict_1.default)(stdErrStub.calledThrice);
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('Failed to retrieve access token'));
strict_1.default.equal(stdErrStub.thirdCall.args[0], 'Credentials invalid');
});
it('handles InvalidRequestContentTypeError', () => {
const error = new errors_1.InvalidRequestContentTypeError('Invalid content type');
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
(0, strict_1.default)(stdErrStub.calledThrice);
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('Invalid request content type'));
strict_1.default.equal(stdErrStub.thirdCall.args[0], 'Invalid content type');
});
it('handles DecryptionAuthenticationError', () => {
const error = new errors_1.DecryptionAuthenticationError('secrets');
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
});
it('handles EntryDecryptionError', () => {
const error = new errors_1.EntryDecryptionError('key', 'staging');
const handled = (0, errors_1.handleError)(command, error);
(0, strict_1.default)(handled);
});
});