"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const slack_1 = require("./slack");
describe('getSlackErrorCode', () => {
    it('returns the error code from a Slack API error shape', () => {
        expect((0, slack_1.getSlackErrorCode)({ data: { error: 'invalid_blocks' } })).toBe('invalid_blocks');
    });
    it('returns undefined for non-Slack errors', () => {
        expect((0, slack_1.getSlackErrorCode)(new Error('boom'))).toBeUndefined();
        expect((0, slack_1.getSlackErrorCode)(undefined)).toBeUndefined();
        expect((0, slack_1.getSlackErrorCode)(null)).toBeUndefined();
        expect((0, slack_1.getSlackErrorCode)('string')).toBeUndefined();
        expect((0, slack_1.getSlackErrorCode)({ data: {} })).toBeUndefined();
    });
});
describe('isUnrecoverableSlackError', () => {
    it('returns true for known unrecoverable codes', () => {
        expect((0, slack_1.isUnrecoverableSlackError)({ data: { error: 'channel_not_found' } })).toBe(true);
        expect((0, slack_1.isUnrecoverableSlackError)({ data: { error: 'invalid_auth' } })).toBe(true);
    });
    it('returns false for recoverable or unknown codes', () => {
        expect((0, slack_1.isUnrecoverableSlackError)({ data: { error: 'invalid_blocks' } })).toBe(false);
        expect((0, slack_1.isUnrecoverableSlackError)(new Error('boom'))).toBe(false);
    });
});
describe('isSlackMessageTooLongError', () => {
    it('returns true for oversized-message codes', () => {
        expect((0, slack_1.isSlackMessageTooLongError)({ data: { error: 'msg_too_long' } })).toBe(true);
        expect((0, slack_1.isSlackMessageTooLongError)({
            data: { error: 'msg_blocks_too_long' },
        })).toBe(true);
    });
    it('returns false for other Slack errors and non-Slack errors', () => {
        expect((0, slack_1.isSlackMessageTooLongError)({ data: { error: 'invalid_blocks' } })).toBe(false);
        expect((0, slack_1.isSlackMessageTooLongError)(new Error('boom'))).toBe(false);
        expect((0, slack_1.isSlackMessageTooLongError)(undefined)).toBe(false);
    });
});
describe('isSlackRateLimitedError', () => {
    it('returns true for the @slack/web-api rate limit error', () => {
        const error = Object.assign(new Error('rate limited'), {
            code: 'slack_webapi_rate_limited_error',
        });
        expect((0, slack_1.isSlackRateLimitedError)(error)).toBe(true);
    });
    it('returns false for other errors', () => {
        expect((0, slack_1.isSlackRateLimitedError)(new Error('boom'))).toBe(false);
        expect((0, slack_1.isSlackRateLimitedError)({ data: { error: 'invalid_blocks' } })).toBe(false);
    });
});
describe('translateSlackError', () => {
    it.each(Object.entries(slack_1.SLACK_USER_FACING_ERROR_MESSAGES))('translates %s to its user-facing message', (slackErrorCode, message) => {
        expect((0, slack_1.translateSlackError)({ data: { error: slackErrorCode } })).toEqual({
            error: message,
            slackErrorCode,
        });
    });
    it('returns null for unknown Slack error codes', () => {
        expect((0, slack_1.translateSlackError)({ data: { error: 'rate_limited' } })).toBeNull();
        expect((0, slack_1.translateSlackError)({ data: { error: 'something_new' } })).toBeNull();
    });
    it('returns null for non-Slack errors', () => {
        expect((0, slack_1.translateSlackError)(new Error('boom'))).toBeNull();
        expect((0, slack_1.translateSlackError)(undefined)).toBeNull();
        expect((0, slack_1.translateSlackError)(null)).toBeNull();
        expect((0, slack_1.translateSlackError)('invalid_blocks')).toBeNull();
    });
});
//# sourceMappingURL=slack.test.js.map