"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts_jest_1 = require("@golevelup/ts-jest");
const request_1 = require("../request");
const DataFixture_1 = require("../../../../__tests__/fixtures/shared/DataFixture");
const LogService_1 = __importDefault(require("../../../app/service/log/LogService"));
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
const ValidationError_1 = require("../../../core/validation/ValidationError");
const Bond_1 = __importDefault(require("./Bond"));
const BondFixture_1 = require("../../../../__tests__/fixtures/bond/BondFixture");
const SecurityFixture_1 = require("../../../../__tests__/fixtures/shared/SecurityFixture");
const Security_1 = require("../../../domain/context/security/Security");
const CreateBondCommand_1 = require("../../../app/usecase/command/bond/create/CreateBondCommand");
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 _1 = require("@faker-js/faker/.");
const GetBondDetailsQuery_1 = require("../../../app/usecase/query/bond/get/getBondDetails/GetBondDetailsQuery");
const SecurityDate_1 = require("../../../domain/context/shared/SecurityDate");
const SetCouponCommand_1 = require("../../../app/usecase/command/bond/coupon/set/SetCouponCommand");
const ethers_1 = require("ethers");
const GetCouponForQuery_1 = require("../../../app/usecase/query/bond/coupons/getCouponFor/GetCouponForQuery");
const GetPrincipalForQuery_1 = require("../../../app/usecase/query/bond/get/getPrincipalFor/GetPrincipalForQuery");
const GetCouponAmountForQuery_1 = require("../../../app/usecase/query/bond/coupons/getCouponAmountFor/GetCouponAmountForQuery");
const GetCouponQuery_1 = require("../../../app/usecase/query/bond/coupons/getCoupon/GetCouponQuery");
const GetCouponCountQuery_1 = require("../../../app/usecase/query/bond/coupons/getCouponCount/GetCouponCountQuery");
const UpdateMaturityDateCommand_1 = require("../../../app/usecase/command/bond/updateMaturityDate/UpdateMaturityDateCommand");
const RedeemAtMaturityByPartitionCommand_1 = require("../../../app/usecase/command/bond/redeemAtMaturityByPartition/RedeemAtMaturityByPartitionCommand");
const FullRedeemAtMaturityCommand_1 = require("../../../app/usecase/command/bond/fullRedeemAtMaturity/FullRedeemAtMaturityCommand");
const GetCouponHoldersQuery_1 = require("../../../app/usecase/query/bond/coupons/getCouponHolders/GetCouponHoldersQuery");
const GetTotalCouponHoldersQuery_1 = require("../../../app/usecase/query/bond/coupons/getTotalCouponHolders/GetTotalCouponHoldersQuery");
const CreateTrexSuiteBondCommand_1 = require("../../../app/usecase/command/bond/createTrexSuite/CreateTrexSuiteBondCommand");
const AddProceedRecipientRequest_1 = __importDefault(require("../request/bond/AddProceedRecipientRequest"));
const AddProceedRecipientCommand_1 = require("../../../app/usecase/command/security/proceedRecipients/addProceedRecipient/AddProceedRecipientCommand");
const RemoveProceedRecipientCommand_1 = require("../../../app/usecase/command/security/proceedRecipients/removeProceedRecipient/RemoveProceedRecipientCommand");
const UpdateProceedRecipientDataCommand_1 = require("../../../app/usecase/command/security/proceedRecipients/updateProceedRecipientData/UpdateProceedRecipientDataCommand");
const IsProceedRecipientQuery_1 = require("../../../app/usecase/query/security/proceedRecipient/isProceedRecipient/IsProceedRecipientQuery");
const GetProceedRecipientsCountQuery_1 = require("../../../app/usecase/query/security/proceedRecipient/getProceedRecipientsCount/GetProceedRecipientsCountQuery");
const GetProceedRecipientDataQuery_1 = require("../../../app/usecase/query/security/proceedRecipient/getProceedRecipientData/GetProceedRecipientDataQuery");
const GetProceedRecipientsQuery_1 = require("../../../app/usecase/query/security/proceedRecipient/getProceedRecipients/GetProceedRecipientsQuery");
describe('Bond', () => {
    let commandBusMock;
    let queryBusMock;
    let networkServiceMock;
    let createBondRequest;
    let getBondDetailsRequest;
    let setCouponRequest;
    let getCouponForRequest;
    let getCouponRequest;
    let getAllCouponsRequest;
    let updateMaturityDateRequest;
    let redeemAtMaturityByPartitionRequest;
    let fullRedeemAtMaturityRequest;
    let getCouponHoldersRequest;
    let getTotalCouponHoldersRequest;
    let createTrexSuiteBondRequest;
    let getPrincipalForRequest;
    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(() => { });
        Bond_1.default.commandBus = commandBusMock;
        Bond_1.default.queryBus = queryBusMock;
        Bond_1.default.networkService = networkServiceMock;
    });
    afterEach(() => {
        jest.resetAllMocks();
        jest.restoreAllMocks();
    });
    describe('create', () => {
        createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create());
        it('should create 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 Bond_1.default.create(createBondRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('CreateBondRequest', createBondRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateBondCommand_1.CreateBondCommand(expect.objectContaining({
                name: createBondRequest.name,
                symbol: createBondRequest.symbol,
                isin: createBondRequest.isin,
                decimals: createBondRequest.decimals,
                isWhiteList: createBondRequest.isWhiteList,
                isControllable: createBondRequest.isControllable,
                arePartitionsProtected: createBondRequest.arePartitionsProtected,
                clearingActive: createBondRequest.clearingActive,
                internalKycActivated: createBondRequest.internalKycActivated,
                isMultiPartition: createBondRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createBondRequest.numberOfUnits),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createBondRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createBondRequest.regulationSubType),
                isCountryControlListWhiteList: createBondRequest.isCountryControlListWhiteList,
                countries: createBondRequest.countries,
                info: createBondRequest.info,
            }), createBondRequest.currency, createBondRequest.nominalValue, createBondRequest.nominalValueDecimals, createBondRequest.startingDate, createBondRequest.maturityDate, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createBondRequest.configId, createBondRequest.configVersion, createBondRequest.diamondOwnerAccount, createBondRequest.externalPausesIds, createBondRequest.externalControlListsIds, createBondRequest.externalKycListsIds, createBondRequest.complianceId, createBondRequest.identityRegistryId, createBondRequest.proceedRecipientsIds, createBondRequest.proceedRecipientsData));
            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(Bond_1.default.create(createBondRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('CreateBondRequest', createBondRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateBondCommand_1.CreateBondCommand(expect.objectContaining({
                name: createBondRequest.name,
                symbol: createBondRequest.symbol,
                isin: createBondRequest.isin,
                decimals: createBondRequest.decimals,
                isWhiteList: createBondRequest.isWhiteList,
                isControllable: createBondRequest.isControllable,
                arePartitionsProtected: createBondRequest.arePartitionsProtected,
                clearingActive: createBondRequest.clearingActive,
                internalKycActivated: createBondRequest.internalKycActivated,
                isMultiPartition: createBondRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createBondRequest.numberOfUnits),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createBondRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createBondRequest.regulationSubType),
                isCountryControlListWhiteList: createBondRequest.isCountryControlListWhiteList,
                countries: createBondRequest.countries,
                info: createBondRequest.info,
            }), createBondRequest.currency, createBondRequest.nominalValue, createBondRequest.nominalValueDecimals, createBondRequest.startingDate, createBondRequest.maturityDate, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createBondRequest.configId, createBondRequest.configVersion, createBondRequest.diamondOwnerAccount, createBondRequest.externalPausesIds, createBondRequest.externalControlListsIds, createBondRequest.externalKycListsIds, createBondRequest.complianceId, createBondRequest.identityRegistryId, createBondRequest.proceedRecipientsIds, createBondRequest.proceedRecipientsData));
        });
        it('should not throw error if proceedRecipientsData not has bytes', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                proceedRecipientsData: ['', '0x1234'],
                proceedRecipientsIds: ['0.0.1234', '0.0.5678'],
            }));
            await expect(Bond_1.default.create(createBondRequest)).resolves.not.toThrow();
        });
        it('should throw error if name is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({ name: '' }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if symbol is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                symbol: '',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if isin is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                isin: '',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if decimals is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                decimals: 2.85,
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if diamondOwnerAccount is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                diamondOwnerAccount: 'invalid',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if currency is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                currency: 'invalid',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if numberOfUnits is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                numberOfUnits: 'invalid',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if nominalValue is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                nominalValue: 'invalid',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if startingDate is invalid', async () => {
            const time = Math.floor(_1.faker.date.past().getTime() / 1000);
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                startingDate: time.toString(),
                maturityDate: (time + 10).toString(),
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if maturityDate is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                maturityDate: _1.faker.date.past().getTime().toString(),
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if regulationSubType is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                regulationSubType: 5,
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if configId is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                configId: 'invalid',
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if externalPausesIds is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                externalPausesIds: ['invalid'],
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if externalControlListsIds is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                externalControlListsIds: ['invalid'],
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if externalKycListsIds is invalid', async () => {
            createBondRequest = new request_1.CreateBondRequest(BondFixture_1.CreateBondRequestFixture.create({
                externalKycListsIds: ['invalid'],
            }));
            await expect(Bond_1.default.create(createBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getBondDetails', () => {
        getBondDetailsRequest = new request_1.GetBondDetailsRequest(BondFixture_1.GetBondDetailsRequestFixture.create());
        it('should get bond details successfully', async () => {
            const expectedResponse = {
                bond: BondFixture_1.BondDetailsFixture.create(),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getBondDetails(getBondDetailsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetBondDetailsRequest', getBondDetailsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetBondDetailsQuery_1.GetBondDetailsQuery(getBondDetailsRequest.bondId));
            expect(result).toEqual(expect.objectContaining({
                currency: expectedResponse.bond.currency,
                nominalValue: expectedResponse.bond.nominalValue.toString(),
                nominalValueDecimals: expectedResponse.bond.nominalValueDecimals,
                startingDate: new Date(expectedResponse.bond.startingDate * SecurityDate_1.ONE_THOUSAND),
                maturityDate: new Date(expectedResponse.bond.maturityDate * 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(Bond_1.default.getBondDetails(getBondDetailsRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetBondDetailsRequest', getBondDetailsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetBondDetailsQuery_1.GetBondDetailsQuery(getBondDetailsRequest.bondId));
        });
        it('should throw error if bondId is invalid', async () => {
            getBondDetailsRequest = new request_1.GetBondDetailsRequest({
                ...BondFixture_1.GetBondDetailsRequestFixture.create(),
                bondId: 'invalid',
            });
            await expect(Bond_1.default.getBondDetails(getBondDetailsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('setCoupon', () => {
        setCouponRequest = new request_1.SetCouponRequest(BondFixture_1.SetCouponRequestFixture.create());
        it('should set coupon successfully', async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.setCoupon(setCouponRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('SetCouponRequest', setCouponRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetCouponCommand_1.SetCouponCommand(setCouponRequest.securityId, setCouponRequest.recordTimestamp, setCouponRequest.executionTimestamp, setCouponRequest.rate, setCouponRequest.period));
            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(Bond_1.default.setCoupon(setCouponRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('SetCouponRequest', setCouponRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetCouponCommand_1.SetCouponCommand(setCouponRequest.securityId, setCouponRequest.recordTimestamp, setCouponRequest.executionTimestamp, setCouponRequest.rate, setCouponRequest.period));
        });
        it('should throw error if recordTimestamp is invalid', async () => {
            setCouponRequest = new request_1.SetCouponRequest({
                ...BondFixture_1.SetCouponRequestFixture.create(),
                recordTimestamp: (Math.ceil(new Date().getTime() / 1000) - 100).toString(),
            });
            await expect(Bond_1.default.setCoupon(setCouponRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if executionTimestamp is invalid', async () => {
            const time = _1.faker.date.past().getTime();
            setCouponRequest = new request_1.SetCouponRequest({
                ...BondFixture_1.SetCouponRequestFixture.create(),
                recordTimestamp: time.toString(),
                executionTimestamp: (time - 10).toString(),
            });
            await expect(Bond_1.default.setCoupon(setCouponRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if securityId is invalid', async () => {
            setCouponRequest = new request_1.SetCouponRequest({
                ...BondFixture_1.SetCouponRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.setCoupon(setCouponRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if rate is invalid', async () => {
            setCouponRequest = new request_1.SetCouponRequest({
                ...BondFixture_1.SetCouponRequestFixture.create(),
                rate: 'invalid',
            });
            await expect(Bond_1.default.setCoupon(setCouponRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getCouponFor', () => {
        beforeEach(() => {
            getCouponForRequest = new request_1.GetCouponForRequest(BondFixture_1.GetCouponForRequestFixture.create());
        });
        it('should get coupon for successfully', async () => {
            const expectedResponse = {
                payload: new BigDecimal_1.default(ethers_1.BigNumber.from(10)),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getCouponFor(getCouponForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetCouponForRequest', getCouponForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponForQuery_1.GetCouponForQuery(getCouponForRequest.targetId, getCouponForRequest.securityId, getCouponForRequest.couponId));
            expect(result).toEqual(expect.objectContaining({
                value: expectedResponse.payload.toString(),
            }));
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getCouponFor(getCouponForRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetCouponForRequest', getCouponForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponForQuery_1.GetCouponForQuery(getCouponForRequest.targetId, getCouponForRequest.securityId, getCouponForRequest.couponId));
        });
        it('should throw error if targetId is invalid', async () => {
            getCouponForRequest = new request_1.GetCouponForRequest({
                ...BondFixture_1.GetCouponForRequestFixture.create(),
                targetId: 'invalid',
            });
            await expect(Bond_1.default.getCouponFor(getCouponForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if securityId is invalid', async () => {
            getCouponForRequest = new request_1.GetCouponForRequest({
                ...BondFixture_1.GetCouponForRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getCouponFor(getCouponForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if couponId is invalid', async () => {
            getCouponForRequest = new request_1.GetCouponForRequest({
                ...BondFixture_1.GetCouponForRequestFixture.create(),
                couponId: 0,
            });
            await expect(Bond_1.default.getCouponFor(getCouponForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getCouponAmountFor', () => {
        beforeEach(() => {
            getCouponForRequest = new request_1.GetCouponForRequest(BondFixture_1.GetCouponForRequestFixture.create());
        });
        it('should get coupon for successfully', async () => {
            const expectedResponse = {
                numerator: '10',
                denominator: '4',
                recordDateReached: true,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getCouponAmountFor(getCouponForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetCouponForRequest', getCouponForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponAmountForQuery_1.GetCouponAmountForQuery(getCouponForRequest.targetId, getCouponForRequest.securityId, getCouponForRequest.couponId));
            expect(result).toEqual(expect.objectContaining({
                numerator: expectedResponse.numerator,
                denominator: expectedResponse.denominator,
                recordDateReached: expectedResponse.recordDateReached,
            }));
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getCouponAmountFor(getCouponForRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetCouponForRequest', getCouponForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponAmountForQuery_1.GetCouponAmountForQuery(getCouponForRequest.targetId, getCouponForRequest.securityId, getCouponForRequest.couponId));
        });
        it('should throw error if targetId is invalid', async () => {
            getCouponForRequest = new request_1.GetCouponForRequest({
                ...BondFixture_1.GetCouponForRequestFixture.create(),
                targetId: 'invalid',
            });
            await expect(Bond_1.default.getCouponAmountFor(getCouponForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if securityId is invalid', async () => {
            getCouponForRequest = new request_1.GetCouponForRequest({
                ...BondFixture_1.GetCouponForRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getCouponAmountFor(getCouponForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if couponId is invalid', async () => {
            getCouponForRequest = new request_1.GetCouponForRequest({
                ...BondFixture_1.GetCouponForRequestFixture.create(),
                couponId: 0,
            });
            await expect(Bond_1.default.getCouponAmountFor(getCouponForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getPrincipalFor', () => {
        beforeEach(() => {
            getPrincipalForRequest = new request_1.GetPrincipalForRequest(BondFixture_1.GetPrincipalForRequestFixture.create());
        });
        it('should get principal for successfully', async () => {
            const expectedResponse = {
                numerator: '10',
                denominator: '4',
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getPrincipalFor(getPrincipalForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetPrincipalForRequest', getPrincipalForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetPrincipalForQuery_1.GetPrincipalForQuery(getPrincipalForRequest.targetId, getPrincipalForRequest.securityId));
            expect(result).toEqual(expect.objectContaining({
                numerator: expectedResponse.numerator,
                denominator: expectedResponse.denominator,
            }));
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getPrincipalFor(getPrincipalForRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetPrincipalForRequest', getPrincipalForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetPrincipalForQuery_1.GetPrincipalForQuery(getPrincipalForRequest.targetId, getPrincipalForRequest.securityId));
        });
        it('should throw error if targetId is invalid', async () => {
            getPrincipalForRequest = new request_1.GetPrincipalForRequest({
                ...BondFixture_1.GetPrincipalForRequestFixture.create(),
                targetId: 'invalid',
            });
            await expect(Bond_1.default.getPrincipalFor(getPrincipalForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if securityId is invalid', async () => {
            getPrincipalForRequest = new request_1.GetPrincipalForRequest({
                ...BondFixture_1.GetPrincipalForRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getPrincipalFor(getPrincipalForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getCoupon', () => {
        getCouponRequest = new request_1.GetCouponRequest(BondFixture_1.GetCouponRequestFixture.create());
        it('should get coupon successfully', async () => {
            const expectedResponse = {
                coupon: BondFixture_1.CouponFixture.create(),
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getCoupon(getCouponRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetCouponRequest', getCouponRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponQuery_1.GetCouponQuery(getCouponRequest.securityId, getCouponRequest.couponId));
            expect(result).toEqual(expect.objectContaining({
                couponId: getCouponRequest.couponId,
                recordDate: new Date(expectedResponse.coupon.recordTimeStamp * SecurityDate_1.ONE_THOUSAND),
                executionDate: new Date(expectedResponse.coupon.executionTimeStamp * SecurityDate_1.ONE_THOUSAND),
                rate: expectedResponse.coupon.rate.toString(),
            }));
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getCoupon(getCouponRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetCouponRequest', getCouponRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponQuery_1.GetCouponQuery(getCouponRequest.securityId, getCouponRequest.couponId));
        });
        it('should throw error if securityId is invalid', async () => {
            getCouponRequest = new request_1.GetCouponRequest({
                ...BondFixture_1.GetCouponRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getCoupon(getCouponRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if couponId is invalid', async () => {
            getCouponRequest = new request_1.GetCouponRequest({
                ...BondFixture_1.GetCouponRequestFixture.create(),
                couponId: 0,
            });
            await expect(Bond_1.default.getCoupon(getCouponRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getAllCoupons', () => {
        getAllCouponsRequest = new request_1.GetAllCouponsRequest(BondFixture_1.GetAllCouponsRequestFixture.create());
        it('should get all coupon successfully', async () => {
            const expectedResponse = {
                payload: 1,
            };
            const expectedResponse2 = {
                coupon: BondFixture_1.CouponFixture.create(),
            };
            queryBusMock.execute
                .mockResolvedValueOnce(expectedResponse)
                .mockResolvedValueOnce(expectedResponse2);
            const result = await Bond_1.default.getAllCoupons(getAllCouponsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetAllCouponsRequest', getAllCouponsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(2);
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(1, new GetCouponCountQuery_1.GetCouponCountQuery(getAllCouponsRequest.securityId));
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(2, new GetCouponQuery_1.GetCouponQuery(getAllCouponsRequest.securityId, 1));
            expect(result).toEqual(expect.arrayContaining([
                {
                    couponId: 1,
                    recordDate: new Date(expectedResponse2.coupon.recordTimeStamp * SecurityDate_1.ONE_THOUSAND),
                    executionDate: new Date(expectedResponse2.coupon.executionTimeStamp * SecurityDate_1.ONE_THOUSAND),
                    rate: expectedResponse2.coupon.rate.toString(),
                },
            ]));
        });
        it('should return empty array if count is 0', async () => {
            const expectedResponse = {
                payload: 0,
            };
            queryBusMock.execute.mockResolvedValueOnce(expectedResponse);
            const result = await Bond_1.default.getAllCoupons(getAllCouponsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetAllCouponsRequest', getAllCouponsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponCountQuery_1.GetCouponCountQuery(getAllCouponsRequest.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(Bond_1.default.getAllCoupons(getAllCouponsRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetAllCouponsRequest', getAllCouponsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponCountQuery_1.GetCouponCountQuery(getAllCouponsRequest.securityId));
        });
    });
    describe('updateMaturityDate', () => {
        updateMaturityDateRequest = new request_1.UpdateMaturityDateRequest(BondFixture_1.UpdateMaturityDateRequestFixture.create());
        it('should update maturity date successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.updateMaturityDate(updateMaturityDateRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('UpdateMaturityDateRequest', updateMaturityDateRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateMaturityDateCommand_1.UpdateMaturityDateCommand(updateMaturityDateRequest.maturityDate, updateMaturityDateRequest.securityId));
            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(Bond_1.default.updateMaturityDate(updateMaturityDateRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('UpdateMaturityDateRequest', updateMaturityDateRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateMaturityDateCommand_1.UpdateMaturityDateCommand(updateMaturityDateRequest.maturityDate, updateMaturityDateRequest.securityId));
        });
        it('should throw error if securityId is invalid', async () => {
            updateMaturityDateRequest = new request_1.UpdateMaturityDateRequest({
                ...BondFixture_1.UpdateMaturityDateRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.updateMaturityDate(updateMaturityDateRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if maturityDate is invalid', async () => {
            updateMaturityDateRequest = new request_1.UpdateMaturityDateRequest({
                ...BondFixture_1.UpdateMaturityDateRequestFixture.create(),
                maturityDate: '-1',
            });
            await expect(Bond_1.default.updateMaturityDate(updateMaturityDateRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('redeemAtMaturityByPartition', () => {
        redeemAtMaturityByPartitionRequest = new request_1.RedeemAtMaturityByPartitionRequest(BondFixture_1.RedeemAtMaturityByPartitionRequestFixture.create());
        it('should redeem at maturity by partition successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.redeemAtMaturityByPartition(redeemAtMaturityByPartitionRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.RedeemAtMaturityByPartitionRequest.name, redeemAtMaturityByPartitionRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RedeemAtMaturityByPartitionCommand_1.RedeemAtMaturityByPartitionCommand(redeemAtMaturityByPartitionRequest.securityId, redeemAtMaturityByPartitionRequest.partitionId, redeemAtMaturityByPartitionRequest.sourceId, redeemAtMaturityByPartitionRequest.amount));
            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(Bond_1.default.redeemAtMaturityByPartition(redeemAtMaturityByPartitionRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.RedeemAtMaturityByPartitionRequest.name, redeemAtMaturityByPartitionRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RedeemAtMaturityByPartitionCommand_1.RedeemAtMaturityByPartitionCommand(redeemAtMaturityByPartitionRequest.securityId, redeemAtMaturityByPartitionRequest.partitionId, redeemAtMaturityByPartitionRequest.sourceId, redeemAtMaturityByPartitionRequest.amount));
        });
        it('should throw error if securityId is invalid', async () => {
            redeemAtMaturityByPartitionRequest =
                new request_1.RedeemAtMaturityByPartitionRequest({
                    ...BondFixture_1.RedeemAtMaturityByPartitionRequestFixture.create(),
                    securityId: 'invalid',
                });
            await expect(Bond_1.default.redeemAtMaturityByPartition(redeemAtMaturityByPartitionRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if partitionId is invalid', async () => {
            redeemAtMaturityByPartitionRequest =
                new request_1.RedeemAtMaturityByPartitionRequest({
                    ...BondFixture_1.RedeemAtMaturityByPartitionRequestFixture.create(),
                    partitionId: 'invalid',
                });
            await expect(Bond_1.default.redeemAtMaturityByPartition(redeemAtMaturityByPartitionRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if sourceId is invalid', async () => {
            redeemAtMaturityByPartitionRequest =
                new request_1.RedeemAtMaturityByPartitionRequest({
                    ...BondFixture_1.RedeemAtMaturityByPartitionRequestFixture.create(),
                    sourceId: 'invalid',
                });
            await expect(Bond_1.default.redeemAtMaturityByPartition(redeemAtMaturityByPartitionRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if amount is invalid', async () => {
            redeemAtMaturityByPartitionRequest =
                new request_1.RedeemAtMaturityByPartitionRequest({
                    ...BondFixture_1.RedeemAtMaturityByPartitionRequestFixture.create(),
                    amount: 'invalid',
                });
            await expect(Bond_1.default.redeemAtMaturityByPartition(redeemAtMaturityByPartitionRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('fullRedeemAtMaturity', () => {
        fullRedeemAtMaturityRequest = new request_1.FullRedeemAtMaturityRequest(BondFixture_1.FullRedeemAtMaturityRequestFixture.create());
        it('should redeem at maturity successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.fullRedeemAtMaturity(fullRedeemAtMaturityRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.FullRedeemAtMaturityRequest.name, fullRedeemAtMaturityRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new FullRedeemAtMaturityCommand_1.FullRedeemAtMaturityCommand(fullRedeemAtMaturityRequest.securityId, fullRedeemAtMaturityRequest.sourceId));
            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(Bond_1.default.fullRedeemAtMaturity(fullRedeemAtMaturityRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.FullRedeemAtMaturityRequest.name, fullRedeemAtMaturityRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new FullRedeemAtMaturityCommand_1.FullRedeemAtMaturityCommand(fullRedeemAtMaturityRequest.securityId, fullRedeemAtMaturityRequest.sourceId));
        });
        it('should throw error if securityId is invalid', async () => {
            fullRedeemAtMaturityRequest =
                new request_1.FullRedeemAtMaturityRequest({
                    ...BondFixture_1.FullRedeemAtMaturityRequestFixture.create(),
                    securityId: 'invalid',
                });
            await expect(Bond_1.default.fullRedeemAtMaturity(fullRedeemAtMaturityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if sourceId is invalid', async () => {
            fullRedeemAtMaturityRequest =
                new request_1.FullRedeemAtMaturityRequest({
                    ...BondFixture_1.FullRedeemAtMaturityRequestFixture.create(),
                    sourceId: 'invalid',
                });
            await expect(Bond_1.default.fullRedeemAtMaturity(fullRedeemAtMaturityRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getCouponHolders', () => {
        getCouponHoldersRequest = new request_1.GetCouponHoldersRequest(BondFixture_1.GetCouponHoldersQueryFixture.create());
        it('should get coupon holders successfully', async () => {
            const expectedResponse = {
                payload: [transactionId],
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getCouponHolders(getCouponHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetCouponHoldersRequest.name, getCouponHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponHoldersQuery_1.GetCouponHoldersQuery(getCouponHoldersRequest.securityId, getCouponHoldersRequest.couponId, getCouponHoldersRequest.start, getCouponHoldersRequest.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(Bond_1.default.getCouponHolders(getCouponHoldersRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetCouponHoldersRequest.name, getCouponHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetCouponHoldersQuery_1.GetCouponHoldersQuery(getCouponHoldersRequest.securityId, getCouponHoldersRequest.couponId, getCouponHoldersRequest.start, getCouponHoldersRequest.end));
        });
        it('should throw error if securityId is invalid', async () => {
            getCouponHoldersRequest = new request_1.GetCouponHoldersRequest({
                ...BondFixture_1.GetCouponHoldersQueryFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getCouponHolders(getCouponHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if couponId is invalid', async () => {
            getCouponHoldersRequest = new request_1.GetCouponHoldersRequest({
                ...BondFixture_1.GetCouponHoldersQueryFixture.create(),
                couponId: -1,
            });
            await expect(Bond_1.default.getCouponHolders(getCouponHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if start is invalid', async () => {
            getCouponHoldersRequest = new request_1.GetCouponHoldersRequest({
                ...BondFixture_1.GetCouponHoldersQueryFixture.create(),
                start: -1,
            });
            await expect(Bond_1.default.getCouponHolders(getCouponHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if end is invalid', async () => {
            getCouponHoldersRequest = new request_1.GetCouponHoldersRequest({
                ...BondFixture_1.GetCouponHoldersQueryFixture.create(),
                end: -1,
            });
            await expect(Bond_1.default.getCouponHolders(getCouponHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('getTotalCouponHolders', () => {
        getTotalCouponHoldersRequest = new request_1.GetTotalCouponHoldersRequest(BondFixture_1.GetTotalCouponHoldersRequestFixture.create());
        it('should get total coupon holders successfully', async () => {
            const expectedResponse = {
                payload: 1,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getTotalCouponHolders(getTotalCouponHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalCouponHoldersRequest.name, getTotalCouponHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalCouponHoldersQuery_1.GetTotalCouponHoldersQuery(getTotalCouponHoldersRequest.securityId, getTotalCouponHoldersRequest.couponId));
            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(Bond_1.default.getTotalCouponHolders(getTotalCouponHoldersRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalCouponHoldersRequest.name, getTotalCouponHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalCouponHoldersQuery_1.GetTotalCouponHoldersQuery(getTotalCouponHoldersRequest.securityId, getTotalCouponHoldersRequest.couponId));
        });
        it('should throw error if securityId is invalid', async () => {
            getTotalCouponHoldersRequest = new request_1.GetTotalCouponHoldersRequest({
                ...BondFixture_1.GetTotalCouponHoldersRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getTotalCouponHolders(getTotalCouponHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if couponId is invalid', async () => {
            getTotalCouponHoldersRequest = new request_1.GetTotalCouponHoldersRequest({
                ...BondFixture_1.GetTotalCouponHoldersRequestFixture.create(),
                couponId: -1,
            });
            await expect(Bond_1.default.getTotalCouponHolders(getTotalCouponHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('createTrexSuite', () => {
        createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create());
        it('should create 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 Bond_1.default.createTrexSuite(createTrexSuiteBondRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('CreateTrexSuiteBondRequest', createTrexSuiteBondRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateTrexSuiteBondCommand_1.CreateTrexSuiteBondCommand(createTrexSuiteBondRequest.salt, createTrexSuiteBondRequest.owner, createTrexSuiteBondRequest.irs, createTrexSuiteBondRequest.onchainId, createTrexSuiteBondRequest.irAgents, createTrexSuiteBondRequest.tokenAgents, createTrexSuiteBondRequest.compliancesModules, createTrexSuiteBondRequest.complianceSettings, createTrexSuiteBondRequest.claimTopics, createTrexSuiteBondRequest.issuers, createTrexSuiteBondRequest.issuerClaims, expect.objectContaining({
                name: createTrexSuiteBondRequest.name,
                symbol: createTrexSuiteBondRequest.symbol,
                isin: createTrexSuiteBondRequest.isin,
                decimals: createTrexSuiteBondRequest.decimals,
                isWhiteList: createTrexSuiteBondRequest.isWhiteList,
                isControllable: createTrexSuiteBondRequest.isControllable,
                arePartitionsProtected: createTrexSuiteBondRequest.arePartitionsProtected,
                clearingActive: createTrexSuiteBondRequest.clearingActive,
                internalKycActivated: createTrexSuiteBondRequest.internalKycActivated,
                isMultiPartition: createTrexSuiteBondRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createTrexSuiteBondRequest.numberOfUnits),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createTrexSuiteBondRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createTrexSuiteBondRequest.regulationSubType),
                isCountryControlListWhiteList: createTrexSuiteBondRequest.isCountryControlListWhiteList,
                countries: createTrexSuiteBondRequest.countries,
                info: createTrexSuiteBondRequest.info,
            }), createTrexSuiteBondRequest.currency, createTrexSuiteBondRequest.nominalValue, createTrexSuiteBondRequest.nominalValueDecimals, createTrexSuiteBondRequest.startingDate, createTrexSuiteBondRequest.maturityDate, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createTrexSuiteBondRequest.configId, createTrexSuiteBondRequest.configVersion, createTrexSuiteBondRequest.diamondOwnerAccount, createTrexSuiteBondRequest.proceedRecipientsIds, createTrexSuiteBondRequest.proceedRecipientsData, createTrexSuiteBondRequest.externalPauses, createTrexSuiteBondRequest.externalControlLists, createTrexSuiteBondRequest.externalKycLists, createTrexSuiteBondRequest.complianceId, createTrexSuiteBondRequest.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(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('CreateTrexSuiteBondRequest', createTrexSuiteBondRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateTrexSuiteBondCommand_1.CreateTrexSuiteBondCommand(createTrexSuiteBondRequest.salt, createTrexSuiteBondRequest.owner, createTrexSuiteBondRequest.irs, createTrexSuiteBondRequest.onchainId, createTrexSuiteBondRequest.irAgents, createTrexSuiteBondRequest.tokenAgents, createTrexSuiteBondRequest.compliancesModules, createTrexSuiteBondRequest.complianceSettings, createTrexSuiteBondRequest.claimTopics, createTrexSuiteBondRequest.issuers, createTrexSuiteBondRequest.issuerClaims, expect.objectContaining({
                name: createTrexSuiteBondRequest.name,
                symbol: createTrexSuiteBondRequest.symbol,
                isin: createTrexSuiteBondRequest.isin,
                decimals: createTrexSuiteBondRequest.decimals,
                isWhiteList: createTrexSuiteBondRequest.isWhiteList,
                isControllable: createTrexSuiteBondRequest.isControllable,
                arePartitionsProtected: createTrexSuiteBondRequest.arePartitionsProtected,
                clearingActive: createTrexSuiteBondRequest.clearingActive,
                internalKycActivated: createTrexSuiteBondRequest.internalKycActivated,
                isMultiPartition: createTrexSuiteBondRequest.isMultiPartition,
                maxSupply: BigDecimal_1.default.fromString(createTrexSuiteBondRequest.numberOfUnits),
                regulationType: RegulationType_1.CastRegulationType.fromNumber(createTrexSuiteBondRequest.regulationType),
                regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(createTrexSuiteBondRequest.regulationSubType),
                isCountryControlListWhiteList: createTrexSuiteBondRequest.isCountryControlListWhiteList,
                countries: createTrexSuiteBondRequest.countries,
                info: createTrexSuiteBondRequest.info,
            }), createTrexSuiteBondRequest.currency, createTrexSuiteBondRequest.nominalValue, createTrexSuiteBondRequest.nominalValueDecimals, createTrexSuiteBondRequest.startingDate, createTrexSuiteBondRequest.maturityDate, new ContractId_1.default(factoryAddress), new ContractId_1.default(resolverAddress), createTrexSuiteBondRequest.configId, createTrexSuiteBondRequest.configVersion, createTrexSuiteBondRequest.diamondOwnerAccount, createTrexSuiteBondRequest.proceedRecipientsIds, createTrexSuiteBondRequest.proceedRecipientsData, createTrexSuiteBondRequest.externalPauses, createTrexSuiteBondRequest.externalControlLists, createTrexSuiteBondRequest.externalKycLists, createTrexSuiteBondRequest.complianceId, createTrexSuiteBondRequest.identityRegistryId));
        });
        it('should throw error if name is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({ name: '' }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if symbol is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                symbol: '',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if isin is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                isin: '',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if decimals is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                decimals: 2.85,
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if diamondOwnerAccount is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                diamondOwnerAccount: 'invalid',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if currency is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                currency: 'invalid',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if numberOfUnits is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                numberOfUnits: 'invalid',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if nominalValue is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                nominalValue: 'invalid',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if startingDate is invalid', async () => {
            const time = Math.floor(_1.faker.date.past().getTime() / 1000);
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                startingDate: time.toString(),
                maturityDate: (time + 10).toString(),
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if maturityDate is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                maturityDate: Math.floor(_1.faker.date.past().getTime() / 1000).toString(),
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if regulationSubType is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                regulationSubType: 5,
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if configId is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                configId: 'invalid',
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if externalPauses is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                externalPauses: ['invalid'],
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if externalControlLists is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                externalControlLists: ['invalid'],
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if externalKycLists is invalid', async () => {
            createTrexSuiteBondRequest = new request_1.CreateTrexSuiteBondRequest(BondFixture_1.CreateTrexSuiteBondRequestFixture.create({
                externalKycLists: ['invalid'],
            }));
            await expect(Bond_1.default.createTrexSuite(createTrexSuiteBondRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('AddProceedRecipientRequest', () => {
        const addProceedRecipientRequest = new AddProceedRecipientRequest_1.default(BondFixture_1.AddProceedRecipientRequestFixture.create());
        it('should add proceed recipient successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.addProceedRecipient(addProceedRecipientRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('AddProceedRecipientRequest', addProceedRecipientRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddProceedRecipientCommand_1.AddProceedRecipientCommand(addProceedRecipientRequest.securityId, addProceedRecipientRequest.proceedRecipientId, addProceedRecipientRequest.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(Bond_1.default.addProceedRecipient(addProceedRecipientRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('AddProceedRecipientRequest', addProceedRecipientRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddProceedRecipientCommand_1.AddProceedRecipientCommand(addProceedRecipientRequest.securityId, addProceedRecipientRequest.proceedRecipientId, addProceedRecipientRequest.data));
        });
        it('should throw error if securityId is invalid', async () => {
            let addProceedRecipientRequest = new AddProceedRecipientRequest_1.default({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.addProceedRecipient(addProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if data is invalid', async () => {
            let addProceedRecipientRequest = new AddProceedRecipientRequest_1.default({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                data: 'invalid',
            });
            await expect(Bond_1.default.addProceedRecipient(addProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if proceedRecipientId is invalid', async () => {
            let addProceedRecipientRequest = new AddProceedRecipientRequest_1.default({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                proceedRecipientId: 'invalid',
            });
            await expect(Bond_1.default.addProceedRecipient(addProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('RemoveProceedRecipientRequest', () => {
        const removeProceedRecipientRequest = new request_1.RemoveProceedRecipientRequest(BondFixture_1.RemoveProceedRecipientRequestFixture.create());
        it('should remove proceed recipient successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.removeProceedRecipient(removeProceedRecipientRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('RemoveProceedRecipientRequest', removeProceedRecipientRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveProceedRecipientCommand_1.RemoveProceedRecipientCommand(removeProceedRecipientRequest.securityId, removeProceedRecipientRequest.proceedRecipientId));
            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(Bond_1.default.removeProceedRecipient(removeProceedRecipientRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('RemoveProceedRecipientRequest', removeProceedRecipientRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveProceedRecipientCommand_1.RemoveProceedRecipientCommand(removeProceedRecipientRequest.securityId, removeProceedRecipientRequest.proceedRecipientId));
        });
        it('should throw error if securityId is invalid', async () => {
            let removeProceedRecipientRequest = new request_1.RemoveProceedRecipientRequest({
                ...BondFixture_1.RemoveProceedRecipientRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.removeProceedRecipient(removeProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if proceedRecipientId is invalid', async () => {
            let removeProceedRecipientRequest = new request_1.RemoveProceedRecipientRequest({
                ...BondFixture_1.RemoveProceedRecipientRequestFixture.create(),
                proceedRecipientId: 'invalid',
            });
            await expect(Bond_1.default.removeProceedRecipient(removeProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('UpdateProceedRecipientDataRequest', () => {
        const updateProceedRecipientDataRequest = new request_1.UpdateProceedRecipientDataRequest(BondFixture_1.UpdateProceedRecipientDataRequestFixture.create());
        it('should update proceed recipient data successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.updateProceedRecipientData(updateProceedRecipientDataRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('UpdateProceedRecipientDataRequest', updateProceedRecipientDataRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateProceedRecipientDataCommand_1.UpdateProceedRecipientDataCommand(updateProceedRecipientDataRequest.securityId, updateProceedRecipientDataRequest.proceedRecipientId, updateProceedRecipientDataRequest.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(Bond_1.default.updateProceedRecipientData(updateProceedRecipientDataRequest)).rejects.toThrow('Command execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('UpdateProceedRecipientDataRequest', updateProceedRecipientDataRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateProceedRecipientDataCommand_1.UpdateProceedRecipientDataCommand(updateProceedRecipientDataRequest.securityId, updateProceedRecipientDataRequest.proceedRecipientId, updateProceedRecipientDataRequest.data));
        });
        it('should throw error if securityId is invalid', async () => {
            let updateProceedRecipientDataRequest = new request_1.UpdateProceedRecipientDataRequest({
                ...BondFixture_1.UpdateProceedRecipientDataRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.updateProceedRecipientData(updateProceedRecipientDataRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if data is invalid', async () => {
            let updateProceedRecipientDataRequest = new request_1.UpdateProceedRecipientDataRequest({
                ...BondFixture_1.UpdateProceedRecipientDataRequestFixture.create(),
                data: 'invalid',
            });
            await expect(Bond_1.default.updateProceedRecipientData(updateProceedRecipientDataRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if proceedRecipientId is invalid', async () => {
            let updateProceedRecipientDataRequest = new request_1.UpdateProceedRecipientDataRequest({
                ...BondFixture_1.UpdateProceedRecipientDataRequestFixture.create(),
                proceedRecipientId: 'invalid',
            });
            await expect(Bond_1.default.updateProceedRecipientData(updateProceedRecipientDataRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('IsProceedRecipientRequest', () => {
        const isProceedRecipientRequest = new request_1.IsProceedRecipientRequest(BondFixture_1.IsProceedRecipientRequestFixture.create());
        it('should get isProceedRecipient successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.isProceedRecipient(isProceedRecipientRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('IsProceedRecipientRequest', isProceedRecipientRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsProceedRecipientQuery_1.IsProceedRecipientQuery(isProceedRecipientRequest.securityId, isProceedRecipientRequest.proceedRecipientId));
            expect(result).toEqual(expectedResponse);
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.isProceedRecipient(isProceedRecipientRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('IsProceedRecipientRequest', isProceedRecipientRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsProceedRecipientQuery_1.IsProceedRecipientQuery(isProceedRecipientRequest.securityId, isProceedRecipientRequest.proceedRecipientId));
        });
        it('should throw error if securityId is invalid', async () => {
            let isProceedRecipientRequest = new request_1.IsProceedRecipientRequest({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.isProceedRecipient(isProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if proceedRecipientId is invalid', async () => {
            let isProceedRecipientRequest = new request_1.IsProceedRecipientRequest({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                proceedRecipientId: 'invalid',
            });
            await expect(Bond_1.default.isProceedRecipient(isProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('GetProceedRecipientsCountRequest', () => {
        const getProceedRecipientsCountRequest = new request_1.GetProceedRecipientsCountRequest(BondFixture_1.GetProceedRecipientsCountRequestFixture.create());
        it('should get proceedRecipients count successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getProceedRecipientsCount(getProceedRecipientsCountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetProceedRecipientsCountRequest', getProceedRecipientsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetProceedRecipientsCountQuery_1.GetProceedRecipientsCountQuery(getProceedRecipientsCountRequest.securityId));
            expect(result).toEqual(expectedResponse);
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getProceedRecipientsCount(getProceedRecipientsCountRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetProceedRecipientsCountRequest', getProceedRecipientsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetProceedRecipientsCountQuery_1.GetProceedRecipientsCountQuery(getProceedRecipientsCountRequest.securityId));
        });
        it('should throw error if securityId is invalid', async () => {
            let getProceedRecipientsCountRequest = new request_1.GetProceedRecipientsCountRequest({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getProceedRecipientsCount(getProceedRecipientsCountRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('GetProceedRecipientDataRequest', () => {
        const getProceedRecipientDataRequest = new request_1.GetProceedRecipientDataRequest(BondFixture_1.GetProceedRecipientDataRequestFixture.create());
        it('should get proceed recipient data successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getProceedRecipientData(getProceedRecipientDataRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetProceedRecipientDataRequest', getProceedRecipientDataRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetProceedRecipientDataQuery_1.GetProceedRecipientDataQuery(getProceedRecipientDataRequest.securityId, getProceedRecipientDataRequest.proceedRecipientId));
            expect(result).toEqual(expectedResponse);
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getProceedRecipientData(getProceedRecipientDataRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetProceedRecipientDataRequest', getProceedRecipientDataRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetProceedRecipientDataQuery_1.GetProceedRecipientDataQuery(getProceedRecipientDataRequest.securityId, getProceedRecipientDataRequest.proceedRecipientId));
        });
        it('should throw error if securityId is invalid', async () => {
            let isProceedRecipientRequest = new request_1.GetProceedRecipientDataRequest({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.isProceedRecipient(isProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if proceedRecipientId is invalid', async () => {
            let isProceedRecipientRequest = new request_1.GetProceedRecipientDataRequest({
                ...BondFixture_1.AddProceedRecipientRequestFixture.create(),
                proceedRecipientId: 'invalid',
            });
            await expect(Bond_1.default.isProceedRecipient(isProceedRecipientRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe('GetProceedRecipientsRequest', () => {
        const getProceedRecipientsRequest = new request_1.GetProceedRecipientsRequest(BondFixture_1.GetProceedRecipientsRequestFixture.create());
        it('should get proceedRecipients successfully', async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Bond_1.default.getProceedRecipients(getProceedRecipientsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith('GetProceedRecipientsRequest', getProceedRecipientsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetProceedRecipientsQuery_1.GetProceedRecipientsQuery(getProceedRecipientsRequest.securityId, getProceedRecipientsRequest.pageIndex, getProceedRecipientsRequest.pageSize));
            expect(result).toEqual(expectedResponse);
        });
        it('should throw an error if query execution fails', async () => {
            const error = new Error('Query execution failed');
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Bond_1.default.getProceedRecipients(getProceedRecipientsRequest)).rejects.toThrow('Query execution failed');
            expect(handleValidationSpy).toHaveBeenCalledWith('GetProceedRecipientsRequest', getProceedRecipientsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetProceedRecipientsQuery_1.GetProceedRecipientsQuery(getProceedRecipientsRequest.securityId, getProceedRecipientsRequest.pageIndex, getProceedRecipientsRequest.pageSize));
        });
        it('should throw error if securityId is invalid', async () => {
            let getProceedRecipientsRequest = new request_1.GetProceedRecipientsRequest({
                ...BondFixture_1.GetProceedRecipientsRequestFixture.create(),
                securityId: 'invalid',
            });
            await expect(Bond_1.default.getProceedRecipients(getProceedRecipientsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it('should throw error if page size is invalid', async () => {
            let getProceedRecipientsRequest = new request_1.GetProceedRecipientsRequest({
                ...BondFixture_1.GetProceedRecipientsRequestFixture.create(),
                pageSize: -1,
            });
            await expect(Bond_1.default.getProceedRecipients(getProceedRecipientsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
});
