// 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 { GetExternalKycListsCountQueryResponse } from "./GetExternalKycListsCountQuery";
import { GetExternalKycListsCountQueryHandler } from "./GetExternalKycListsCountQueryHandler";
import { Security } from "../../../../../../domain/context/security/Security";
import { SecurityPropsFixture } from "../../../../../../../__tests__/fixtures/shared/SecurityFixture";
import { GetExternalKycListsCountQueryFixture } from "../../../../../../../__tests__/fixtures/externalKycLists/ExternalKycListsFixture";
describe("GetExternalKycListsCountQueryHandler", () => {
    let handler;
    let query;
    const securityServiceMock = createMock();
    const queryAdapterServiceMock = createMock();
    const contractServiceMock = createMock();
    const evmAddress = new EvmAddress(EvmAddressPropsFixture.create().value);
    const security = new Security(SecurityPropsFixture.create());
    beforeEach(() => {
        handler = new GetExternalKycListsCountQueryHandler(securityServiceMock, contractServiceMock, queryAdapterServiceMock);
        query = GetExternalKycListsCountQueryFixture.create();
    });
    afterEach(() => {
        jest.resetAllMocks();
    });
    describe("execute", () => {
        it("should successfully get external kyc lists count", async () => {
            securityServiceMock.get.mockResolvedValueOnce(security);
            contractServiceMock.getContractEvmAddress.mockResolvedValueOnce(evmAddress);
            queryAdapterServiceMock.getExternalKycListsCount.mockResolvedValue(1);
            const result = await handler.execute(query);
            expect(result).toBeInstanceOf(GetExternalKycListsCountQueryResponse);
            expect(result.payload).toBe(1);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenCalledTimes(1);
            expect(securityServiceMock.get).toHaveBeenCalledTimes(1);
            expect(queryAdapterServiceMock.getExternalKycListsCount).toHaveBeenCalledTimes(1);
            expect(securityServiceMock.get).toHaveBeenCalledWith(query.securityId);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenCalledWith(query.securityId);
            expect(queryAdapterServiceMock.getExternalKycListsCount).toHaveBeenCalledWith(evmAddress);
        });
    });
});
