"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("jest-extended");
const http_status_codes_1 = require("http-status-codes");
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");
describe("DefaultConsortiumProvider", () => {
    const logLevel = "SILENT";
    const log = cactus_common_1.LoggerProvider.getOrCreate({
        label: "default-consortium-provider.test.ts",
        level: logLevel,
    });
    let httpServer1;
    let apiClientConfig;
    beforeAll(async () => {
        httpServer1 = await cactus_common_1.Servers.startOnPreferredPort(4050);
        const { address, port } = httpServer1.address();
        const apiHost = `http://${address}:${port}`;
        log.info("API host: %s", apiHost);
        apiClientConfig = new cactus_core_api_1.Configuration({
            basePath: apiHost,
            baseOptions: {
                timeout: 2000,
            },
        });
    });
    afterAll(async () => {
        await cactus_common_1.Servers.shutdown(httpServer1);
    });
    it("Handles timeout/connection refusal transparently", async () => {
        const provider = new typescript_1.DefaultConsortiumProvider({
            logLevel,
            apiClient: new cactus_plugin_consortium_manual_1.DefaultApi(apiClientConfig),
        });
        expect(provider.get()).rejects.toMatchObject({
            message: expect.stringMatching(new RegExp(`connect ECONNREFUSED (.*):4050`)),
        });
    });
    it("Handles 4xx transparently", async () => {
        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),
        });
        expect(provider.get()).rejects.toMatchObject({
            code: "ERR_BAD_REQUEST",
            message: expect.stringContaining("status code " + http_status_codes_1.StatusCodes.NOT_FOUND),
        });
    });
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdC1jb25zb3J0aXVtLXByb3ZpZGVyLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8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