"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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_1 = require("run-time-error");
const testCase = "API server: runs gRPC TS-proto web services";
const logLevel = "TRACE";
tape_1.default(testCase, async (t) => {
    var _a;
    const configService = new public_api_1.ConfigService();
    const apiSrvOpts = configService.newExampleConfig();
    apiSrvOpts.authorizationProtocol = public_api_2.AuthorizationProtocol.NONE;
    apiSrvOpts.configFile = "";
    apiSrvOpts.logLevel = logLevel;
    apiSrvOpts.apiCorsDomainCsv = "*";
    apiSrvOpts.apiPort = 0;
    apiSrvOpts.grpcPort = 0;
    apiSrvOpts.cockpitPort = 0;
    apiSrvOpts.grpcMtlsEnabled = false;
    apiSrvOpts.apiTlsEnabled = false;
    apiSrvOpts.plugins = [];
    const config = 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_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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ3JwYy1wcm90by1nZW4tdHMtY2xpZW50LWhlYWx0aGNoZWNrLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvdGVzdC90eXBlc2NyaXB0L3VuaXQvZ3JwYy1wcm90by1nZW4tdHMtY2xpZW50LWhlYWx0aGNoZWNrLnRlc3QudHMiXSwibmFtZ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