"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 Amortization_1 = __importDefault(require("./Amortization"));
const AmortizationFixture_1 = require("../../../../../__tests__/fixtures/amortization/AmortizationFixture");
const SetAmortizationCommand_1 = require("../../../../app/usecase/command/amortization/set/SetAmortizationCommand");
const CancelAmortizationCommand_1 = require("../../../../app/usecase/command/amortization/cancel/CancelAmortizationCommand");
const SetAmortizationHoldCommand_1 = require("../../../../app/usecase/command/amortization/setHold/SetAmortizationHoldCommand");
const ReleaseAmortizationHoldCommand_1 = require("../../../../app/usecase/command/amortization/releaseHold/ReleaseAmortizationHoldCommand");
const GetAmortizationQuery_1 = require("../../../../app/usecase/query/amortization/getAmortization/GetAmortizationQuery");
const GetAmortizationForQuery_1 = require("../../../../app/usecase/query/amortization/getAmortizationFor/GetAmortizationForQuery");
const GetAmortizationsForQuery_1 = require("../../../../app/usecase/query/amortization/getAmortizationsFor/GetAmortizationsForQuery");
const GetAmortizationsCountQuery_1 = require("../../../../app/usecase/query/amortization/getAmortizationsCount/GetAmortizationsCountQuery");
const GetAmortizationHoldersQuery_1 = require("../../../../app/usecase/query/amortization/getAmortizationHolders/GetAmortizationHoldersQuery");
const GetTotalAmortizationHoldersQuery_1 = require("../../../../app/usecase/query/amortization/getTotalAmortizationHolders/GetTotalAmortizationHoldersQuery");
const GetAmortizationPaymentAmountQuery_1 = require("../../../../app/usecase/query/amortization/getAmortizationPaymentAmount/GetAmortizationPaymentAmountQuery");
const GetActiveAmortizationHoldHoldersQuery_1 = require("../../../../app/usecase/query/amortization/getActiveAmortizationHoldHolders/GetActiveAmortizationHoldHoldersQuery");
const GetTotalActiveAmortizationHoldHoldersQuery_1 = require("../../../../app/usecase/query/amortization/getTotalActiveAmortizationHoldHolders/GetTotalActiveAmortizationHoldHoldersQuery");
const GetActiveAmortizationIdsQuery_1 = require("../../../../app/usecase/query/amortization/getActiveAmortizationIds/GetActiveAmortizationIdsQuery");
const GetTotalActiveAmortizationIdsQuery_1 = require("../../../../app/usecase/query/amortization/getTotalActiveAmortizationIds/GetTotalActiveAmortizationIdsQuery");
const SecurityDate_1 = require("../../../../domain/context/shared/SecurityDate");
describe("Amortization", () => {
    let commandBusMock;
    let queryBusMock;
    let setAmortizationRequest;
    let cancelAmortizationRequest;
    let setAmortizationHoldRequest;
    let releaseAmortizationHoldRequest;
    let getAmortizationRequest;
    let getAmortizationForRequest;
    let getAmortizationsForRequest;
    let getAmortizationsCountRequest;
    let getAmortizationHoldersRequest;
    let getTotalAmortizationHoldersRequest;
    let getAmortizationPaymentAmountRequest;
    let getActiveAmortizationHoldHoldersRequest;
    let getTotalActiveAmortizationHoldHoldersRequest;
    let getActiveAmortizationIdsRequest;
    let getTotalActiveAmortizationIdsRequest;
    let handleValidationSpy;
    const transactionId = DataFixture_1.TransactionIdFixture.create().id;
    beforeEach(() => {
        commandBusMock = (0, ts_jest_1.createMock)();
        queryBusMock = (0, ts_jest_1.createMock)();
        handleValidationSpy = jest.spyOn(ValidatedArgs_1.default, "handleValidation");
        jest.spyOn(LogService_1.default, "logError").mockImplementation(() => { });
        Amortization_1.default.commandBus = commandBusMock;
        Amortization_1.default.queryBus = queryBusMock;
    });
    afterEach(() => {
        jest.resetAllMocks();
        jest.restoreAllMocks();
    });
    describe("setAmortization", () => {
        setAmortizationRequest = new request_1.SetAmortizationRequest(AmortizationFixture_1.SetAmortizationRequestFixture.create());
        it("should set amortization successfully", async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.setAmortization(setAmortizationRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("SetAmortizationRequest", setAmortizationRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetAmortizationCommand_1.SetAmortizationCommand(setAmortizationRequest.securityId, setAmortizationRequest.recordTimestamp, setAmortizationRequest.executionTimestamp, setAmortizationRequest.tokensToRedeem));
            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(Amortization_1.default.setAmortization(setAmortizationRequest)).rejects.toThrow("Command execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            setAmortizationRequest = new request_1.SetAmortizationRequest({
                ...AmortizationFixture_1.SetAmortizationRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.setAmortization(setAmortizationRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("cancelAmortization", () => {
        cancelAmortizationRequest = new request_1.CancelAmortizationRequest(AmortizationFixture_1.CancelAmortizationRequestFixture.create());
        it("should cancel amortization successfully", async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.cancelAmortization(cancelAmortizationRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("CancelAmortizationRequest", cancelAmortizationRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CancelAmortizationCommand_1.CancelAmortizationCommand(cancelAmortizationRequest.securityId, cancelAmortizationRequest.amortizationId));
            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(Amortization_1.default.cancelAmortization(cancelAmortizationRequest)).rejects.toThrow("Command execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            cancelAmortizationRequest = new request_1.CancelAmortizationRequest({
                ...AmortizationFixture_1.CancelAmortizationRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.cancelAmortization(cancelAmortizationRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("setAmortizationHold", () => {
        setAmortizationHoldRequest = new request_1.SetAmortizationHoldRequest(AmortizationFixture_1.SetAmortizationHoldRequestFixture.create());
        it("should set amortization hold successfully", async () => {
            const expectedResponse = {
                payload: 1,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.setAmortizationHold(setAmortizationHoldRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("SetAmortizationHoldRequest", setAmortizationHoldRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new SetAmortizationHoldCommand_1.SetAmortizationHoldCommand(setAmortizationHoldRequest.securityId, setAmortizationHoldRequest.amortizationId, setAmortizationHoldRequest.tokenHolder, setAmortizationHoldRequest.tokenAmount));
            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(Amortization_1.default.setAmortizationHold(setAmortizationHoldRequest)).rejects.toThrow("Command execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            setAmortizationHoldRequest = new request_1.SetAmortizationHoldRequest({
                ...AmortizationFixture_1.SetAmortizationHoldRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.setAmortizationHold(setAmortizationHoldRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if tokenHolder is invalid", async () => {
            setAmortizationHoldRequest = new request_1.SetAmortizationHoldRequest({
                ...AmortizationFixture_1.SetAmortizationHoldRequestFixture.create(),
                tokenHolder: "invalid",
            });
            await expect(Amortization_1.default.setAmortizationHold(setAmortizationHoldRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("releaseAmortizationHold", () => {
        releaseAmortizationHoldRequest = new request_1.ReleaseAmortizationHoldRequest(AmortizationFixture_1.ReleaseAmortizationHoldRequestFixture.create());
        it("should release amortization hold successfully", async () => {
            const expectedResponse = {
                payload: true,
                transactionId: transactionId,
            };
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.releaseAmortizationHold(releaseAmortizationHoldRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("ReleaseAmortizationHoldRequest", releaseAmortizationHoldRequest);
            expect(commandBusMock.execute).toHaveBeenCalledTimes(1);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new ReleaseAmortizationHoldCommand_1.ReleaseAmortizationHoldCommand(releaseAmortizationHoldRequest.securityId, releaseAmortizationHoldRequest.amortizationId, releaseAmortizationHoldRequest.tokenHolder));
            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(Amortization_1.default.releaseAmortizationHold(releaseAmortizationHoldRequest)).rejects.toThrow("Command execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            releaseAmortizationHoldRequest = new request_1.ReleaseAmortizationHoldRequest({
                ...AmortizationFixture_1.ReleaseAmortizationHoldRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.releaseAmortizationHold(releaseAmortizationHoldRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAmortization", () => {
        getAmortizationRequest = new request_1.GetAmortizationRequest(AmortizationFixture_1.GetAmortizationRequestFixture.create());
        it("should get amortization successfully", async () => {
            const registeredAmortization = AmortizationFixture_1.RegisteredAmortizationFixture.create();
            const expectedResponse = {
                amortization: registeredAmortization,
            };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getAmortization(getAmortizationRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAmortizationRequest", getAmortizationRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationQuery_1.GetAmortizationQuery(getAmortizationRequest.securityId, getAmortizationRequest.amortizationId));
            expect(result).toEqual(expect.objectContaining({
                amortizationId: getAmortizationRequest.amortizationId,
                recordDate: new Date(registeredAmortization.amortization.recordDate * SecurityDate_1.ONE_THOUSAND),
                executionDate: new Date(registeredAmortization.amortization.executionDate * SecurityDate_1.ONE_THOUSAND),
                tokensToRedeem: registeredAmortization.amortization.tokensToRedeem.toString(),
                snapshotId: registeredAmortization.snapshotId,
                isDisabled: registeredAmortization.isDisabled,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Amortization_1.default.getAmortization(getAmortizationRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getAmortizationRequest = new request_1.GetAmortizationRequest({
                ...AmortizationFixture_1.GetAmortizationRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getAmortization(getAmortizationRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAllAmortizations", () => {
        getAmortizationsCountRequest = new request_1.GetAmortizationsCountRequest(AmortizationFixture_1.GetAmortizationsCountRequestFixture.create());
        it("should get all amortizations successfully", async () => {
            const registeredAmortization = AmortizationFixture_1.RegisteredAmortizationFixture.create();
            const countResponse = { payload: 1 };
            const amortizationResponse = { amortization: registeredAmortization };
            queryBusMock.execute.mockResolvedValueOnce(countResponse).mockResolvedValueOnce(amortizationResponse);
            const result = await Amortization_1.default.getAllAmortizations(getAmortizationsCountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAmortizationsCountRequest", getAmortizationsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(2);
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(1, new GetAmortizationsCountQuery_1.GetAmortizationsCountQuery(getAmortizationsCountRequest.securityId));
            expect(queryBusMock.execute).toHaveBeenNthCalledWith(2, new GetAmortizationQuery_1.GetAmortizationQuery(getAmortizationsCountRequest.securityId, 1));
            expect(result).toEqual(expect.arrayContaining([
                {
                    amortizationId: 1,
                    recordDate: new Date(registeredAmortization.amortization.recordDate * SecurityDate_1.ONE_THOUSAND),
                    executionDate: new Date(registeredAmortization.amortization.executionDate * SecurityDate_1.ONE_THOUSAND),
                    tokensToRedeem: registeredAmortization.amortization.tokensToRedeem.toString(),
                    snapshotId: registeredAmortization.snapshotId,
                    isDisabled: registeredAmortization.isDisabled,
                },
            ]));
        });
        it("should return empty array if count is 0", async () => {
            const countResponse = { payload: 0 };
            queryBusMock.execute.mockResolvedValueOnce(countResponse);
            const result = await Amortization_1.default.getAllAmortizations(getAmortizationsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationsCountQuery_1.GetAmortizationsCountQuery(getAmortizationsCountRequest.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(Amortization_1.default.getAllAmortizations(getAmortizationsCountRequest)).rejects.toThrow("Query execution failed");
        });
    });
    describe("getAmortizationFor", () => {
        getAmortizationForRequest = new request_1.GetAmortizationForRequest(AmortizationFixture_1.GetAmortizationForRequestFixture.create());
        it("should get amortization for successfully", async () => {
            const amortizationFor = AmortizationFixture_1.AmortizationForFixture.create();
            const expectedResponse = { amortizationFor };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getAmortizationFor(getAmortizationForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAmortizationForRequest", getAmortizationForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationForQuery_1.GetAmortizationForQuery(getAmortizationForRequest.securityId, getAmortizationForRequest.targetId, getAmortizationForRequest.amortizationId));
            expect(result).toEqual(expect.objectContaining({
                account: amortizationFor.account,
                holdId: amortizationFor.holdId,
                holdActive: amortizationFor.holdActive,
                decimalsHeld: amortizationFor.decimalsHeld,
                decimalsBalance: amortizationFor.decimalsBalance,
                recordDateReached: amortizationFor.recordDateReached,
                nominalValueDecimals: amortizationFor.nominalValueDecimals,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Amortization_1.default.getAmortizationFor(getAmortizationForRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getAmortizationForRequest = new request_1.GetAmortizationForRequest({
                ...AmortizationFixture_1.GetAmortizationForRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getAmortizationFor(getAmortizationForRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAmortizationsFor", () => {
        getAmortizationsForRequest = new request_1.GetAmortizationsForRequest(AmortizationFixture_1.GetAmortizationsForRequestFixture.create());
        it("should get amortizations for successfully", async () => {
            const amortizationsFor = [AmortizationFixture_1.AmortizationForFixture.create()];
            const expectedResponse = { payload: amortizationsFor };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getAmortizationsFor(getAmortizationsForRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAmortizationsForRequest", getAmortizationsForRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationsForQuery_1.GetAmortizationsForQuery(getAmortizationsForRequest.securityId, getAmortizationsForRequest.amortizationId, getAmortizationsForRequest.start, getAmortizationsForRequest.end));
            expect(result).toHaveLength(1);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Amortization_1.default.getAmortizationsFor(getAmortizationsForRequest)).rejects.toThrow("Query execution failed");
        });
    });
    describe("getAmortizationsCount", () => {
        getAmortizationsCountRequest = new request_1.GetAmortizationsCountRequest(AmortizationFixture_1.GetAmortizationsCountRequestFixture.create());
        it("should get amortizations count successfully", async () => {
            const expectedResponse = { payload: 5 };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getAmortizationsCount(getAmortizationsCountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAmortizationsCountRequest", getAmortizationsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationsCountQuery_1.GetAmortizationsCountQuery(getAmortizationsCountRequest.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(Amortization_1.default.getAmortizationsCount(getAmortizationsCountRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getAmortizationsCountRequest = new request_1.GetAmortizationsCountRequest({
                ...AmortizationFixture_1.GetAmortizationsCountRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getAmortizationsCount(getAmortizationsCountRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAmortizationHolders", () => {
        getAmortizationHoldersRequest = new request_1.GetAmortizationHoldersRequest(AmortizationFixture_1.GetAmortizationHoldersRequestFixture.create());
        it("should get amortization holders successfully", async () => {
            const holderId = DataFixture_1.HederaIdPropsFixture.create().value;
            const expectedResponse = { payload: [holderId] };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getAmortizationHolders(getAmortizationHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetAmortizationHoldersRequest.name, getAmortizationHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationHoldersQuery_1.GetAmortizationHoldersQuery(getAmortizationHoldersRequest.securityId, getAmortizationHoldersRequest.amortizationId, getAmortizationHoldersRequest.start, getAmortizationHoldersRequest.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(Amortization_1.default.getAmortizationHolders(getAmortizationHoldersRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getAmortizationHoldersRequest = new request_1.GetAmortizationHoldersRequest({
                ...AmortizationFixture_1.GetAmortizationHoldersRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getAmortizationHolders(getAmortizationHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getTotalAmortizationHolders", () => {
        getTotalAmortizationHoldersRequest = new request_1.GetTotalAmortizationHoldersRequest(AmortizationFixture_1.GetTotalAmortizationHoldersRequestFixture.create());
        it("should get total amortization holders successfully", async () => {
            const expectedResponse = { payload: 3 };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getTotalAmortizationHolders(getTotalAmortizationHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalAmortizationHoldersRequest.name, getTotalAmortizationHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalAmortizationHoldersQuery_1.GetTotalAmortizationHoldersQuery(getTotalAmortizationHoldersRequest.securityId, getTotalAmortizationHoldersRequest.amortizationId));
            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(Amortization_1.default.getTotalAmortizationHolders(getTotalAmortizationHoldersRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getTotalAmortizationHoldersRequest = new request_1.GetTotalAmortizationHoldersRequest({
                ...AmortizationFixture_1.GetTotalAmortizationHoldersRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getTotalAmortizationHolders(getTotalAmortizationHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getAmortizationPaymentAmount", () => {
        getAmortizationPaymentAmountRequest = new request_1.GetAmortizationPaymentAmountRequest(AmortizationFixture_1.GetAmortizationPaymentAmountRequestFixture.create());
        it("should get amortization payment amount successfully", async () => {
            const paymentAmount = AmortizationFixture_1.AmortizationPaymentAmountFixture.create();
            const expectedResponse = { amortizationPaymentAmount: paymentAmount };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getAmortizationPaymentAmount(getAmortizationPaymentAmountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetAmortizationPaymentAmountRequest", getAmortizationPaymentAmountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetAmortizationPaymentAmountQuery_1.GetAmortizationPaymentAmountQuery(getAmortizationPaymentAmountRequest.securityId, getAmortizationPaymentAmountRequest.amortizationId, getAmortizationPaymentAmountRequest.tokenHolder));
            expect(result).toEqual(expect.objectContaining({
                tokenAmount: paymentAmount.tokenAmount.toString(),
                decimals: paymentAmount.decimals,
            }));
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(Amortization_1.default.getAmortizationPaymentAmount(getAmortizationPaymentAmountRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getAmortizationPaymentAmountRequest = new request_1.GetAmortizationPaymentAmountRequest({
                ...AmortizationFixture_1.GetAmortizationPaymentAmountRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getAmortizationPaymentAmount(getAmortizationPaymentAmountRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getActiveAmortizationHoldHolders", () => {
        getActiveAmortizationHoldHoldersRequest = new request_1.GetActiveAmortizationHoldHoldersRequest(AmortizationFixture_1.GetActiveAmortizationHoldHoldersRequestFixture.create());
        it("should get active amortization hold holders successfully", async () => {
            const holderId = DataFixture_1.HederaIdPropsFixture.create().value;
            const expectedResponse = { payload: [holderId] };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getActiveAmortizationHoldHolders(getActiveAmortizationHoldHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetActiveAmortizationHoldHoldersRequest.name, getActiveAmortizationHoldHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetActiveAmortizationHoldHoldersQuery_1.GetActiveAmortizationHoldHoldersQuery(getActiveAmortizationHoldHoldersRequest.securityId, getActiveAmortizationHoldHoldersRequest.amortizationId, getActiveAmortizationHoldHoldersRequest.start, getActiveAmortizationHoldHoldersRequest.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(Amortization_1.default.getActiveAmortizationHoldHolders(getActiveAmortizationHoldHoldersRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getActiveAmortizationHoldHoldersRequest = new request_1.GetActiveAmortizationHoldHoldersRequest({
                ...AmortizationFixture_1.GetActiveAmortizationHoldHoldersRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getActiveAmortizationHoldHolders(getActiveAmortizationHoldHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getTotalActiveAmortizationHoldHolders", () => {
        getTotalActiveAmortizationHoldHoldersRequest = new request_1.GetTotalActiveAmortizationHoldHoldersRequest(AmortizationFixture_1.GetTotalActiveAmortizationHoldHoldersRequestFixture.create());
        it("should get total active amortization hold holders successfully", async () => {
            const expectedResponse = { payload: 2 };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getTotalActiveAmortizationHoldHolders(getTotalActiveAmortizationHoldHoldersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalActiveAmortizationHoldHoldersRequest.name, getTotalActiveAmortizationHoldHoldersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalActiveAmortizationHoldHoldersQuery_1.GetTotalActiveAmortizationHoldHoldersQuery(getTotalActiveAmortizationHoldHoldersRequest.securityId, getTotalActiveAmortizationHoldHoldersRequest.amortizationId));
            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(Amortization_1.default.getTotalActiveAmortizationHoldHolders(getTotalActiveAmortizationHoldHoldersRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getTotalActiveAmortizationHoldHoldersRequest = new request_1.GetTotalActiveAmortizationHoldHoldersRequest({
                ...AmortizationFixture_1.GetTotalActiveAmortizationHoldHoldersRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getTotalActiveAmortizationHoldHolders(getTotalActiveAmortizationHoldHoldersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getActiveAmortizationIds", () => {
        getActiveAmortizationIdsRequest = new request_1.GetActiveAmortizationIdsRequest(AmortizationFixture_1.GetActiveAmortizationIdsRequestFixture.create());
        it("should get active amortization IDs successfully", async () => {
            const expectedResponse = { payload: [1, 2, 3] };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getActiveAmortizationIds(getActiveAmortizationIdsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetActiveAmortizationIdsRequest.name, getActiveAmortizationIdsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetActiveAmortizationIdsQuery_1.GetActiveAmortizationIdsQuery(getActiveAmortizationIdsRequest.securityId, getActiveAmortizationIdsRequest.start, getActiveAmortizationIdsRequest.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(Amortization_1.default.getActiveAmortizationIds(getActiveAmortizationIdsRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getActiveAmortizationIdsRequest = new request_1.GetActiveAmortizationIdsRequest({
                ...AmortizationFixture_1.GetActiveAmortizationIdsRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getActiveAmortizationIds(getActiveAmortizationIdsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getTotalActiveAmortizationIds", () => {
        getTotalActiveAmortizationIdsRequest = new request_1.GetTotalActiveAmortizationIdsRequest(AmortizationFixture_1.GetTotalActiveAmortizationIdsRequestFixture.create());
        it("should get total active amortization IDs successfully", async () => {
            const expectedResponse = { payload: 7 };
            queryBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await Amortization_1.default.getTotalActiveAmortizationIds(getTotalActiveAmortizationIdsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith(request_1.GetTotalActiveAmortizationIdsRequest.name, getTotalActiveAmortizationIdsRequest);
            expect(queryBusMock.execute).toHaveBeenCalledTimes(1);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetTotalActiveAmortizationIdsQuery_1.GetTotalActiveAmortizationIdsQuery(getTotalActiveAmortizationIdsRequest.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(Amortization_1.default.getTotalActiveAmortizationIds(getTotalActiveAmortizationIdsRequest)).rejects.toThrow("Query execution failed");
        });
        it("should throw error if securityId is invalid", async () => {
            getTotalActiveAmortizationIdsRequest = new request_1.GetTotalActiveAmortizationIdsRequest({
                ...AmortizationFixture_1.GetTotalActiveAmortizationIdsRequestFixture.create(),
                securityId: "invalid",
            });
            await expect(Amortization_1.default.getTotalActiveAmortizationIds(getTotalActiveAmortizationIdsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
});
