// SPDX-License-Identifier: Apache-2.0
import { createMock } from "@golevelup/ts-jest";
import { EvmAddressPropsFixture } from "../../../../../../../../__tests__/fixtures/shared/DataFixture";
import EvmAddress from "../../../../../../../domain/context/contract/EvmAddress";
import { IsAuthorizedBlackListMockQueryFixture } from "../../../../../../../../__tests__/fixtures/externalControlLists/ExternalControlListsFixture";
import { IsAuthorizedBlackListMockQueryHandler } from "./IsAuthorizedBlackListMockQueryHandler";
import { IsAuthorizedBlackListMockQueryResponse, } from "./IsAuthorizedBlackListMockQuery";
describe("IsAuthorizedBlackListMockQueryHandler", () => {
    let handler;
    let query;
    const rpcQueryAdapterMock = createMock();
    const contractServiceMock = createMock();
    const accountServiceMock = createMock();
    const contractEvmAddress = new EvmAddress(EvmAddressPropsFixture.create().value);
    const targetEvmAddress = new EvmAddress(EvmAddressPropsFixture.create().value);
    beforeEach(() => {
        handler = new IsAuthorizedBlackListMockQueryHandler(contractServiceMock, rpcQueryAdapterMock, accountServiceMock);
        query = IsAuthorizedBlackListMockQueryFixture.create();
    });
    afterEach(() => {
        jest.resetAllMocks();
    });
    describe("execute", () => {
        it("should successfully verify if is authorized", async () => {
            contractServiceMock.getContractEvmAddress.mockResolvedValueOnce(contractEvmAddress);
            accountServiceMock.getAccountEvmAddress.mockResolvedValueOnce(targetEvmAddress);
            rpcQueryAdapterMock.isAuthorizedBlackListMock.mockResolvedValue(true);
            const result = await handler.execute(query);
            expect(result).toBeInstanceOf(IsAuthorizedBlackListMockQueryResponse);
            expect(result.payload).toBe(true);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenCalledTimes(1);
            expect(rpcQueryAdapterMock.isAuthorizedBlackListMock).toHaveBeenCalledTimes(1);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenCalledWith(query.contractId);
            expect(accountServiceMock.getAccountEvmAddress).toHaveBeenCalledWith(query.targetId);
            expect(rpcQueryAdapterMock.isAuthorizedBlackListMock).toHaveBeenCalledWith(contractEvmAddress, targetEvmAddress);
        });
    });
});
