"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts_jest_1 = require("@golevelup/ts-jest");
const request_1 = require("../request");
const DataFixture_1 = require("../../../../__tests__/fixtures/shared/DataFixture");
const LogService_1 = __importDefault(require("../../../app/service/log/LogService"));
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
const ValidationError_1 = require("../../../core/validation/ValidationError");
const SecurityFixture_1 = require("../../../../__tests__/fixtures/shared/SecurityFixture");
const Security_1 = require("../../../domain/context/security/Security");
const ContractId_1 = __importDefault(require("../../../domain/context/contract/ContractId"));
const RegulationType_1 = require("../../../domain/context/factory/RegulationType");
const BigDecimal_1 = __importDefault(require("../../../domain/context/shared/BigDecimal"));
const SecurityDate_1 = require("../../../domain/context/shared/SecurityDate");
const Equity_1 = __importDefault(require("./Equity"));
const EquityFixture_1 = require("../../../../__tests__/fixtures/equity/EquityFixture");
const CreateEquityCommand_1 = require("../../../app/usecase/command/equity/create/CreateEquityCommand");
const DividendType_1 = require("../../../domain/context/equity/DividendType");
const GetEquityDetailsQuery_1 = require("../../../app/usecase/query/equity/get/getEquityDetails/GetEquityDetailsQuery");
const SetVotingRightsCommand_1 = require("../../../app/usecase/command/equity/votingRights/set/SetVotingRightsCommand");
const CancelVotingCommand_1 = require("../../../app/usecase/command/equity/votingRights/cancel/CancelVotingCommand");
const GetVotingForQuery_1 = require("../../../app/usecase/query/equity/votingRights/getVotingFor/GetVotingForQuery");
const GetVotingQuery_1 = require("../../../app/usecase/query/equity/votingRights/getVoting/GetVotingQuery");
const GetVotingCountQuery_1 = require("../../../app/usecase/query/equity/votingRights/getVotingCount/GetVotingCountQuery");
const SetScheduledBalanceAdjustmentCommand_1 = require("../../../app/usecase/command/equity/balanceAdjustments/setScheduledBalanceAdjustment/SetScheduledBalanceAdjustmentCommand");
const GetScheduledBalanceAdjustmentQuery_1 = require("../../../app/usecase/query/equity/balanceAdjustments/getScheduledBalanceAdjustment/GetScheduledBalanceAdjustmentQuery");
const GetScheduledBalanceAdjustmentsCountQuery_1 = require("../../../app/usecase/query/equity/balanceAdjustments/getScheduledBalanceAdjustmentCount/GetScheduledBalanceAdjustmentsCountQuery");
const CancelScheduledBalanceAdjustmentCommand_1 = require("../../../app/usecase/command/equity/balanceAdjustments/cancelScheduledBalanceAdjustment/CancelScheduledBalanceAdjustmentCommand");
const GetVotingHoldersQuery_1 = require("../../../app/usecase/query/equity/votingRights/getVotingHolders/GetVotingHoldersQuery");
const GetTotalVotingHoldersQuery_1 = require("../../../app/usecase/query/equity/votingRights/getTotalVotingHolders/GetTotalVotingHoldersQuery");
const CreateTrexSuiteEquityCommand_1 = require("../../../app/usecase/command/equity/createTrexSuite/CreateTrexSuiteEquityCommand");
describe("Equity", () => {
    let commandBusMock;
    let queryBusMock;
    let networkServiceMock;
    let createEquityRequest;
    let getEquityDetailsRequest;
    let setVotingRightsRequest;
    let cancelVotingRequest;
    let getVotingRightsForRequest;
    let getVotingRightsRequest;
    let getAllVotingRightsRequest;
    let setScheduledBalanceAdjustmentRequest;
    let getScheduledBalanceAdjustmentCountRequest;
    let getScheduledBalanceAdjustmentRequest;
    let cancelScheduledBalanceAdjustmentRequest;
    let getAllScheduledBalanceAdjustmentsRequest;
    let getVotingHoldersRequest;
    let getTotalVotingHoldersRequest;
    let createTrexSuiteEquityRequest;
    let handleValidationSpy;
    const transactionId = DataFixture_1.TransactionIdFixture.create().id;
    const security = new Security_1.Security(SecurityFixture_1.SecurityPropsFixture.create());
    const factoryAddress = DataFixture_1.HederaIdPropsFixture.create().value;
    const resolverAddress = DataFixture_1.HederaIdPropsFixture.create().value;
    beforeEach(() => {
        commandBusMock = (0, ts_jest_1.createMock)();
        queryBusMock = (0, ts_jest_1.createMock)();
        handleValidationSpy = jest.spyOn(ValidatedArgs_1.default, "handleValidation");
        networkServiceMock = (0, ts_jest_1.createMock)({
            configuration: {
                factoryAddress: factoryAddress,
                resolverAddress: resolverAddress,
            },
        });
        jest.spyOn(LogService_1.default, "logError").mockImplementation(() => { });
        Equity_1.default.commandBus = commandBusMock;
        Equity_1.default.queryBus = queryBusMock;
        Equity_1.default.networkService = networkServiceMock;
    });
    afterEach(() => {
        jest.resetAllMocks();
        jest.restoreAllMocks();
    });
    describe("create", () => {
        createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create());
        it("should create equity successfully", async () => {
            const expectedResponse = {
                securityId: new ContractId_1.default(DataFixture_1.HederaIdPropsFixture.create().value),
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            queryBusMock.execute.mockResolvedValue({
                security: security,
            });
            const result = await Equity_1.default.create(createEquityRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("CreateEquityRequest", createEquityRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateEquityCommand_1.CreateEquityCommand(expect.objectContaining({
                name: createEquityRequest.name,
                symbol: createEquityRequest.symbol,
                isin: createEquityRequest.isin,
                decimals: createEquityRequest.decimals,
                isWhiteList: createEquityRequest.isWhiteList,
                isControllable: createEquityRequest.isControllable,
                arePartitionsProtected: createEquityRequest.arePartitionsProtected,
                clearingActive: createEquityRequest.clearingActive,
                internalKycActivated: createEquityRequest.internalKycActivated,
                isMultiPartition: createEquityRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createEquityRequest.numberOfShares),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createEquityRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createEquityRequest.regulationSubType),
                isCountryControlListWhiteList: createEquityRequest.isCountryControlListWhiteList,
                countries: createEquityRequest.countries,
                info: createEquityRequest.info,
            }), createEquityRequest.votingRight, createEquityRequest.informationRight, createEquityRequest.liquidationRight, createEquityRequest.subscriptionRight, createEquityRequest.conversionRight, createEquityRequest.redemptionRight, createEquityRequest.putRight, DividendType_1.CastDividendType.fromNumber(createEquityRequest.dividendRight), createEquityRequest.currency, createEquityRequest.nominalValue, createEquityRequest.nominalValueDecimals, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createEquityRequest.configId, createEquityRequest.configVersion, createEquityRequest.diamondOwnerAccount, createEquityRequest.externalPausesIds, createEquityRequest.externalControlListsIds, createEquityRequest.externalKycListsIds, createEquityRequest.complianceId, createEquityRequest.identityRegistryId));
            expect(result).toEqual(expect.objectContaining({
                security: security,
                transactionId: expectedResponse.transactionId,
            }));
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("CreateEquityRequest", createEquityRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateEquityCommand_1.CreateEquityCommand(expect.objectContaining({
                name: createEquityRequest.name,
                symbol: createEquityRequest.symbol,
                isin: createEquityRequest.isin,
                decimals: createEquityRequest.decimals,
                isWhiteList: createEquityRequest.isWhiteList,
                isControllable: createEquityRequest.isControllable,
                arePartitionsProtected: createEquityRequest.arePartitionsProtected,
                clearingActive: createEquityRequest.clearingActive,
                internalKycActivated: createEquityRequest.internalKycActivated,
                isMultiPartition: createEquityRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createEquityRequest.numberOfShares),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createEquityRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createEquityRequest.regulationSubType),
                isCountryControlListWhiteList: createEquityRequest.isCountryControlListWhiteList,
                countries: createEquityRequest.countries,
                info: createEquityRequest.info,
            }), createEquityRequest.votingRight, createEquityRequest.informationRight, createEquityRequest.liquidationRight, createEquityRequest.subscriptionRight, createEquityRequest.conversionRight, createEquityRequest.redemptionRight, createEquityRequest.putRight, DividendType_1.CastDividendType.fromNumber(createEquityRequest.dividendRight), createEquityRequest.currency, createEquityRequest.nominalValue, createEquityRequest.nominalValueDecimals, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createEquityRequest.configId, createEquityRequest.configVersion, createEquityRequest.diamondOwnerAccount, createEquityRequest.externalPausesIds, createEquityRequest.externalControlListsIds, createEquityRequest.externalKycListsIds, createEquityRequest.complianceId, createEquityRequest.identityRegistryId));
        });
        it("should throw error if name is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({ name: "" }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if symbol is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                symbol: "",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if isin is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                isin: "",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if decimals is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                decimals: 2.85,
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if diamondOwnerAccount is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                diamondOwnerAccount: "invalid",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if dividendRight is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                dividendRight: 100,
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if currency is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                currency: "invalid",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if numberOfShares is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                numberOfShares: "invalid",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if nominalValue is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                nominalValue: "invalid",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if regulationType is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                regulationType: 5,
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if regulationSubType is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                regulationSubType: 5,
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if configId is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                configId: "invalid",
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalPausesIds is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                externalPausesIds: ["invalid"],
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlListsIds is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                externalControlListsIds: ["invalid"],
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycListsIds is invalid", async () => {
            createEquityRequest = new request_1.CreateEquityRequest(EquityFixture_1.CreateEquityRequestFixture.create({
                externalKycListsIds: ["invalid"],
            }));
            await expect(Equity_1.default.create(createEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getEquityDetails", () => {
        getEquityDetailsRequest = new request_1.GetEquityDetailsRequest(EquityFixture_1.GetEquityDetailsRequestFixture.create());
        it("should get equity details successfully", async () => {
            const expectedResponse = {
                equity: EquityFixture_1.EquityDetailsFixture.create(),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getEquityDetails(getEquityDetailsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetEquityDetailsRequest", getEquityDetailsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetEquityDetailsQuery_1.GetEquityDetailsQuery(getEquityDetailsRequest.equityId));
            expect(result).toEqual(expect.objectContaining({
                votingRight: expectedResponse.equity.votingRight,
                informationRight: expectedResponse.equity.informationRight,
                liquidationRight: expectedResponse.equity.liquidationRight,
                subscriptionRight: expectedResponse.equity.subscriptionRight,
                conversionRight: expectedResponse.equity.conversionRight,
                redemptionRight: expectedResponse.equity.redemptionRight,
                putRight: expectedResponse.equity.putRight,
                dividendRight: DividendType_1.CastDividendType.toNumber(expectedResponse.equity.dividendRight),
                currency: expectedResponse.equity.currency,
                nominalValue: expectedResponse.equity.nominalValue.toString(),
                nominalValueDecimals: expectedResponse.equity.nominalValueDecimals,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getEquityDetails(getEquityDetailsRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetEquityDetailsRequest", getEquityDetailsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetEquityDetailsQuery_1.GetEquityDetailsQuery(getEquityDetailsRequest.equityId));
        });
        it("should throw error if equityId is invalid", async () => {
            getEquityDetailsRequest = new request_1.GetEquityDetailsRequest({
                ...EquityFixture_1.GetEquityDetailsRequestFixture.create(),
                equityId: "invalid",
            });
            await expect(Equity_1.default.getEquityDetails(getEquityDetailsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("setVotingRights", () => {
        setVotingRightsRequest = new request_1.SetVotingRightsRequest(EquityFixture_1.SetVotingRightsRequestFixture.create());
        it("should set voting rights successfully", async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.setVotingRights(setVotingRightsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("SetVotingRightsRequest", setVotingRightsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetVotingRightsCommand_1.SetVotingRightsCommand(setVotingRightsRequest.securityId, setVotingRightsRequest.recordTimestamp, setVotingRightsRequest.data));
            expect(result).toEqual(expectedResponse);
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.setVotingRights(setVotingRightsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("SetVotingRightsRequest", setVotingRightsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetVotingRightsCommand_1.SetVotingRightsCommand(setVotingRightsRequest.securityId, setVotingRightsRequest.recordTimestamp, setVotingRightsRequest.data));
        });
        it("should throw error if securityId is invalid", async () => {
            setVotingRightsRequest = new request_1.SetVotingRightsRequest({
                ...EquityFixture_1.SetVotingRightsRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.setVotingRights(setVotingRightsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if recordTimestamp is invalid", async () => {
            setVotingRightsRequest = new request_1.SetVotingRightsRequest({
                ...EquityFixture_1.SetVotingRightsRequestFixture.create(),
                recordTimestamp: (Math.ceil(new Date().getTime() / 1000) - 100).toString(),
            });
            await expect(Equity_1.default.setVotingRights(setVotingRightsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if data is invalid", async () => {
            setVotingRightsRequest = new request_1.SetVotingRightsRequest({
                ...EquityFixture_1.SetVotingRightsRequestFixture.create(),
                data: "invalid",
            });
            await expect(Equity_1.default.setVotingRights(setVotingRightsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getVotingRightsFor", () => {
        getVotingRightsForRequest = new request_1.GetVotingRightsForRequest(EquityFixture_1.GetVotingRightsForRequestFixture.create());
        it("should get voting rights for successfully", async () => {
            const expectedResponse = {
                tokenBalance: new BigDecimal_1.default(BigInt(10)),
                decimals: 1,
                isDisabled: false,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getVotingRightsFor(getVotingRightsForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetVotingRightsForRequest", getVotingRightsForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingForQuery_1.GetVotingForQuery(getVotingRightsForRequest.targetId, getVotingRightsForRequest.securityId, getVotingRightsForRequest.votingId));
            expect(result).toEqual(expect.objectContaining({
                tokenBalance: expectedResponse.tokenBalance.toString(),
                decimals: expectedResponse.decimals.toString(),
                isDisabled: expectedResponse.isDisabled,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getVotingRightsFor(getVotingRightsForRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetVotingRightsForRequest", getVotingRightsForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingForQuery_1.GetVotingForQuery(getVotingRightsForRequest.targetId, getVotingRightsForRequest.securityId, getVotingRightsForRequest.votingId));
        });
        it("should throw error if targetId is invalid", async () => {
            getVotingRightsForRequest = new request_1.GetVotingRightsForRequest({
                ...EquityFixture_1.GetVotingRightsForRequestFixture.create(),
                targetId: "invalid",
            });
            await expect(Equity_1.default.getVotingRightsFor(getVotingRightsForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if securityId is invalid", async () => {
            getVotingRightsForRequest = new request_1.GetVotingRightsForRequest({
                ...EquityFixture_1.GetVotingRightsForRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.getVotingRightsFor(getVotingRightsForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if votingId is invalid", async () => {
            getVotingRightsForRequest = new request_1.GetVotingRightsForRequest({
                ...EquityFixture_1.GetVotingRightsForRequestFixture.create(),
                votingId: 0,
            });
            await expect(Equity_1.default.getVotingRightsFor(getVotingRightsForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getVotingRights", () => {
        getVotingRightsRequest = new request_1.GetVotingRightsRequest(EquityFixture_1.GetVotingRightsRequestFixture.create());
        it("should get voting rights successfully", async () => {
            const expectedResponse = {
                voting: EquityFixture_1.VotingRightsFixture.create(),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getVotingRights(getVotingRightsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetVotingRightsRequest", getVotingRightsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingQuery_1.GetVotingQuery(getVotingRightsRequest.securityId, getVotingRightsRequest.votingId));
            expect(result).toEqual(expect.objectContaining({
                votingId: getVotingRightsRequest.votingId,
                recordDate: new Date(expectedResponse.voting.recordTimeStamp * SecurityDate_1.ONE_THOUSAND),
                data: expectedResponse.voting.data,
                isDisabled: expectedResponse.voting.isDisabled,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getVotingRights(getVotingRightsRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetVotingRightsRequest", getVotingRightsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingQuery_1.GetVotingQuery(getVotingRightsRequest.securityId, getVotingRightsRequest.votingId));
        });
        it("should throw error if securityId is invalid", async () => {
            getVotingRightsRequest = new request_1.GetVotingRightsRequest({
                ...EquityFixture_1.GetVotingRightsRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.getVotingRights(getVotingRightsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if votingId is invalid", async () => {
            getVotingRightsRequest = new request_1.GetVotingRightsRequest({
                ...EquityFixture_1.GetVotingRightsRequestFixture.create(),
                votingId: -1,
            });
            await expect(Equity_1.default.getVotingRights(getVotingRightsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAllVotingRights", () => {
        getAllVotingRightsRequest = new request_1.GetAllVotingRightsRequest(EquityFixture_1.GetAllVotingRightsRequestFixture.create());
        it("should get all voting rights successfully", async () => {
            const expectedResponse = {
                payload: 1,
            };
            const expectedResponse2 = {
                voting: EquityFixture_1.VotingRightsFixture.create(),
            };
            queryBusMock.execute.mockResolvedValueOnce(expectedResponse).mockResolvedValueOnce(expectedResponse2);
            const result = await Equity_1.default.getAllVotingRights(getAllVotingRightsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAllVotingRightsRequest", getAllVotingRightsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(2);
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(1, new GetVotingCountQuery_1.GetVotingCountQuery(getAllVotingRightsRequest.securityId));
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(2, new GetVotingQuery_1.GetVotingQuery(getAllVotingRightsRequest.securityId, 1));
            expect(result).toEqual(expect.arrayContaining([
                {
                    votingId: 1,
                    recordDate: new Date(expectedResponse2.voting.recordTimeStamp * SecurityDate_1.ONE_THOUSAND),
                    data: expectedResponse2.voting.data,
                    isDisabled: expectedResponse2.voting.isDisabled,
                },
            ]));
        });
        it("should return empty array if count is 0", async () => {
            const expectedResponse = {
                payload: 0,
            };
            queryBusMock.execute.mockResolvedValueOnce(expectedResponse);
            const result = await Equity_1.default.getAllVotingRights(getAllVotingRightsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAllVotingRightsRequest", getAllVotingRightsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingCountQuery_1.GetVotingCountQuery(getAllVotingRightsRequest.securityId));
            expect(result).toStrictEqual([]);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getAllVotingRights(getAllVotingRightsRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAllVotingRightsRequest", getAllVotingRightsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingCountQuery_1.GetVotingCountQuery(getAllVotingRightsRequest.securityId));
        });
    });
    describe("setScheduledBalanceAdjustment", () => {
        setScheduledBalanceAdjustmentRequest = new request_1.SetScheduledBalanceAdjustmentRequest(EquityFixture_1.SetScheduledBalanceAdjustmentRequestFixture.create());
        it("should set scheduled balance adjustment successfully", async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.setScheduledBalanceAdjustment(setScheduledBalanceAdjustmentRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("SetScheduledBalanceAdjustmentRequest", setScheduledBalanceAdjustmentRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetScheduledBalanceAdjustmentCommand_1.SetScheduledBalanceAdjustmentCommand(setScheduledBalanceAdjustmentRequest.securityId, setScheduledBalanceAdjustmentRequest.executionDate, setScheduledBalanceAdjustmentRequest.factor, setScheduledBalanceAdjustmentRequest.decimals));
            expect(result).toEqual(expectedResponse);
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.setScheduledBalanceAdjustment(setScheduledBalanceAdjustmentRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("SetScheduledBalanceAdjustmentRequest", setScheduledBalanceAdjustmentRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetScheduledBalanceAdjustmentCommand_1.SetScheduledBalanceAdjustmentCommand(setScheduledBalanceAdjustmentRequest.securityId, setScheduledBalanceAdjustmentRequest.executionDate, setScheduledBalanceAdjustmentRequest.factor, setScheduledBalanceAdjustmentRequest.decimals));
        });
        it("should throw error if securityId is invalid", async () => {
            setScheduledBalanceAdjustmentRequest = new request_1.SetScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.SetScheduledBalanceAdjustmentRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.setScheduledBalanceAdjustment(setScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if executionDate is invalid", async () => {
            setScheduledBalanceAdjustmentRequest = new request_1.SetScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.SetScheduledBalanceAdjustmentRequestFixture.create(),
                executionDate: (Math.ceil(new Date().getTime() / 1000) - 100).toString(),
            });
            await expect(Equity_1.default.setScheduledBalanceAdjustment(setScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if factor is invalid", async () => {
            setScheduledBalanceAdjustmentRequest = new request_1.SetScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.SetScheduledBalanceAdjustmentRequestFixture.create(),
                factor: "invalid",
            });
            await expect(Equity_1.default.setScheduledBalanceAdjustment(setScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if decimals is invalid", async () => {
            setScheduledBalanceAdjustmentRequest = new request_1.SetScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.SetScheduledBalanceAdjustmentRequestFixture.create(),
                decimals: "invalid",
            });
            await expect(Equity_1.default.setScheduledBalanceAdjustment(setScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("cancelScheduledBalanceAdjustment", () => {
        cancelScheduledBalanceAdjustmentRequest = new request_1.CancelScheduledBalanceAdjustmentRequest(EquityFixture_1.CancelScheduledBalanceAdjustmentRequestFixture.create());
        it("should set scheduled balance adjustment successfully", async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.cancelScheduledBalanceAdjustment(cancelScheduledBalanceAdjustmentRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("CancelScheduledBalanceAdjustmentRequest", cancelScheduledBalanceAdjustmentRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CancelScheduledBalanceAdjustmentCommand_1.CancelScheduledBalanceAdjustmentCommand(cancelScheduledBalanceAdjustmentRequest.securityId, cancelScheduledBalanceAdjustmentRequest.balanceAdjustmentId));
            expect(result).toEqual(expectedResponse);
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.cancelScheduledBalanceAdjustment(cancelScheduledBalanceAdjustmentRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("CancelScheduledBalanceAdjustmentRequest", cancelScheduledBalanceAdjustmentRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CancelScheduledBalanceAdjustmentCommand_1.CancelScheduledBalanceAdjustmentCommand(cancelScheduledBalanceAdjustmentRequest.securityId, cancelScheduledBalanceAdjustmentRequest.balanceAdjustmentId));
        });
        it("should throw error if securityId is invalid", async () => {
            cancelScheduledBalanceAdjustmentRequest = new request_1.CancelScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.CancelScheduledBalanceAdjustmentRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.cancelScheduledBalanceAdjustment(cancelScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getScheduledBalanceAdjustment", () => {
        getScheduledBalanceAdjustmentRequest = new request_1.GetScheduledBalanceAdjustmentRequest(EquityFixture_1.GetScheduledBalanceAdjustmentRequestFixture.create());
        it("should get scheduled balance adjustment for successfully", async () => {
            const expectedResponse = {
                scheduleBalanceAdjustment: EquityFixture_1.ScheduledBalanceAdjustmentFixture.create(),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getScheduledBalanceAdjustment(getScheduledBalanceAdjustmentRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetScheduledBalanceAdjustmentRequest", getScheduledBalanceAdjustmentRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetScheduledBalanceAdjustmentQuery_1.GetScheduledBalanceAdjustmentQuery(getScheduledBalanceAdjustmentRequest.securityId, getScheduledBalanceAdjustmentRequest.balanceAdjustmentId));
            expect(result).toEqual(expect.objectContaining({
                id: getScheduledBalanceAdjustmentRequest.balanceAdjustmentId,
                executionDate: new Date(expectedResponse.scheduleBalanceAdjustment.executionTimeStamp * SecurityDate_1.ONE_THOUSAND),
                factor: expectedResponse.scheduleBalanceAdjustment.factor.toString(),
                decimals: expectedResponse.scheduleBalanceAdjustment.decimals.toString(),
                isDisabled: expectedResponse.scheduleBalanceAdjustment.isDisabled,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getScheduledBalanceAdjustment(getScheduledBalanceAdjustmentRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetScheduledBalanceAdjustmentRequest", getScheduledBalanceAdjustmentRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetScheduledBalanceAdjustmentQuery_1.GetScheduledBalanceAdjustmentQuery(getScheduledBalanceAdjustmentRequest.securityId, getScheduledBalanceAdjustmentRequest.balanceAdjustmentId));
        });
        it("should throw error if securityId is invalid", async () => {
            getScheduledBalanceAdjustmentRequest = new request_1.GetScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.GetScheduledBalanceAdjustmentRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.getScheduledBalanceAdjustment(getScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if balanceAdjustmentId is invalid", async () => {
            getScheduledBalanceAdjustmentRequest = new request_1.GetScheduledBalanceAdjustmentRequest({
                ...EquityFixture_1.GetScheduledBalanceAdjustmentRequestFixture.create(),
                balanceAdjustmentId: -1,
            });
            await expect(Equity_1.default.getScheduledBalanceAdjustment(getScheduledBalanceAdjustmentRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getScheduledBalanceAdjustmentsCount", () => {
        getScheduledBalanceAdjustmentCountRequest = new request_1.GetScheduledBalanceAdjustmentCountRequest(EquityFixture_1.GetScheduledBalanceAdjustmentCountRequestFixture.create());
        it("should get scheduled balance adjustments count successfully", async () => {
            const expectedResponse = {
                payload: 1,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getScheduledBalanceAdjustmentsCount(getScheduledBalanceAdjustmentCountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetScheduledBalanceAdjustmentCountRequest", getScheduledBalanceAdjustmentCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetScheduledBalanceAdjustmentsCountQuery_1.GetScheduledBalanceAdjustmentCountQuery(getScheduledBalanceAdjustmentCountRequest.securityId));
            expect(result).toEqual(expectedResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getScheduledBalanceAdjustmentsCount(getScheduledBalanceAdjustmentCountRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetScheduledBalanceAdjustmentCountRequest", getScheduledBalanceAdjustmentCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetScheduledBalanceAdjustmentsCountQuery_1.GetScheduledBalanceAdjustmentCountQuery(getScheduledBalanceAdjustmentCountRequest.securityId));
        });
        it("should throw error if securityId is invalid", async () => {
            getScheduledBalanceAdjustmentCountRequest = new request_1.GetScheduledBalanceAdjustmentCountRequest({
                ...EquityFixture_1.GetScheduledBalanceAdjustmentCountRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.getScheduledBalanceAdjustmentsCount(getScheduledBalanceAdjustmentCountRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAllScheduledBalanceAdjustments", () => {
        getAllScheduledBalanceAdjustmentsRequest = new request_1.GetAllScheduledBalanceAdjustmentsRequest(EquityFixture_1.GetAllScheduledBalanceAdjustmentsRequestFixture.create());
        it("should get all scheduled balance adjustments successfully", async () => {
            const expectedResponse = {
                payload: 1,
            };
            const expectedResponse2 = {
                scheduleBalanceAdjustment: EquityFixture_1.ScheduledBalanceAdjustmentFixture.create(),
            };
            queryBusMock.execute.mockResolvedValueOnce(expectedResponse).mockResolvedValueOnce(expectedResponse2);
            const result = await Equity_1.default.getAllScheduledBalanceAdjustments(getAllScheduledBalanceAdjustmentsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAllScheduledBalanceAdjustmentsRequest", getAllScheduledBalanceAdjustmentsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(2);
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(1, new GetScheduledBalanceAdjustmentsCountQuery_1.GetScheduledBalanceAdjustmentCountQuery(getAllScheduledBalanceAdjustmentsRequest.securityId));
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(2, new GetScheduledBalanceAdjustmentQuery_1.GetScheduledBalanceAdjustmentQuery(getAllScheduledBalanceAdjustmentsRequest.securityId, 1));
            expect(result).toEqual(expect.arrayContaining([
                {
                    decimals: expectedResponse2.scheduleBalanceAdjustment.decimals.toString(),
                    id: 1,
                    executionDate: new Date(expectedResponse2.scheduleBalanceAdjustment.executionTimeStamp * SecurityDate_1.ONE_THOUSAND),
                    factor: expectedResponse2.scheduleBalanceAdjustment.factor.toString(),
                    isDisabled: expectedResponse2.scheduleBalanceAdjustment.isDisabled,
                },
            ]));
        });
        it("should return empty array if count is 0", async () => {
            const expectedResponse = {
                payload: 0,
            };
            queryBusMock.execute.mockResolvedValueOnce(expectedResponse);
            const result = await Equity_1.default.getAllScheduledBalanceAdjustments(getAllScheduledBalanceAdjustmentsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAllScheduledBalanceAdjustmentsRequest", getAllScheduledBalanceAdjustmentsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetScheduledBalanceAdjustmentsCountQuery_1.GetScheduledBalanceAdjustmentCountQuery(getAllScheduledBalanceAdjustmentsRequest.securityId));
            expect(result).toStrictEqual([]);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getAllScheduledBalanceAdjustments(getAllScheduledBalanceAdjustmentsRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAllScheduledBalanceAdjustmentsRequest", getAllScheduledBalanceAdjustmentsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetScheduledBalanceAdjustmentsCountQuery_1.GetScheduledBalanceAdjustmentCountQuery(getAllScheduledBalanceAdjustmentsRequest.securityId));
        });
    });
    describe("getVotingHolders", () => {
        getVotingHoldersRequest = new request_1.GetVotingHoldersRequest(EquityFixture_1.GetVotingHoldersRequestFixture.create());
        it("should get voting token holders successfully", async () => {
            const expectedResponse = {
                payload: [transactionId],
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getVotingHolders(getVotingHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetVotingHoldersRequest.name, getVotingHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingHoldersQuery_1.GetVotingHoldersQuery(getVotingHoldersRequest.securityId, getVotingHoldersRequest.voteId, getVotingHoldersRequest.start, getVotingHoldersRequest.end));
            expect(result).toStrictEqual(expectedResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getVotingHolders(getVotingHoldersRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetVotingHoldersRequest.name, getVotingHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingHoldersQuery_1.GetVotingHoldersQuery(getVotingHoldersRequest.securityId, getVotingHoldersRequest.voteId, getVotingHoldersRequest.start, getVotingHoldersRequest.end));
        });
        it("should throw error if securityId is invalid", async () => {
            getVotingHoldersRequest = new request_1.GetVotingHoldersRequest({
                ...EquityFixture_1.GetVotingHoldersRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.getVotingHolders(getVotingHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if voteId is invalid", async () => {
            getVotingHoldersRequest = new request_1.GetVotingHoldersRequest({
                ...EquityFixture_1.GetVotingHoldersRequestFixture.create(),
                voteId: -1,
            });
            await expect(Equity_1.default.getVotingHolders(getVotingHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if start is invalid", async () => {
            getVotingHoldersRequest = new request_1.GetVotingHoldersRequest({
                ...EquityFixture_1.GetVotingHoldersRequestFixture.create(),
                start: -1,
            });
            await expect(Equity_1.default.getVotingHolders(getVotingHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if end is invalid", async () => {
            getVotingHoldersRequest = new request_1.GetVotingHoldersRequest({
                ...EquityFixture_1.GetVotingHoldersRequestFixture.create(),
                end: -1,
            });
            await expect(Equity_1.default.getVotingHolders(getVotingHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getTotalVotingHolders", () => {
        getTotalVotingHoldersRequest = new request_1.GetTotalVotingHoldersRequest(EquityFixture_1.GetTotalVotingHoldersRequestFixture.create());
        it("should get total voting holders successfully", async () => {
            const expectedResponse = {
                payload: 1,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getTotalVotingHolders(getTotalVotingHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalVotingHoldersRequest.name, getTotalVotingHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalVotingHoldersQuery_1.GetTotalVotingHoldersQuery(getTotalVotingHoldersRequest.securityId, getTotalVotingHoldersRequest.voteId));
            expect(result).toEqual(expectedResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.getTotalVotingHolders(getTotalVotingHoldersRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalVotingHoldersRequest.name, getTotalVotingHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalVotingHoldersQuery_1.GetTotalVotingHoldersQuery(getTotalVotingHoldersRequest.securityId, getTotalVotingHoldersRequest.voteId));
        });
        it("should throw error if securityId is invalid", async () => {
            getTotalVotingHoldersRequest = new request_1.GetTotalVotingHoldersRequest({
                ...EquityFixture_1.GetTotalVotingHoldersRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.getTotalVotingHolders(getTotalVotingHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if voteId is invalid", async () => {
            getTotalVotingHoldersRequest = new request_1.GetTotalVotingHoldersRequest({
                ...EquityFixture_1.GetTotalVotingHoldersRequestFixture.create(),
                voteId: -1,
            });
            await expect(Equity_1.default.getTotalVotingHolders(getTotalVotingHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("createTrexSuite", () => {
        createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create());
        it("should create equity successfully", async () => {
            const expectedResponse = {
                securityId: new ContractId_1.default(DataFixture_1.HederaIdPropsFixture.create().value),
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            queryBusMock.execute.mockResolvedValue({
                security: security,
            });
            const result = await Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("CreateTrexSuiteEquityRequest", createTrexSuiteEquityRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateTrexSuiteEquityCommand_1.CreateTrexSuiteEquityCommand(createTrexSuiteEquityRequest.salt, createTrexSuiteEquityRequest.owner, createTrexSuiteEquityRequest.irs, createTrexSuiteEquityRequest.onchainId, createTrexSuiteEquityRequest.irAgents, createTrexSuiteEquityRequest.tokenAgents, createTrexSuiteEquityRequest.compliancesModules, createTrexSuiteEquityRequest.complianceSettings, createTrexSuiteEquityRequest.claimTopics, createTrexSuiteEquityRequest.issuers, createTrexSuiteEquityRequest.issuerClaims, expect.objectContaining({
                name: createTrexSuiteEquityRequest.name,
                symbol: createTrexSuiteEquityRequest.symbol,
                isin: createTrexSuiteEquityRequest.isin,
                decimals: createTrexSuiteEquityRequest.decimals,
                isWhiteList: createTrexSuiteEquityRequest.isWhiteList,
                isControllable: createTrexSuiteEquityRequest.isControllable,
                arePartitionsProtected: createTrexSuiteEquityRequest.arePartitionsProtected,
                clearingActive: createTrexSuiteEquityRequest.clearingActive,
                internalKycActivated: createTrexSuiteEquityRequest.internalKycActivated,
                isMultiPartition: createTrexSuiteEquityRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createTrexSuiteEquityRequest.numberOfShares),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createTrexSuiteEquityRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createTrexSuiteEquityRequest.regulationSubType),
                isCountryControlListWhiteList: createTrexSuiteEquityRequest.isCountryControlListWhiteList,
                countries: createTrexSuiteEquityRequest.countries,
                info: createTrexSuiteEquityRequest.info,
            }), createTrexSuiteEquityRequest.votingRight, createTrexSuiteEquityRequest.informationRight, createTrexSuiteEquityRequest.liquidationRight, createTrexSuiteEquityRequest.subscriptionRight, createTrexSuiteEquityRequest.conversionRight, createTrexSuiteEquityRequest.redemptionRight, createTrexSuiteEquityRequest.putRight, DividendType_1.CastDividendType.fromNumber(createTrexSuiteEquityRequest.dividendRight), createTrexSuiteEquityRequest.currency, createTrexSuiteEquityRequest.nominalValue, createTrexSuiteEquityRequest.nominalValueDecimals, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createTrexSuiteEquityRequest.configId, createTrexSuiteEquityRequest.configVersion, createTrexSuiteEquityRequest.diamondOwnerAccount, createTrexSuiteEquityRequest.externalPauses, createTrexSuiteEquityRequest.externalControlLists, createTrexSuiteEquityRequest.externalKycLists, createTrexSuiteEquityRequest.complianceId, createTrexSuiteEquityRequest.identityRegistryId));
            expect(result).toEqual(expect.objectContaining({
                security: security,
                transactionId: expectedResponse.transactionId,
            }));
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("CreateTrexSuiteEquityRequest", createTrexSuiteEquityRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateTrexSuiteEquityCommand_1.CreateTrexSuiteEquityCommand(createTrexSuiteEquityRequest.salt, createTrexSuiteEquityRequest.owner, createTrexSuiteEquityRequest.irs, createTrexSuiteEquityRequest.onchainId, createTrexSuiteEquityRequest.irAgents, createTrexSuiteEquityRequest.tokenAgents, createTrexSuiteEquityRequest.compliancesModules, createTrexSuiteEquityRequest.complianceSettings, createTrexSuiteEquityRequest.claimTopics, createTrexSuiteEquityRequest.issuers, createTrexSuiteEquityRequest.issuerClaims, expect.objectContaining({
                name: createTrexSuiteEquityRequest.name,
                symbol: createTrexSuiteEquityRequest.symbol,
                isin: createTrexSuiteEquityRequest.isin,
                decimals: createTrexSuiteEquityRequest.decimals,
                isWhiteList: createTrexSuiteEquityRequest.isWhiteList,
                isControllable: createTrexSuiteEquityRequest.isControllable,
                arePartitionsProtected: createTrexSuiteEquityRequest.arePartitionsProtected,
                clearingActive: createTrexSuiteEquityRequest.clearingActive,
                internalKycActivated: createTrexSuiteEquityRequest.internalKycActivated,
                isMultiPartition: createTrexSuiteEquityRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createTrexSuiteEquityRequest.numberOfShares),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createTrexSuiteEquityRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createTrexSuiteEquityRequest.regulationSubType),
                isCountryControlListWhiteList: createTrexSuiteEquityRequest.isCountryControlListWhiteList,
                countries: createTrexSuiteEquityRequest.countries,
                info: createTrexSuiteEquityRequest.info,
            }), createTrexSuiteEquityRequest.votingRight, createTrexSuiteEquityRequest.informationRight, createTrexSuiteEquityRequest.liquidationRight, createTrexSuiteEquityRequest.subscriptionRight, createTrexSuiteEquityRequest.conversionRight, createTrexSuiteEquityRequest.redemptionRight, createTrexSuiteEquityRequest.putRight, DividendType_1.CastDividendType.fromNumber(createTrexSuiteEquityRequest.dividendRight), createTrexSuiteEquityRequest.currency, createTrexSuiteEquityRequest.nominalValue, createTrexSuiteEquityRequest.nominalValueDecimals, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createTrexSuiteEquityRequest.configId, createTrexSuiteEquityRequest.configVersion, createTrexSuiteEquityRequest.diamondOwnerAccount, createTrexSuiteEquityRequest.externalPauses, createTrexSuiteEquityRequest.externalControlLists, createTrexSuiteEquityRequest.externalKycLists, createTrexSuiteEquityRequest.complianceId, createTrexSuiteEquityRequest.identityRegistryId));
        });
        it("should throw error if name is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({ name: "" }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if symbol is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                symbol: "",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if isin is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                isin: "",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if decimals is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                decimals: 2.85,
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if diamondOwnerAccount is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                diamondOwnerAccount: "invalid",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if dividendRight is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                dividendRight: 100,
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if currency is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                currency: "invalid",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if numberOfShares is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                numberOfShares: "invalid",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if nominalValue is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                nominalValue: "invalid",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if regulationType is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                regulationType: 5,
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if regulationSubType is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                regulationSubType: 5,
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if configId is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                configId: "invalid",
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalPauses is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                externalPauses: ["invalid"],
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlLists is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                externalControlLists: ["invalid"],
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycLists is invalid", async () => {
            createTrexSuiteEquityRequest = new request_1.CreateTrexSuiteEquityRequest(EquityFixture_1.CreateTrexSuiteEquityRequestFixture.create({
                externalKycLists: ["invalid"],
            }));
            await expect(Equity_1.default.createTrexSuite(createTrexSuiteEquityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("cancelVoting", () => {
        cancelVotingRequest = new request_1.CancelVotingRequest(EquityFixture_1.CancelVotingRequestFixture.create());
        it("should cancel a voting successfully", async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.cancelVoting(cancelVotingRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("CancelVotingRequest", cancelVotingRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CancelVotingCommand_1.CancelVotingCommand(cancelVotingRequest.securityId, cancelVotingRequest.votingId));
            expect(result.payload).toBe(true);
            expect(result.transactionId).toBe(transactionId);
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(Equity_1.default.cancelVoting(cancelVotingRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("CancelVotingRequest", cancelVotingRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CancelVotingCommand_1.CancelVotingCommand(cancelVotingRequest.securityId, cancelVotingRequest.votingId));
        });
        it("should throw error if securityId is invalid", async () => {
            cancelVotingRequest = new request_1.CancelVotingRequest({
                ...EquityFixture_1.CancelVotingRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Equity_1.default.cancelVoting(cancelVotingRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
});
