"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 DataFixture_1 = require("../../../../../../../../__tests__/fixtures/shared/DataFixture");
const EvmAddress_1 = __importDefault(require("../../../../../../../domain/context/contract/EvmAddress"));
const ExternalControlListsFixture_1 = require("../../../../../../../../__tests__/fixtures/externalControlLists/ExternalControlListsFixture");
const IsAuthorizedBlackListMockQueryHandler_1 = require("./IsAuthorizedBlackListMockQueryHandler");
const IsAuthorizedBlackListMockQuery_1 = require("./IsAuthorizedBlackListMockQuery");
describe("IsAuthorizedBlackListMockQueryHandler", () => {
    let handler;
    let query;
    const rpcQueryAdapterMock = (0, ts_jest_1.createMock)();
    const contractServiceMock = (0, ts_jest_1.createMock)();
    const accountServiceMock = (0, ts_jest_1.createMock)();
    const contractEvmAddress = new EvmAddress_1.default(DataFixture_1.EvmAddressPropsFixture.create().value);
    const targetEvmAddress = new EvmAddress_1.default(DataFixture_1.EvmAddressPropsFixture.create().value);
    beforeEach(() => {
        handler = new IsAuthorizedBlackListMockQueryHandler_1.IsAuthorizedBlackListMockQueryHandler(contractServiceMock, rpcQueryAdapterMock, accountServiceMock);
        query = ExternalControlListsFixture_1.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(IsAuthorizedBlackListMockQuery_1.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);
        });
    });
});
