// 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 { Security } from "../../../../../../domain/context/security/Security";
import { SecurityPropsFixture } from "../../../../../../../__tests__/fixtures/shared/SecurityFixture";
import { IsExternalKycListQueryHandler } from "./IsExternalKycListQueryHandler";
import { IsExternalKycListQueryResponse } from "./IsExternalKycListQuery";
import { IsExternalKycListQueryFixture } from "../../../../../../../__tests__/fixtures/externalKycLists/ExternalKycListsFixture";
describe("IsExternalKycListQueryHandler", () => {
    let handler;
    let query;
    const securityServiceMock = createMock();
    const queryAdapterServiceMock = createMock();
    const contractServiceMock = createMock();
    const evmAddress = new EvmAddress(EvmAddressPropsFixture.create().value);
    const externalKycListEvmAddress = new EvmAddress(EvmAddressPropsFixture.create().value);
    const security = new Security(SecurityPropsFixture.create());
    beforeEach(() => {
        handler = new IsExternalKycListQueryHandler(securityServiceMock, contractServiceMock, queryAdapterServiceMock);
        query = IsExternalKycListQueryFixture.create();
    });
    afterEach(() => {
        jest.resetAllMocks();
    });
    describe("execute", () => {
        it("should successfully validate if is external kyc list", async () => {
            securityServiceMock.get.mockResolvedValueOnce(security);
            contractServiceMock.getContractEvmAddress
                .mockResolvedValueOnce(evmAddress)
                .mockResolvedValueOnce(externalKycListEvmAddress);
            queryAdapterServiceMock.isExternalKycList.mockResolvedValue(true);
            const result = await handler.execute(query);
            expect(result).toBeInstanceOf(IsExternalKycListQueryResponse);
            expect(result.payload).toBe(true);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenCalledTimes(2);
            expect(securityServiceMock.get).toHaveBeenCalledTimes(1);
            expect(queryAdapterServiceMock.isExternalKycList).toHaveBeenCalledTimes(1);
            expect(securityServiceMock.get).toHaveBeenCalledWith(query.securityId);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenNthCalledWith(1, query.securityId);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenNthCalledWith(2, query.externalKycListAddress);
            expect(queryAdapterServiceMock.isExternalKycList).toHaveBeenCalledWith(evmAddress, externalKycListEvmAddress);
        });
    });
});
