"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tape_1 = __importDefault(require("tape"));
const cactus_plugin_consortium_manual_1 = require("@hyperledger/cactus-plugin-consortium-manual");
const cactus_common_1 = require("@hyperledger/cactus-common");
const typescript_1 = require("../../../main/typescript");
tape_1.default("Reports failures with meaningful information", async (t) => {
    const logLevel = "TRACE";
    tape_1.default("Handles timeout/connection refusal transparently", async (t2) => {
        const httpServer1 = await cactus_common_1.Servers.startOnPreferredPort(4050);
        tape_1.default.onFinish(() => cactus_common_1.Servers.shutdown(httpServer1));
        const addressInfo1 = httpServer1.address();
        const apiHost = `http://${addressInfo1.address}:${addressInfo1.port}`;
        const provider = new typescript_1.DefaultConsortiumProvider({
            logLevel,
            apiClient: new cactus_plugin_consortium_manual_1.DefaultApi({
                basePath: apiHost,
                baseOptions: {
                    timeout: 2000,
                },
            }),
        });
        try {
            await provider.get();
            t2.fail("Provider.get() did not throw despite API errors.");
        }
        catch (ex) {
            t2.ok(ex, "Thrown error truthy OK");
            t2.ok(ex.message, "Thrown error.message truthy OK");
            t2.equal(typeof ex.message, "string", "Thrown error.message type string OK");
            t2.true(ex.message.includes("timeout"), "Has timeout in msg OK");
        }
        t2.end();
    });
    tape_1.default("Handles 4xx transparently", async (t2) => {
        const provider = new typescript_1.DefaultConsortiumProvider({
            logLevel,
            apiClient: new cactus_plugin_consortium_manual_1.DefaultApi({
                basePath: "https://httpbin.org/status/400",
            }),
        });
        try {
            await provider.get();
            t2.fail("Provider.get() did not throw despite API errors.");
        }
        catch (ex) {
            t2.ok(ex, "Thrown error truthy OK");
            t2.ok(ex.message, "Thrown error.message truthy OK");
            t2.equal(typeof ex.message, "string", "Thrown error.message type string OK");
            t2.true(ex.message.includes("status code 404"), "Has Status Code in msg OK");
        }
        t2.end();
    });
    t.end();
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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