"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const errors_1 = require("../../../src/providers/chain-state/external/adapters/errors");
describe('AdapterError', function () {
    it('should extend Error with providerName, code, and affectsHealth', function () {
        const err = new errors_1.AdapterError('TestProvider', errors_1.AdapterErrorCode.UPSTREAM, 'something broke');
        (0, chai_1.expect)(err).to.be.instanceOf(Error);
        (0, chai_1.expect)(err.name).to.equal('AdapterError');
        (0, chai_1.expect)(err.providerName).to.equal('TestProvider');
        (0, chai_1.expect)(err.code).to.equal(errors_1.AdapterErrorCode.UPSTREAM);
        (0, chai_1.expect)(err.affectsHealth).to.equal(true);
        (0, chai_1.expect)(err.message).to.include('something broke');
    });
    it('should use code as message when detail is omitted', function () {
        const err = new errors_1.AdapterError('P', errors_1.AdapterErrorCode.RATE_LIMIT);
        (0, chai_1.expect)(err.message).to.equal('P: RATE_LIMIT');
    });
    describe('affectsHealth derived from code', function () {
        const cases = [
            { code: errors_1.AdapterErrorCode.INVALID_REQUEST, affectsHealth: false },
            { code: errors_1.AdapterErrorCode.NOT_FOUND, affectsHealth: false },
            { code: errors_1.AdapterErrorCode.AUTH, affectsHealth: true },
            { code: errors_1.AdapterErrorCode.RATE_LIMIT, affectsHealth: true },
            { code: errors_1.AdapterErrorCode.TIMEOUT, affectsHealth: true },
            { code: errors_1.AdapterErrorCode.UPSTREAM, affectsHealth: true },
        ];
        for (const { code, affectsHealth } of cases) {
            it(`code=${code} → affectsHealth=${affectsHealth}`, function () {
                const err = new errors_1.AdapterError('P', code);
                (0, chai_1.expect)(err.affectsHealth).to.equal(affectsHealth);
            });
        }
    });
    describe('AllProvidersUnavailableError', function () {
        it('should extend Error but NOT AdapterError', function () {
            const err = new errors_1.AllProvidersUnavailableError('getTransaction', 'ETH', 'mainnet');
            (0, chai_1.expect)(err).to.be.instanceOf(Error);
            (0, chai_1.expect)(err).to.not.be.instanceOf(errors_1.AdapterError);
            (0, chai_1.expect)(err.name).to.equal('AllProvidersUnavailableError');
            (0, chai_1.expect)(err.message).to.include('ETH:mainnet');
        });
    });
});
//# sourceMappingURL=errors.test.js.map