"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 Account_1 = __importDefault(require("../../../../../../domain/context/account/Account"));
const SecurityRole_1 = require("../../../../../../domain/context/security/SecurityRole");
const UpdateExternalPausesCommandHandler_js_1 = require("./UpdateExternalPausesCommandHandler.js");
const UpdateExternalPausesCommand_js_1 = require("./UpdateExternalPausesCommand.js");
const ExternalPausesFixture_1 = require("../../../../../../../__tests__/fixtures/externalPauses/ExternalPausesFixture");
describe("UpdateExternalPausesCommandHandler", () => {
    let handler;
    let command;
    const transactionServiceMock = (0, ts_jest_1.createMock)();
    const validationServiceMock = (0, ts_jest_1.createMock)();
    const accountServiceMock = (0, ts_jest_1.createMock)();
    const contractServiceMock = (0, ts_jest_1.createMock)();
    const evmAddress = new EvmAddress_1.default(DataFixture_1.EvmAddressPropsFixture.create().value);
    const externalEvmAddress = new EvmAddress_1.default(DataFixture_1.EvmAddressPropsFixture.create().value);
    const account = new Account_1.default({
        id: DataFixture_1.HederaIdPropsFixture.create().value,
        evmAddress: DataFixture_1.EvmAddressPropsFixture.create().value,
    });
    const transactionId = DataFixture_1.TransactionIdFixture.create().id;
    beforeEach(() => {
        handler = new UpdateExternalPausesCommandHandler_js_1.UpdateExternalPausesCommandHandler(accountServiceMock, contractServiceMock, transactionServiceMock, validationServiceMock);
        command = ExternalPausesFixture_1.UpdateExternalPausesCommandFixture.create();
    });
    afterEach(() => {
        jest.resetAllMocks();
    });
    describe("execute", () => {
        it("should successfully update external pauses", async () => {
            contractServiceMock.getContractEvmAddress
                .mockResolvedValueOnce(evmAddress)
                .mockResolvedValueOnce(externalEvmAddress);
            accountServiceMock.getCurrentAccount.mockReturnValue(account);
            validationServiceMock.checkPause.mockResolvedValue(undefined);
            validationServiceMock.checkRole.mockResolvedValue(undefined);
            transactionServiceMock.getHandler().updateExternalPauses.mockResolvedValue({
                id: transactionId,
            });
            const result = await handler.execute(command);
            expect(result).toBeInstanceOf(UpdateExternalPausesCommand_js_1.UpdateExternalPausesCommandResponse);
            expect(result.payload).toBe(true);
            expect(result.transactionId).toBe(transactionId);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenCalledTimes(2);
            expect(accountServiceMock.getCurrentAccount).toHaveBeenCalledTimes(1);
            expect(transactionServiceMock.getHandler().updateExternalPauses).toHaveBeenCalledTimes(1);
            expect(validationServiceMock.checkPause).toHaveBeenCalledWith(command.securityId);
            expect(validationServiceMock.checkRole).toHaveBeenCalledWith(SecurityRole_1.SecurityRole._PAUSE_MANAGER_ROLE, account.id.toString(), command.securityId);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenNthCalledWith(1, command.securityId);
            expect(contractServiceMock.getContractEvmAddress).toHaveBeenNthCalledWith(2, command.externalPausesAddresses[0]);
            expect(transactionServiceMock.getHandler().updateExternalPauses).toHaveBeenCalledWith(evmAddress, [externalEvmAddress], command.actives, command.securityId);
        });
    });
});
