"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");
const cactus_core_api_1 = require("@hyperledger/cactus-core-api");
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 config = new cactus_core_api_1.Configuration({
            basePath: apiHost,
            baseOptions: {
                timeout: 2000,
            },
        });
        const provider = new typescript_1.DefaultConsortiumProvider({
            logLevel,
            apiClient: new cactus_plugin_consortium_manual_1.DefaultApi(config),
        });
        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 config = new cactus_core_api_1.Configuration({
            basePath: "https://httpbin.org/status/400",
        });
        const provider = new typescript_1.DefaultConsortiumProvider({
            logLevel,
            apiClient: new cactus_plugin_consortium_manual_1.DefaultApi(config),
        });
        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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