"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 ExternalControlListsManagement_1 = __importDefault(require("./ExternalControlListsManagement"));
const request_1 = require("../request");
const UpdateExternalControlListsCommand_1 = require("../../../app/usecase/command/security/externalControlLists/updateExternalControlLists/UpdateExternalControlListsCommand");
const ExternalControlListsFixture_1 = require("../../../../__tests__/fixtures/externalControlLists/ExternalControlListsFixture");
const DataFixture_1 = require("../../../../__tests__/fixtures/shared/DataFixture");
const LogService_1 = __importDefault(require("../../../app/service/log/LogService"));
const AddExternalControlListCommand_1 = require("../../../app/usecase/command/security/externalControlLists/addExternalControlList/AddExternalControlListCommand");
const RemoveExternalControlListCommand_1 = require("../../../app/usecase/command/security/externalControlLists/removeExternalControlList/RemoveExternalControlListCommand");
const IsExternalControlListQuery_1 = require("../../../app/usecase/query/security/externalControlLists/isExternalControlList/IsExternalControlListQuery");
const GetExternalControlListsCountQuery_1 = require("../../../app/usecase/query/security/externalControlLists/getExternalControlListsCount/GetExternalControlListsCountQuery");
const GetExternalControlListsMembersQuery_1 = require("../../../app/usecase/query/security/externalControlLists/getExternalControlListsMembers/GetExternalControlListsMembersQuery");
const AddToBlackListMockCommand_1 = require("../../../app/usecase/command/security/externalControlLists/mock/addToBlackListMock/AddToBlackListMockCommand");
const AddToWhiteListMockCommand_1 = require("../../../app/usecase/command/security/externalControlLists/mock/addToWhiteListMock/AddToWhiteListMockCommand");
const RemoveFromBlackListMockCommand_1 = require("../../../app/usecase/command/security/externalControlLists/mock/removeFromBlackListMock/RemoveFromBlackListMockCommand");
const RemoveFromWhiteListMockCommand_1 = require("../../../app/usecase/command/security/externalControlLists/mock/removeFromWhiteListMock/RemoveFromWhiteListMockCommand");
const CreateExternalBlackListMockCommand_1 = require("../../../app/usecase/command/security/externalControlLists/mock/createExternalBlackListMock/CreateExternalBlackListMockCommand");
const CreateExternalWhiteListMockCommand_1 = require("../../../app/usecase/command/security/externalControlLists/mock/createExternalWhiteListMock/CreateExternalWhiteListMockCommand");
const IsAuthorizedBlackListMockQuery_1 = require("../../../app/usecase/query/security/externalControlLists/mock/isAuthorizedBlackListMock/IsAuthorizedBlackListMockQuery");
const IsAuthorizedWhiteListMockQuery_1 = require("../../../app/usecase/query/security/externalControlLists/mock/isAuthorizedWhiteListMock/IsAuthorizedWhiteListMockQuery");
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
const ValidationError_1 = require("../../../core/validation/ValidationError");
describe("ExternalControlListsManagement", () => {
    let commandBusMock;
    let queryBusMock;
    let updateExternalControlListsRequest;
    let addExternalControlListsRequest;
    let removeExternalControlListsRequest;
    let isExternalControlListRequest;
    let getExternalControlListsCountRequest;
    let getExternalControlListsMembersRequest;
    let addToBlackListMockRequest;
    let addToWhiteListMockRequest;
    let removeFromBlackListMockRequest;
    let removeFromWhiteListMockRequest;
    let isAuthorizedBlackListMockRequest;
    let isAuthorizedWhiteListMockRequest;
    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(() => { });
        ExternalControlListsManagement_1.default.commandBus = commandBusMock;
        ExternalControlListsManagement_1.default.queryBus = queryBusMock;
    });
    afterEach(() => {
        jest.resetAllMocks();
        jest.restoreAllMocks();
    });
    describe("updateExternalControlListsPauses", () => {
        updateExternalControlListsRequest = new request_1.UpdateExternalControlListsRequest(ExternalControlListsFixture_1.UpdateExternalControlListsRequestFixture.create());
        it("should update external control lists successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.updateExternalControlLists(updateExternalControlListsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("UpdateExternalControlListsRequest", updateExternalControlListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateExternalControlListsCommand_1.UpdateExternalControlListsCommand(updateExternalControlListsRequest.securityId, updateExternalControlListsRequest.externalControlListsAddresses, updateExternalControlListsRequest.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(ExternalControlListsManagement_1.default.updateExternalControlLists(updateExternalControlListsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("UpdateExternalControlListsRequest", updateExternalControlListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new UpdateExternalControlListsCommand_1.UpdateExternalControlListsCommand(updateExternalControlListsRequest.securityId, updateExternalControlListsRequest.externalControlListsAddresses, updateExternalControlListsRequest.actives));
        });
        it("should throw error if securityId is invalid", async () => {
            updateExternalControlListsRequest = new request_1.UpdateExternalControlListsRequest({
                ...ExternalControlListsFixture_1.UpdateExternalControlListsRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.updateExternalControlLists(updateExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlListsAddresses array is invalid", async () => {
            updateExternalControlListsRequest = new request_1.UpdateExternalControlListsRequest({
                ...ExternalControlListsFixture_1.UpdateExternalControlListsRequestFixture.create({
                    externalControlListsAddresses: ["invalid"],
                }),
            });
            await expect(ExternalControlListsManagement_1.default.updateExternalControlLists(updateExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlListsAddresses and active array are different", async () => {
            updateExternalControlListsRequest = new request_1.UpdateExternalControlListsRequest({
                ...ExternalControlListsFixture_1.UpdateExternalControlListsRequestFixture.create({
                    actives: [true, false],
                }),
            });
            await expect(ExternalControlListsManagement_1.default.updateExternalControlLists(updateExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("addExternalControlList", () => {
        addExternalControlListsRequest = new request_1.AddExternalControlListRequest(ExternalControlListsFixture_1.AddExternalControlListsRequestFixture.create());
        it("should add external control list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.addExternalControlList(addExternalControlListsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("AddExternalControlListRequest", addExternalControlListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddExternalControlListCommand_1.AddExternalControlListCommand(addExternalControlListsRequest.securityId, addExternalControlListsRequest.externalControlListAddress));
            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(ExternalControlListsManagement_1.default.addExternalControlList(addExternalControlListsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("AddExternalControlListRequest", addExternalControlListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddExternalControlListCommand_1.AddExternalControlListCommand(addExternalControlListsRequest.securityId, addExternalControlListsRequest.externalControlListAddress));
        });
        it("should throw error if securityId is invalid", async () => {
            addExternalControlListsRequest = new request_1.AddExternalControlListRequest({
                ...ExternalControlListsFixture_1.AddExternalControlListsRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.addExternalControlList(addExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlListAddress is invalid", async () => {
            addExternalControlListsRequest = new request_1.AddExternalControlListRequest({
                ...ExternalControlListsFixture_1.AddExternalControlListsRequestFixture.create({
                    externalControlListAddress: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.addExternalControlList(addExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("removeExternalControlList", () => {
        removeExternalControlListsRequest = new request_1.RemoveExternalControlListRequest(ExternalControlListsFixture_1.RemoveExternalControlListsRequestFixture.create());
        it("should remove external control list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.removeExternalControlList(removeExternalControlListsRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveExternalControlListRequest", removeExternalControlListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveExternalControlListCommand_1.RemoveExternalControlListCommand(removeExternalControlListsRequest.securityId, removeExternalControlListsRequest.externalControlListAddress));
            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(ExternalControlListsManagement_1.default.removeExternalControlList(removeExternalControlListsRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveExternalControlListRequest", removeExternalControlListsRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveExternalControlListCommand_1.RemoveExternalControlListCommand(removeExternalControlListsRequest.securityId, removeExternalControlListsRequest.externalControlListAddress));
        });
        it("should throw error if securityId is invalid", async () => {
            removeExternalControlListsRequest = new request_1.RemoveExternalControlListRequest({
                ...ExternalControlListsFixture_1.RemoveExternalControlListsRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.removeExternalControlList(removeExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlListAddress is invalid", async () => {
            removeExternalControlListsRequest = new request_1.RemoveExternalControlListRequest({
                ...ExternalControlListsFixture_1.RemoveExternalControlListsRequestFixture.create({
                    externalControlListAddress: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.removeExternalControlList(removeExternalControlListsRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("isExternalControlList", () => {
        isExternalControlListRequest = new request_1.IsExternalControlListRequest(ExternalControlListsFixture_1.IsExternalControlListRequestFixture.create());
        const expectedQueryResponse = {
            payload: true,
        };
        it("should check if is external control list successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalControlListsManagement_1.default.isExternalControlList(isExternalControlListRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("IsExternalControlListRequest", isExternalControlListRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsExternalControlListQuery_1.IsExternalControlListQuery(isExternalControlListRequest.securityId, isExternalControlListRequest.externalControlListAddress));
            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(ExternalControlListsManagement_1.default.isExternalControlList(isExternalControlListRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("IsExternalControlListRequest", isExternalControlListRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsExternalControlListQuery_1.IsExternalControlListQuery(isExternalControlListRequest.securityId, isExternalControlListRequest.externalControlListAddress));
        });
        it("should throw error if securityId is invalid", async () => {
            isExternalControlListRequest = new request_1.IsExternalControlListRequest({
                ...ExternalControlListsFixture_1.IsExternalControlListRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.isExternalControlList(isExternalControlListRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if externalControlListAddress is invalid", async () => {
            isExternalControlListRequest = new request_1.IsExternalControlListRequest({
                ...ExternalControlListsFixture_1.IsExternalControlListRequestFixture.create({
                    externalControlListAddress: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.isExternalControlList(isExternalControlListRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getExternalControlListsCount", () => {
        getExternalControlListsCountRequest = new request_1.GetExternalControlListsCountRequest(ExternalControlListsFixture_1.GetExternalControlListsCountRequestFixture.create());
        const expectedQueryResponse = {
            payload: 1,
        };
        it("should get external control lists count successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalControlListsManagement_1.default.getExternalControlListsCount(getExternalControlListsCountRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalControlListsCountRequest", getExternalControlListsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalControlListsCountQuery_1.GetExternalControlListsCountQuery(getExternalControlListsCountRequest.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(ExternalControlListsManagement_1.default.getExternalControlListsCount(getExternalControlListsCountRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalControlListsCountRequest", getExternalControlListsCountRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalControlListsCountQuery_1.GetExternalControlListsCountQuery(getExternalControlListsCountRequest.securityId));
        });
        it("should throw error if securityId is invalid", async () => {
            getExternalControlListsCountRequest = new request_1.GetExternalControlListsCountRequest({
                ...ExternalControlListsFixture_1.GetExternalControlListsCountRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.getExternalControlListsCount(getExternalControlListsCountRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("getExternalControlListsMembers", () => {
        getExternalControlListsMembersRequest = new request_1.GetExternalControlListsMembersRequest(ExternalControlListsFixture_1.GetExternalControlListsMembersRequestFixture.create());
        const expectedQueryResponse = {
            payload: [DataFixture_1.HederaIdPropsFixture.create().value],
        };
        it("should get external control lists members successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalControlListsManagement_1.default.getExternalControlListsMembers(getExternalControlListsMembersRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalControlListsMembersRequest", getExternalControlListsMembersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalControlListsMembersQuery_1.GetExternalControlListsMembersQuery(getExternalControlListsMembersRequest.securityId, getExternalControlListsMembersRequest.start, getExternalControlListsMembersRequest.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(ExternalControlListsManagement_1.default.getExternalControlListsMembers(getExternalControlListsMembersRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("GetExternalControlListsMembersRequest", getExternalControlListsMembersRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new GetExternalControlListsMembersQuery_1.GetExternalControlListsMembersQuery(getExternalControlListsMembersRequest.securityId, getExternalControlListsMembersRequest.start, getExternalControlListsMembersRequest.end));
        });
        it("should throw error if securityId is invalid", async () => {
            getExternalControlListsMembersRequest = new request_1.GetExternalControlListsMembersRequest({
                ...ExternalControlListsFixture_1.GetExternalControlListsMembersRequestFixture.create({
                    securityId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.getExternalControlListsMembers(getExternalControlListsMembersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if start is negative", async () => {
            getExternalControlListsMembersRequest = new request_1.GetExternalControlListsMembersRequest({
                ...ExternalControlListsFixture_1.GetExternalControlListsMembersRequestFixture.create({
                    start: -1,
                }),
            });
            await expect(ExternalControlListsManagement_1.default.getExternalControlListsMembers(getExternalControlListsMembersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if end is negative", async () => {
            getExternalControlListsMembersRequest = new request_1.GetExternalControlListsMembersRequest({
                ...ExternalControlListsFixture_1.GetExternalControlListsMembersRequestFixture.create({
                    end: -1,
                }),
            });
            await expect(ExternalControlListsManagement_1.default.getExternalControlListsMembers(getExternalControlListsMembersRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("addToBlackListMock", () => {
        addToBlackListMockRequest = new request_1.AddToBlackListMockRequest(ExternalControlListsFixture_1.AddToBlackListMockRequestFixture.create());
        it("should add to external control black list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.addToBlackListMock(addToBlackListMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("AddToBlackListMockRequest", addToBlackListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddToBlackListMockCommand_1.AddToBlackListMockCommand(addToBlackListMockRequest.contractId, addToBlackListMockRequest.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(ExternalControlListsManagement_1.default.addToBlackListMock(addToBlackListMockRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("AddToBlackListMockRequest", addToBlackListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddToBlackListMockCommand_1.AddToBlackListMockCommand(addToBlackListMockRequest.contractId, addToBlackListMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            addToBlackListMockRequest = new request_1.AddToBlackListMockRequest({
                ...ExternalControlListsFixture_1.AddToBlackListMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.addToBlackListMock(addToBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            addToBlackListMockRequest = new request_1.AddToBlackListMockRequest({
                ...ExternalControlListsFixture_1.AddToBlackListMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.addToBlackListMock(addToBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("addToWhiteListMock", () => {
        addToWhiteListMockRequest = new request_1.AddToWhiteListMockRequest(ExternalControlListsFixture_1.AddToWhiteListMockRequestFixture.create());
        it("should add to external control white list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.addToWhiteListMock(addToWhiteListMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("AddToWhiteListMockRequest", addToWhiteListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddToWhiteListMockCommand_1.AddToWhiteListMockCommand(addToWhiteListMockRequest.contractId, addToWhiteListMockRequest.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(ExternalControlListsManagement_1.default.addToWhiteListMock(addToWhiteListMockRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("AddToWhiteListMockRequest", addToWhiteListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new AddToBlackListMockCommand_1.AddToBlackListMockCommand(addToWhiteListMockRequest.contractId, addToWhiteListMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            addToWhiteListMockRequest = new request_1.AddToWhiteListMockRequest({
                ...ExternalControlListsFixture_1.AddToWhiteListMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.addToWhiteListMock(addToBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            addToWhiteListMockRequest = new request_1.AddToWhiteListMockRequest({
                ...ExternalControlListsFixture_1.AddToWhiteListMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.addToWhiteListMock(addToBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("removeFromBlackListMock", () => {
        removeFromBlackListMockRequest = new request_1.RemoveFromBlackListMockRequest(ExternalControlListsFixture_1.RemoveFromBlackListMockRequestFixture.create());
        it("should remove from external control black list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.removeFromBlackListMock(removeFromBlackListMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveFromBlackListMockRequest", removeFromBlackListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveFromBlackListMockCommand_1.RemoveFromBlackListMockCommand(removeFromBlackListMockRequest.contractId, removeFromBlackListMockRequest.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(ExternalControlListsManagement_1.default.removeFromBlackListMock(removeFromBlackListMockRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveFromBlackListMockRequest", removeFromBlackListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveFromBlackListMockCommand_1.RemoveFromBlackListMockCommand(removeFromBlackListMockRequest.contractId, removeFromBlackListMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            removeFromBlackListMockRequest = new request_1.RemoveFromBlackListMockRequest({
                ...ExternalControlListsFixture_1.RemoveFromBlackListMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.removeFromBlackListMock(removeFromBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            removeFromBlackListMockRequest = new request_1.RemoveFromBlackListMockRequest({
                ...ExternalControlListsFixture_1.RemoveFromBlackListMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.removeFromBlackListMock(removeFromBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("removeFromWhiteListMock", () => {
        removeFromWhiteListMockRequest = new request_1.RemoveFromWhiteListMockRequest(ExternalControlListsFixture_1.RemoveFromWhiteListMockRequestFixture.create());
        it("should remove from external control white list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedResponse);
            const result = await ExternalControlListsManagement_1.default.removeFromWhiteListMock(removeFromWhiteListMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveFromWhiteListMockRequest", removeFromWhiteListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveFromWhiteListMockCommand_1.RemoveFromWhiteListMockCommand(removeFromWhiteListMockRequest.contractId, removeFromWhiteListMockRequest.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(ExternalControlListsManagement_1.default.removeFromWhiteListMock(removeFromWhiteListMockRequest)).rejects.toThrow("Command execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("RemoveFromWhiteListMockRequest", removeFromWhiteListMockRequest);
            expect(commandBusMock.execute).toHaveBeenCalledWith(new RemoveFromWhiteListMockCommand_1.RemoveFromWhiteListMockCommand(removeFromWhiteListMockRequest.contractId, removeFromWhiteListMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            removeFromWhiteListMockRequest = new request_1.RemoveFromWhiteListMockRequest({
                ...ExternalControlListsFixture_1.RemoveFromWhiteListMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.removeFromWhiteListMock(removeFromWhiteListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            removeFromWhiteListMockRequest = new request_1.RemoveFromBlackListMockRequest({
                ...ExternalControlListsFixture_1.RemoveFromWhiteListMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.removeFromWhiteListMock(removeFromWhiteListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("createExternalBlackListMock", () => {
        const expectedCommandResponse = {
            payload: hederaId,
        };
        it("should create external control black list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedCommandResponse);
            const result = await ExternalControlListsManagement_1.default.createExternalBlackListMock();
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateExternalBlackListMockCommand_1.CreateExternalBlackListMockCommand());
            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(ExternalControlListsManagement_1.default.createExternalBlackListMock()).rejects.toThrow("Command execution failed");
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateExternalBlackListMockCommand_1.CreateExternalBlackListMockCommand());
        });
    });
    describe("createExternalWhiteListMock", () => {
        const expectedCommandResponse = {
            payload: hederaId,
        };
        it("should create external control white list successfully", async () => {
            commandBusMock.execute.mockResolvedValue(expectedCommandResponse);
            const result = await ExternalControlListsManagement_1.default.createExternalWhiteListMock();
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateExternalWhiteListMockCommand_1.CreateExternalWhiteListMockCommand());
            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(ExternalControlListsManagement_1.default.createExternalWhiteListMock()).rejects.toThrow("Command execution failed");
            expect(commandBusMock.execute).toHaveBeenCalledWith(new CreateExternalWhiteListMockCommand_1.CreateExternalWhiteListMockCommand());
        });
    });
    describe("isAuthorizedBlackListMock", () => {
        isAuthorizedBlackListMockRequest = new request_1.IsAuthorizedBlackListMockRequest(ExternalControlListsFixture_1.IsAuthorizedBlackListMockRequestFixture.create());
        const expectedQueryResponse = {
            payload: true,
        };
        it("should check if address is in external control black list successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalControlListsManagement_1.default.isAuthorizedBlackListMock(isAuthorizedBlackListMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("IsAuthorizedBlackListMockRequest", isAuthorizedBlackListMockRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsAuthorizedBlackListMockQuery_1.IsAuthorizedBlackListMockQuery(isAuthorizedBlackListMockRequest.contractId, isAuthorizedBlackListMockRequest.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(ExternalControlListsManagement_1.default.isAuthorizedBlackListMock(isAuthorizedBlackListMockRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("IsAuthorizedBlackListMockRequest", isAuthorizedBlackListMockRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsAuthorizedBlackListMockQuery_1.IsAuthorizedBlackListMockQuery(isAuthorizedBlackListMockRequest.contractId, isAuthorizedBlackListMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            isAuthorizedBlackListMockRequest = new request_1.IsAuthorizedBlackListMockRequest({
                ...ExternalControlListsFixture_1.IsAuthorizedBlackListMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.isAuthorizedBlackListMock(isAuthorizedBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            isAuthorizedBlackListMockRequest = new request_1.IsAuthorizedBlackListMockRequest({
                ...ExternalControlListsFixture_1.IsAuthorizedBlackListMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.isAuthorizedBlackListMock(isAuthorizedBlackListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
    describe("isAuthorizedWhiteListMock", () => {
        isAuthorizedWhiteListMockRequest = new request_1.IsAuthorizedWhiteListMockRequest(ExternalControlListsFixture_1.IsAuthorizedWhiteListMockRequestFixture.create());
        const expectedQueryResponse = {
            payload: true,
        };
        it("should check if address is in external control white list successfully", async () => {
            queryBusMock.execute.mockResolvedValue(expectedQueryResponse);
            const result = await ExternalControlListsManagement_1.default.isAuthorizedWhiteListMock(isAuthorizedWhiteListMockRequest);
            expect(handleValidationSpy).toHaveBeenCalledWith("IsAuthorizedWhiteListMockRequest", isAuthorizedWhiteListMockRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsAuthorizedWhiteListMockQuery_1.IsAuthorizedWhiteListMockQuery(isAuthorizedWhiteListMockRequest.contractId, isAuthorizedWhiteListMockRequest.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(ExternalControlListsManagement_1.default.isAuthorizedWhiteListMock(isAuthorizedWhiteListMockRequest)).rejects.toThrow("Query execution failed");
            expect(handleValidationSpy).toHaveBeenCalledWith("IsAuthorizedWhiteListMockRequest", isAuthorizedWhiteListMockRequest);
            expect(queryBusMock.execute).toHaveBeenCalledWith(new IsAuthorizedWhiteListMockQuery_1.IsAuthorizedWhiteListMockQuery(isAuthorizedWhiteListMockRequest.contractId, isAuthorizedWhiteListMockRequest.targetId));
        });
        it("should throw error if securityId is invalid", async () => {
            isAuthorizedWhiteListMockRequest = new request_1.IsAuthorizedWhiteListMockRequest({
                ...ExternalControlListsFixture_1.IsAuthorizedWhiteListMockRequestFixture.create({
                    contractId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.isAuthorizedWhiteListMock(isAuthorizedWhiteListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
        it("should throw error if targetId is invalid", async () => {
            isAuthorizedWhiteListMockRequest = new request_1.IsAuthorizedWhiteListMockRequest({
                ...ExternalControlListsFixture_1.IsAuthorizedWhiteListMockRequestFixture.create({
                    targetId: "invalid",
                }),
            });
            await expect(ExternalControlListsManagement_1.default.isAuthorizedWhiteListMock(isAuthorizedWhiteListMockRequest)).rejects.toThrow(ValidationError_1.ValidationError);
        });
    });
});
