"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 ExternalKycListsFixture_1 = require("../../../../__tests__/fixtures/externalKycLists/ExternalKycListsFixture");
const ExternalKycListsManagement_1 = __importDefault(require("./ExternalKycListsManagement"));
const UpdateExternalKycListsCommand_1 = require("../../../app/usecase/command/security/externalKycLists/updateExternalKycLists/UpdateExternalKycListsCommand");
const AddExternalKycListCommand_1 = require("../../../app/usecase/command/security/externalKycLists/addExternalKycList/AddExternalKycListCommand");
const RemoveExternalKycListCommand_1 = require("../../../app/usecase/command/security/externalKycLists/removeExternalKycList/RemoveExternalKycListCommand");
const IsExternallyGrantedQuery_1 = require("../../../app/usecase/query/security/externalKycLists/isExternallyGranted/IsExternallyGrantedQuery");
const IsExternalKycListQuery_1 = require("../../../app/usecase/query/security/externalKycLists/isExternalKycList/IsExternalKycListQuery");
const GetExternalKycListsCountQuery_1 = require("../../../app/usecase/query/security/externalKycLists/getExternalKycListsCount/GetExternalKycListsCountQuery");
const GetExternalKycListsMembersQuery_1 = require("../../../app/usecase/query/security/externalKycLists/getExternalKycListsMembers/GetExternalKycListsMembersQuery");
const GrantKycMockCommand_1 = require("../../../app/usecase/command/security/externalKycLists/mock/grantKycMock/GrantKycMockCommand");
const RevokeKycMockCommand_1 = require("../../../app/usecase/command/security/externalKycLists/mock/revokeKycMock/RevokeKycMockCommand");
const GetKycStatusMockQuery_1 = require("../../../app/usecase/query/security/externalKycLists/mock/getKycStatusMock/GetKycStatusMockQuery");
const CreateExternalKycMockCommand_1 = require("../../../app/usecase/command/security/externalKycLists/mock/createExternalKycMock/CreateExternalKycMockCommand");
describe("ExternalKycListsManagement", () => {
    let commandBusMock;
    let queryBusMock;
    let updateExternalKycListsRequest;
    let addExternalKycListsRequest;
    let removeExternalKycListsRequest;
    let isExternallyGrantedRequest;
    let isExternalKycListRequest;
    let getExternalKycListsCountRequest;
    let getExternalKycListsMembersRequest;
    let grantKycMockRequest;
    let revokeKycMockRequest;
    let getKycStatusMockRequest;
    let handleValidationSpy;
    const transactionId = DataFixture_1.TransactionIdFixture.create().id;
    const hederaId = DataFixture_1.HederaIdPropsFixture.create().value;
    const expectedResponse = {
        payload: true,
        transactionId: transactionId,
    };
    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(() => { });
        ExternalKycListsManagement_1.default.commandBus = commandBusMock;
        ExternalKycListsManagement_1.default.queryBus = queryBusMock;
    });
    afterEach(() => {
        jest.resetAllMocks();
        jest.restoreAllMocks();
    });
    describe("updateExternalKycListsPauses", () => {
        updateExternalKycListsRequest = new request_1.UpdateExternalKycListsRequest(ExternalKycListsFixture_1.UpdateExternalKycListsRequestFixture.create());
        it("should update external kyc lists successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalKycListsManagement_1.default.updateExternalKycLists(updateExternalKycListsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("UpdateExternalKycListsRequest", updateExternalKycListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateExternalKycListsCommand_1.UpdateExternalKycListsCommand(updateExternalKycListsRequest.securityId, updateExternalKycListsRequest.externalKycListsAddresses, updateExternalKycListsRequest.actives));
            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(ExternalKycListsManagement_1.default.updateExternalKycLists(updateExternalKycListsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("UpdateExternalKycListsRequest", updateExternalKycListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateExternalKycListsCommand_1.UpdateExternalKycListsCommand(updateExternalKycListsRequest.securityId, updateExternalKycListsRequest.externalKycListsAddresses, updateExternalKycListsRequest.actives));
        });
        it("should throw error if securityId is invalid", async () => {
            updateExternalKycListsRequest = new request_1.UpdateExternalKycListsRequest({
                ...ExternalKycListsFixture_1.UpdateExternalKycListsRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.updateExternalKycLists(updateExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycListsAddresses array is invalid", async () => {
            updateExternalKycListsRequest = new request_1.UpdateExternalKycListsRequest({
                ...ExternalKycListsFixture_1.UpdateExternalKycListsRequestFixture.create({
                    externalKycListsAddresses: ["invalid"],
                }),
            });
            await expect(ExternalKycListsManagement_1.default.updateExternalKycLists(updateExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycListsAddresses and active array are different", async () => {
            updateExternalKycListsRequest = new request_1.UpdateExternalKycListsRequest({
                ...ExternalKycListsFixture_1.UpdateExternalKycListsRequestFixture.create({
                    actives: [true, false],
                }),
            });
            await expect(ExternalKycListsManagement_1.default.updateExternalKycLists(updateExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("addExternalKycList", () => {
        addExternalKycListsRequest = new request_1.AddExternalKycListRequest(ExternalKycListsFixture_1.AddExternalKycListsRequestFixture.create());
        it("should add external kyc list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalKycListsManagement_1.default.addExternalKycList(addExternalKycListsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("AddExternalKycListRequest", addExternalKycListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddExternalKycListCommand_1.AddExternalKycListCommand(addExternalKycListsRequest.securityId, addExternalKycListsRequest.externalKycListAddress));
            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(ExternalKycListsManagement_1.default.addExternalKycList(addExternalKycListsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("AddExternalKycListRequest", addExternalKycListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddExternalKycListCommand_1.AddExternalKycListCommand(addExternalKycListsRequest.securityId, addExternalKycListsRequest.externalKycListAddress));
        });
        it("should throw error if securityId is invalid", async () => {
            addExternalKycListsRequest = new request_1.AddExternalKycListRequest({
                ...ExternalKycListsFixture_1.AddExternalKycListsRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.addExternalKycList(addExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycListAddress is invalid", async () => {
            addExternalKycListsRequest = new request_1.AddExternalKycListRequest({
                ...ExternalKycListsFixture_1.AddExternalKycListsRequestFixture.create({
                    externalKycListAddress: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.addExternalKycList(addExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("removeExternalKycList", () => {
        removeExternalKycListsRequest = new request_1.RemoveExternalKycListRequest(ExternalKycListsFixture_1.RemoveExternalKycListsRequestFixture.create());
        it("should remove external kyc list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalKycListsManagement_1.default.removeExternalKycList(removeExternalKycListsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveExternalKycListRequest", removeExternalKycListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveExternalKycListCommand_1.RemoveExternalKycListCommand(removeExternalKycListsRequest.securityId, removeExternalKycListsRequest.externalKycListAddress));
            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(ExternalKycListsManagement_1.default.removeExternalKycList(removeExternalKycListsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveExternalKycListRequest", removeExternalKycListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveExternalKycListCommand_1.RemoveExternalKycListCommand(removeExternalKycListsRequest.securityId, removeExternalKycListsRequest.externalKycListAddress));
        });
        it("should throw error if securityId is invalid", async () => {
            removeExternalKycListsRequest = new request_1.RemoveExternalKycListRequest({
                ...ExternalKycListsFixture_1.RemoveExternalKycListsRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.removeExternalKycList(removeExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycListAddress is invalid", async () => {
            removeExternalKycListsRequest = new request_1.RemoveExternalKycListRequest({
                ...ExternalKycListsFixture_1.RemoveExternalKycListsRequestFixture.create({
                    externalKycListAddress: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.removeExternalKycList(removeExternalKycListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("isExternallyGranted", () => {
        isExternallyGrantedRequest = new request_1.IsExternallyGrantedRequest(ExternalKycListsFixture_1.IsExternallyGrantedRequestFixture.create());
        const expectedQueryResponse = {
            payload: true,
        };
        it("should check if address is externally granted successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalKycListsManagement_1.default.isExternallyGranted(isExternallyGrantedRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("IsExternallyGrantedRequest", isExternallyGrantedRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsExternallyGrantedQuery_1.IsExternallyGrantedQuery(isExternallyGrantedRequest.securityId, isExternallyGrantedRequest.kycStatus, isExternallyGrantedRequest.targetId));
            expect(result).toEqual(expectedQueryResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(ExternalKycListsManagement_1.default.isExternallyGranted(isExternallyGrantedRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("IsExternallyGrantedRequest", isExternallyGrantedRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsExternallyGrantedQuery_1.IsExternallyGrantedQuery(isExternallyGrantedRequest.securityId, isExternallyGrantedRequest.kycStatus, isExternallyGrantedRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            isExternallyGrantedRequest = new request_1.IsExternallyGrantedRequest({
                ...ExternalKycListsFixture_1.IsExternallyGrantedRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.isExternallyGranted(isExternallyGrantedRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            isExternallyGrantedRequest = new request_1.IsExternallyGrantedRequest({
                ...ExternalKycListsFixture_1.IsExternallyGrantedRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.isExternallyGranted(isExternallyGrantedRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if kycStatus is invalid", async () => {
            isExternallyGrantedRequest = new request_1.IsExternallyGrantedRequest({
                ...ExternalKycListsFixture_1.IsExternallyGrantedRequestFixture.create({
                    kycStatus: -1,
                }),
            });
            await expect(ExternalKycListsManagement_1.default.isExternallyGranted(isExternallyGrantedRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("isExternalKycList", () => {
        isExternalKycListRequest = new request_1.IsExternalKycListRequest(ExternalKycListsFixture_1.IsExternalKycListRequestFixture.create());
        const expectedQueryResponse = {
            payload: true,
        };
        it("should check if is external kyc list successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalKycListsManagement_1.default.isExternalKycList(isExternalKycListRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("IsExternalKycListRequest", isExternalKycListRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsExternalKycListQuery_1.IsExternalKycListQuery(isExternalKycListRequest.securityId, isExternalKycListRequest.externalKycListAddress));
            expect(result).toEqual(expectedQueryResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(ExternalKycListsManagement_1.default.isExternalKycList(isExternalKycListRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("IsExternalKycListRequest", isExternalKycListRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsExternalKycListQuery_1.IsExternalKycListQuery(isExternalKycListRequest.securityId, isExternalKycListRequest.externalKycListAddress));
        });
        it("should throw error if securityId is invalid", async () => {
            isExternalKycListRequest = new request_1.IsExternalKycListRequest({
                ...ExternalKycListsFixture_1.IsExternalKycListRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.isExternalKycList(isExternalKycListRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalKycListAddress is invalid", async () => {
            isExternalKycListRequest = new request_1.IsExternalKycListRequest({
                ...ExternalKycListsFixture_1.IsExternalKycListRequestFixture.create({
                    externalKycListAddress: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.isExternalKycList(isExternalKycListRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getExternalKycListsCount", () => {
        getExternalKycListsCountRequest = new request_1.GetExternalKycListsCountRequest(ExternalKycListsFixture_1.GetExternalKycListsCountRequestFixture.create());
        const expectedQueryResponse = {
            payload: 1,
        };
        it("should get external kyc lists count successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalKycListsManagement_1.default.getExternalKycListsCount(getExternalKycListsCountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalKycListsCountRequest", getExternalKycListsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalKycListsCountQuery_1.GetExternalKycListsCountQuery(getExternalKycListsCountRequest.securityId));
            expect(result).toEqual(expectedQueryResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(ExternalKycListsManagement_1.default.getExternalKycListsCount(getExternalKycListsCountRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalKycListsCountRequest", getExternalKycListsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalKycListsCountQuery_1.GetExternalKycListsCountQuery(getExternalKycListsCountRequest.securityId));
        });
        it("should throw error if securityId is invalid", async () => {
            getExternalKycListsCountRequest = new request_1.GetExternalKycListsCountRequest({
                ...ExternalKycListsFixture_1.GetExternalKycListsCountRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.getExternalKycListsCount(getExternalKycListsCountRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getExternalKycListsMembers", () => {
        getExternalKycListsMembersRequest = new request_1.GetExternalKycListsMembersRequest(ExternalKycListsFixture_1.GetExternalKycListsMembersRequestFixture.create());
        const expectedQueryResponse = {
            payload: [DataFixture_1.HederaIdPropsFixture.create().value],
        };
        it("should get external kyc lists members successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalKycListsManagement_1.default.getExternalKycListsMembers(getExternalKycListsMembersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalKycListsMembersRequest", getExternalKycListsMembersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalKycListsMembersQuery_1.GetExternalKycListsMembersQuery(getExternalKycListsMembersRequest.securityId, getExternalKycListsMembersRequest.start, getExternalKycListsMembersRequest.end));
            expect(result).toEqual(expectedQueryResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(ExternalKycListsManagement_1.default.getExternalKycListsMembers(getExternalKycListsMembersRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalKycListsMembersRequest", getExternalKycListsMembersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalKycListsMembersQuery_1.GetExternalKycListsMembersQuery(getExternalKycListsMembersRequest.securityId, getExternalKycListsMembersRequest.start, getExternalKycListsMembersRequest.end));
        });
        it("should throw error if securityId is invalid", async () => {
            getExternalKycListsMembersRequest = new request_1.GetExternalKycListsMembersRequest({
                ...ExternalKycListsFixture_1.GetExternalKycListsMembersRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.getExternalKycListsMembers(getExternalKycListsMembersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if start is negative", async () => {
            getExternalKycListsMembersRequest = new request_1.GetExternalKycListsMembersRequest({
                ...ExternalKycListsFixture_1.GetExternalKycListsMembersRequestFixture.create({
                    start: -1,
                }),
            });
            await expect(ExternalKycListsManagement_1.default.getExternalKycListsMembers(getExternalKycListsMembersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if end is negative", async () => {
            getExternalKycListsMembersRequest = new request_1.GetExternalKycListsMembersRequest({
                ...ExternalKycListsFixture_1.GetExternalKycListsMembersRequestFixture.create({
                    end: -1,
                }),
            });
            await expect(ExternalKycListsManagement_1.default.getExternalKycListsMembers(getExternalKycListsMembersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("grantKycMockRequest", () => {
        grantKycMockRequest = new request_1.GrantKycMockRequest(ExternalKycListsFixture_1.GrantKycMockRequestFixture.create());
        it("should grant kyc mock successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalKycListsManagement_1.default.grantKycMock(grantKycMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GrantKycMockRequest", grantKycMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new GrantKycMockCommand_1.GrantKycMockCommand(grantKycMockRequest.contractId, grantKycMockRequest.targetId));
            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(ExternalKycListsManagement_1.default.grantKycMock(grantKycMockRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GrantKycMockRequest", grantKycMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new GrantKycMockCommand_1.GrantKycMockCommand(grantKycMockRequest.contractId, grantKycMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            grantKycMockRequest = new request_1.GrantKycMockRequest({
                ...ExternalKycListsFixture_1.GrantKycMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.grantKycMock(grantKycMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            grantKycMockRequest = new request_1.GrantKycMockRequest({
                ...ExternalKycListsFixture_1.GrantKycMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.grantKycMock(grantKycMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("revokeKycMock", () => {
        revokeKycMockRequest = new request_1.RevokeKycMockRequest(ExternalKycListsFixture_1.RevokeKycMockRequestFixture.create());
        it("should revoke kyc mock successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalKycListsManagement_1.default.revokeKycMock(revokeKycMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("RevokeKycMockRequest", revokeKycMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RevokeKycMockCommand_1.RevokeKycMockCommand(revokeKycMockRequest.contractId, revokeKycMockRequest.targetId));
            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(ExternalKycListsManagement_1.default.revokeKycMock(revokeKycMockRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("RevokeKycMockRequest", revokeKycMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RevokeKycMockCommand_1.RevokeKycMockCommand(revokeKycMockRequest.contractId, revokeKycMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            revokeKycMockRequest = new request_1.RevokeKycMockRequest({
                ...ExternalKycListsFixture_1.RevokeKycMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.revokeKycMock(revokeKycMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            grantKycMockRequest = new request_1.GrantKycMockRequest({
                ...ExternalKycListsFixture_1.GrantKycMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.grantKycMock(grantKycMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getKycStatusMock", () => {
        getKycStatusMockRequest = new request_1.GetKycStatusMockRequest(ExternalKycListsFixture_1.GetKycStatusMockRequestFixture.create());
        const expectedQueryResponse = {
            payload: true,
        };
        it("should get kyc status mock successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalKycListsManagement_1.default.getKycStatusMock(getKycStatusMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetKycStatusMockRequest", getKycStatusMockRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetKycStatusMockQuery_1.GetKycStatusMockQuery(getKycStatusMockRequest.contractId, getKycStatusMockRequest.targetId));
            expect(result).toEqual(expectedQueryResponse.payload);
        });
        it("should throw an error if query execution fails", async () => {
            const error = new Error("Query execution failed");
            queryBusMock.execute.mockRejectedValue(error);
            await expect(ExternalKycListsManagement_1.default.getKycStatusMock(getKycStatusMockRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetKycStatusMockRequest", getKycStatusMockRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetKycStatusMockQuery_1.GetKycStatusMockQuery(getKycStatusMockRequest.contractId, getKycStatusMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            getKycStatusMockRequest = new request_1.GetKycStatusMockRequest({
                ...ExternalKycListsFixture_1.GetKycStatusMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.getKycStatusMock(getKycStatusMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            getKycStatusMockRequest = new request_1.GetKycStatusMockRequest({
                ...ExternalKycListsFixture_1.GetKycStatusMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalKycListsManagement_1.default.getKycStatusMock(getKycStatusMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("createExternalKycMock", () => {
        const expectedCommandResponse = {
            payload: hederaId,
        };
        it("should create external kyc list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedCommandResponse);
            const result = await ExternalKycListsManagement_1.default.createExternalKycMock();
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateExternalKycMockCommand_1.CreateExternalKycListMockCommand());
            expect(result).toEqual(expectedCommandResponse.payload);
        });
        it("should throw an error if command execution fails", async () => {
            const error = new Error("Command execution failed");
            commandBusMock.execute.mockRejectedValue(error);
            await expect(ExternalKycListsManagement_1.default.createExternalKycMock()).rejects.toThrow("Command execution failed");
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateExternalKycMockCommand_1.CreateExternalKycListMockCommand());
        });
    });
});
