"use strict";
/*
                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
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 ethers_1 = require("ethers");
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 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 SetDividendsCommand_1 = require("../../../app/usecase/command/equity/dividends/set/SetDividendsCommand");
const GetDividendsForQuery_1 = require("../../../app/usecase/query/equity/dividends/getDividendsFor/GetDividendsForQuery");
const GetDividendsQuery_1 = require("../../../app/usecase/query/equity/dividends/getDividends/GetDividendsQuery");
const GetDividendsCountQuery_1 = require("../../../app/usecase/query/equity/dividends/getDividendsCount/GetDividendsCountQuery");
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 GetDividendHoldersQuery_1 = require("../../../app/usecase/query/equity/dividends/getDividendHolders/GetDividendHoldersQuery");
const GetTotalDividendHoldersQuery_1 = require("../../../app/usecase/query/equity/dividends/getTotalDividendHolders/GetTotalDividendHoldersQuery");
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 setDividendsRequest;
    let getDividendsForRequest;
    let getDividendsRequest;
    let getAllDividendsRequest;
    let setVotingRightsRequest;
    let getVotingRightsForRequest;
    let getVotingRightsRequest;
    let getAllVotingRightsRequest;
    let setScheduledBalanceAdjustmentRequest;
    let getScheduledBalanceAdjustmentCountRequest;
    let getScheduledBalanceAdjustmentRequest;
    let getAllScheduledBalanceAdjustmentsRequest;
    let getDividendHoldersRequest;
    let getTotalDividendHoldersRequest;
    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(ethers_1.BigNumber.from(10)),
                decimals: 1,
            };
            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(),
            }));
        });
        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,
            }));
        });
        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,
                },
            ]));
        });
        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('setDividends', () => {
        setDividendsRequest = new request_1.SetDividendsRequest(EquityFixture_1.SetDividendsRequestFixture.create());
        it('should set dividends successfully', async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.setDividends(setDividendsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('SetDividendsRequest', setDividendsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetDividendsCommand_1.SetDividendsCommand(setDividendsRequest.securityId, setDividendsRequest.recordTimestamp, setDividendsRequest.executionTimestamp, setDividendsRequest.amountPerUnitOfSecurity));
            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.setDividends(setDividendsRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('SetDividendsRequest', setDividendsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetDividendsCommand_1.SetDividendsCommand(setDividendsRequest.securityId, setDividendsRequest.recordTimestamp, setDividendsRequest.executionTimestamp, setDividendsRequest.amountPerUnitOfSecurity));
        });
        it('should throw error if securityId is invalid', async () => {
            setDividendsRequest = new request_1.SetDividendsRequest({
                ...EquityFixture_1.SetDividendsRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Equity_1.default.setDividends(setDividendsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if recordTimestamp is invalid', async () => {
            setDividendsRequest = new request_1.SetDividendsRequest({
                ...EquityFixture_1.SetDividendsRequestFixture.create(),
                recordTimestamp: (Math.ceil(new Date().getTime() / 1000) - 100).toString(),
            });
            await expect(Equity_1.default.setDividends(setDividendsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if executionTimestamp is invalid', async () => {
            const time = Math.ceil(new Date().getTime() / 1000);
            setDividendsRequest = new request_1.SetDividendsRequest({
                ...EquityFixture_1.SetDividendsRequestFixture.create(),
                recordTimestamp: time.toString(),
                executionTimestamp: (time - 100).toString(),
            });
            await expect(Equity_1.default.setDividends(setDividendsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if amountPerUnitOfSecurity is invalid', async () => {
            setDividendsRequest = new request_1.SetDividendsRequest({
                ...EquityFixture_1.SetDividendsRequestFixture.create(),
                amountPerUnitOfSecurity: 'invalid',
            });
            await expect(Equity_1.default.setDividends(setDividendsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getDividendsFor', () => {
        getDividendsForRequest = new request_1.GetDividendsForRequest(EquityFixture_1.GetDividendsForRequestFixture.create());
        it('should get dividends for successfully', async () => {
            const expectedResponse = {
                tokenBalance: new BigDecimal_1.default(ethers_1.BigNumber.from(10)),
                decimals: 1,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getDividendsFor(getDividendsForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetDividendsForRequest', getDividendsForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendsForQuery_1.GetDividendsForQuery(getDividendsForRequest.targetId, getDividendsForRequest.securityId, getDividendsForRequest.dividendId));
            expect(result).toEqual(expect.objectContaining({
                tokenBalance: expectedResponse.tokenBalance.toString(),
                decimals: expectedResponse.decimals.toString(),
            }));
        });
        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.getDividendsFor(getDividendsForRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetDividendsForRequest', getDividendsForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendsForQuery_1.GetDividendsForQuery(getDividendsForRequest.targetId, getDividendsForRequest.securityId, getDividendsForRequest.dividendId));
        });
        it('should throw error if targetId is invalid', async () => {
            getDividendsForRequest = new request_1.GetDividendsForRequest({
                ...EquityFixture_1.GetDividendsForRequestFixture.create(),
                targetId: 'invalid',
            });
            await expect(Equity_1.default.getDividendsFor(getDividendsForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if securityId is invalid', async () => {
            getDividendsForRequest = new request_1.GetDividendsForRequest({
                ...EquityFixture_1.GetDividendsForRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Equity_1.default.getDividendsFor(getDividendsForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if dividendId is invalid', async () => {
            getDividendsForRequest = new request_1.GetDividendsForRequest({
                ...EquityFixture_1.GetDividendsForRequestFixture.create(),
                dividendId: 0,
            });
            await expect(Equity_1.default.getDividendsFor(getDividendsForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getDividends', () => {
        getDividendsRequest = new request_1.GetDividendsRequest(EquityFixture_1.GetDividendsRequestFixture.create());
        it('should get dividends successfully', async () => {
            const expectedResponse = {
                dividend: EquityFixture_1.DividendFixture.create(),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getDividends(getDividendsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetDividendsRequest', getDividendsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendsQuery_1.GetDividendsQuery(getDividendsRequest.securityId, getDividendsRequest.dividendId));
            expect(result).toEqual(expect.objectContaining({
                dividendId: getDividendsRequest.dividendId,
                amountPerUnitOfSecurity: expectedResponse.dividend.amountPerUnitOfSecurity.toString(),
                recordDate: new Date(expectedResponse.dividend.recordTimeStamp * SecurityDate_1.ONE_THOUSAND),
                executionDate: new Date(expectedResponse.dividend.executionTimeStamp * SecurityDate_1.ONE_THOUSAND),
            }));
        });
        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.getDividends(getDividendsRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetDividendsRequest', getDividendsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendsQuery_1.GetDividendsQuery(getDividendsRequest.securityId, getDividendsRequest.dividendId));
        });
        it('should throw error if securityId is invalid', async () => {
            getDividendsRequest = new request_1.GetDividendsRequest({
                ...EquityFixture_1.GetDividendsRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Equity_1.default.getDividends(getDividendsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if dividendId is invalid', async () => {
            getDividendsRequest = new request_1.GetDividendsRequest({
                ...EquityFixture_1.GetDividendsRequestFixture.create(),
                dividendId: -1,
            });
            await expect(Equity_1.default.getDividends(getDividendsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getAllDividends', () => {
        getAllDividendsRequest = new request_1.GetAllDividendsRequest(EquityFixture_1.GetAllDividendsRequestFixture.create());
        it('should get all dividends successfully', async () => {
            const expectedResponse = {
                payload: 1,
            };
            const expectedResponse2 = {
                dividend: EquityFixture_1.DividendFixture.create(),
            };
            queryBusMock.execute
                .mockResolvedValueOnce(expectedResponse)
                .mockResolvedValueOnce(expectedResponse2);
            const result = await Equity_1.default.getAllDividends(getAllDividendsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetAllDividendsRequest', getAllDividendsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(2);
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(1, new GetDividendsCountQuery_1.GetDividendsCountQuery(getAllDividendsRequest.securityId));
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(2, new GetDividendsQuery_1.GetDividendsQuery(getAllDividendsRequest.securityId, 1));
            expect(result).toEqual(expect.arrayContaining([
                {
                    dividendId: 1,
                    amountPerUnitOfSecurity: expectedResponse2.dividend.amountPerUnitOfSecurity.toString(),
                    recordDate: new Date(expectedResponse2.dividend.recordTimeStamp * SecurityDate_1.ONE_THOUSAND),
                    executionDate: new Date(expectedResponse2.dividend.executionTimeStamp * SecurityDate_1.ONE_THOUSAND),
                },
            ]));
        });
        it('should return empty array if count is 0', async () => {
            const expectedResponse = {
                payload: 0,
            };
            queryBusMock.execute.mockResolvedValueOnce(expectedResponse);
            const result = await Equity_1.default.getAllDividends(getAllDividendsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetAllDividendsRequest', getAllDividendsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendsCountQuery_1.GetDividendsCountQuery(getAllDividendsRequest.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.getAllDividends(getAllDividendsRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetAllDividendsRequest', getAllDividendsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetVotingCountQuery_1.GetVotingCountQuery(getAllDividendsRequest.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('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(),
            }));
        });
        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(),
                },
            ]));
        });
        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('getDividendHolders', () => {
        getDividendHoldersRequest = new request_1.GetDividendHoldersRequest(EquityFixture_1.GetDividendHoldersRequestFixture.create());
        it('should get dividend token holders successfully', async () => {
            const expectedResponse = {
                payload: [transactionId],
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getDividendHolders(getDividendHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetDividendHoldersRequest.name, getDividendHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendHoldersQuery_1.GetDividendHoldersQuery(getDividendHoldersRequest.securityId, getDividendHoldersRequest.dividendId, getDividendHoldersRequest.start, getDividendHoldersRequest.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.getDividendHolders(getDividendHoldersRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetDividendHoldersRequest.name, getDividendHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetDividendHoldersQuery_1.GetDividendHoldersQuery(getDividendHoldersRequest.securityId, getDividendHoldersRequest.dividendId, getDividendHoldersRequest.start, getDividendHoldersRequest.end));
        });
        it('should throw error if securityId is invalid', async () => {
            getDividendHoldersRequest = new request_1.GetDividendHoldersRequest({
                ...EquityFixture_1.GetDividendHoldersRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Equity_1.default.getDividendHolders(getDividendHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if dividendId is invalid', async () => {
            getDividendHoldersRequest = new request_1.GetDividendHoldersRequest({
                ...EquityFixture_1.GetDividendHoldersRequestFixture.create(),
                dividendId: -1,
            });
            await expect(Equity_1.default.getDividendHolders(getDividendHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if start is invalid', async () => {
            getDividendHoldersRequest = new request_1.GetDividendHoldersRequest({
                ...EquityFixture_1.GetDividendHoldersRequestFixture.create(),
                start: -1,
            });
            await expect(Equity_1.default.getDividendHolders(getDividendHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if end is invalid', async () => {
            getDividendHoldersRequest = new request_1.GetDividendHoldersRequest({
                ...EquityFixture_1.GetDividendHoldersRequestFixture.create(),
                end: -1,
            });
            await expect(Equity_1.default.getDividendHolders(getDividendHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getTotalDividendHolders', () => {
        getTotalDividendHoldersRequest = new request_1.GetTotalDividendHoldersRequest(EquityFixture_1.GetTotalDividendHoldersRequestFixture.create());
        it('should get total dividend holders successfully', async () => {
            const expectedResponse = {
                payload: 1,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Equity_1.default.getTotalDividendHolders(getTotalDividendHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalDividendHoldersRequest.name, getTotalDividendHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalDividendHoldersQuery_1.GetTotalDividendHoldersQuery(getTotalDividendHoldersRequest.securityId, getTotalDividendHoldersRequest.dividendId));
            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.getTotalDividendHolders(getTotalDividendHoldersRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalDividendHoldersRequest.name, getTotalDividendHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalDividendHoldersQuery_1.GetTotalDividendHoldersQuery(getTotalDividendHoldersRequest.securityId, getTotalDividendHoldersRequest.dividendId));
        });
        it('should throw error if securityId is invalid', async () => {
            getTotalDividendHoldersRequest = new request_1.GetTotalDividendHoldersRequest({
                ...EquityFixture_1.GetTotalDividendHoldersRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Equity_1.default.getTotalDividendHolders(getTotalDividendHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if dividendId is invalid', async () => {
            getTotalDividendHoldersRequest = new request_1.GetTotalDividendHoldersRequest({
                ...EquityFixture_1.GetTotalDividendHoldersRequestFixture.create(),
                dividendId: -1,
            });
            await expect(Equity_1.default.getTotalDividendHolders(getTotalDividendHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    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);
        });
    });
});
