"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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-promise/tape"));
const grpc = __importStar(require("@grpc/grpc-js"));
const public_api_1 = require("../../../main/typescript/public-api");
const public_api_2 = require("../../../main/typescript/public-api");
const public_api_3 = require("../../../main/typescript/public-api");
const public_api_4 = require("../../../main/typescript/public-api");
const run_time_error_cjs_1 = require("run-time-error-cjs");
const testCase = "API server: runs gRPC TS-proto web services";
const logLevel = "TRACE";
(0, tape_1.default)(testCase, async (t) => {
    var _a;
    const configService = new public_api_1.ConfigService();
    const apiSrvOpts = await configService.newExampleConfig();
    apiSrvOpts.authorizationProtocol = public_api_2.AuthorizationProtocol.NONE;
    apiSrvOpts.configFile = "";
    apiSrvOpts.logLevel = logLevel;
    apiSrvOpts.apiCorsDomainCsv = "*";
    apiSrvOpts.apiPort = 0;
    apiSrvOpts.grpcPort = 0;
    apiSrvOpts.crpcPort = 0;
    apiSrvOpts.cockpitPort = 0;
    apiSrvOpts.grpcMtlsEnabled = false;
    apiSrvOpts.apiTlsEnabled = false;
    apiSrvOpts.plugins = [];
    const config = await configService.newExampleConfigConvict(apiSrvOpts);
    const apiServer = new public_api_1.ApiServer({
        config: config.getProperties(),
    });
    tape_1.default.onFinish(async () => await apiServer.shutdown());
    const startResponse = apiServer.start();
    await t.doesNotReject(startResponse, "failed to start API server with dynamic plugin imports configured for it...");
    t.ok(startResponse, "startResponse truthy OK");
    const addressInfoGrpc = (await startResponse).addressInfoGrpc;
    const { address, port } = addressInfoGrpc;
    const grpcHostAndPort = `${address}:${port}`;
    const apiClient = new public_api_3.default_service.org.hyperledger.cactus.cmd_api_server.DefaultServiceClient(grpcHostAndPort, grpc.credentials.createInsecure());
    t.ok(apiClient, "apiClient truthy OK");
    const responsePromise = new Promise((resolve, reject) => {
        apiClient.GetHealthCheckV1(new public_api_4.empty.google.protobuf.Empty(), (error, response) => {
            if (error) {
                reject(error);
            }
            else if (response) {
                resolve(response);
            }
            else {
                throw new run_time_error_cjs_1.RuntimeError("No error, nor response received.");
            }
        });
    });
    await t.doesNotReject(responsePromise, "No error in healthcheck OK");
    const res = await responsePromise;
    const resHc = res === null || res === void 0 ? void 0 : res.toObject();
    t.ok(resHc, `healthcheck response truthy OK`);
    t.ok(resHc === null || resHc === void 0 ? void 0 : resHc.createdAt, `resHc.createdAt truthy OK`);
    t.ok(resHc === null || resHc === void 0 ? void 0 : resHc.memoryUsage, `resHc.memoryUsage truthy OK`);
    t.ok((_a = resHc === null || resHc === void 0 ? void 0 : resHc.memoryUsage) === null || _a === void 0 ? void 0 : _a.rss, `resHc.memoryUsage.rss truthy OK`);
    t.ok(resHc === null || resHc === void 0 ? void 0 : resHc.success, `resHc.success truthy OK`);
    t.end();
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JwYy1wcm90by1nZW4tdHMtY2xpZW50LWhlYWx0aGNoZWNrLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIu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