From 231ec7f3e655a37962a24ed3d3384ae629ed9876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Thu, 7 Nov 2024 13:55:04 +0100 Subject: [PATCH] Fix tests --- src/hooks/useUpdateOwners/useAddOwner.test.ts | 12 ++++++++---- src/hooks/useUpdateOwners/useRemoveOwner.test.ts | 12 ++++++++---- src/hooks/useUpdateOwners/useSwapOwner.test.ts | 12 ++++++++---- src/hooks/useUpdateThreshold.test.ts | 12 ++++++++---- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/hooks/useUpdateOwners/useAddOwner.test.ts b/src/hooks/useUpdateOwners/useAddOwner.test.ts index 8f1e357..1c0097f 100644 --- a/src/hooks/useUpdateOwners/useAddOwner.test.ts +++ b/src/hooks/useUpdateOwners/useAddOwner.test.ts @@ -4,13 +4,14 @@ import { SafeClient } from '@safe-global/sdk-starter-kit' import * as useSendTransaction from '@/hooks/useSendTransaction.js' import * as useSignerClientMutation from '@/hooks/useSignerClientMutation.js' import { useAddOwner } from '@/hooks/useUpdateOwners/useAddOwner.js' +import * as useConfig from '@/hooks//useConfig.js' import { accounts, ethereumTxHash, safeMultisigTransaction, signerPrivateKeys } from '@test/fixtures/index.js' -import { configPredictedSafe } from '@test/config.js' +import { configExistingSafe, configPredictedSafe } from '@test/config.js' import { createCustomMutationResult } from '@test/fixtures/mutationResult/index.js' import { renderHookInQueryClientProvider } from '@test/utils.js' import { MutationKey } from '@/constants.js' @@ -30,6 +31,7 @@ describe('useAddOwner', () => { const useSendTransactionSpy = jest.spyOn(useSendTransaction, 'useSendTransaction') const useSignerClientMutationSpy = jest.spyOn(useSignerClientMutation, 'useSignerClientMutation') + const useConfigSpy = jest.spyOn(useConfig, 'useConfig') const createAddOwnerTxResultMock = safeMultisigTransaction const createAddOwnerTxMock = jest.fn().mockResolvedValue(createAddOwnerTxResultMock) @@ -59,6 +61,8 @@ describe('useAddOwner', () => { useSendTransactionSpy.mockReturnValue({ sendTransactionAsync: sendTransactionAsyncMock } as unknown as useSendTransaction.UseSendTransactionReturnType) + + useConfigSpy.mockReturnValue([configExistingSafe, () => {}]) }) afterEach(() => { @@ -71,7 +75,7 @@ describe('useAddOwner', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config: undefined }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationSafeClientFn: expect.any(Function), mutationKey: [MutationKey.AddOwner] @@ -79,7 +83,7 @@ describe('useAddOwner', () => { expect(result.current).toEqual(mutationIdleResult) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationKey: [MutationKey.AddOwner], mutationSafeClientFn: expect.any(Function) @@ -97,7 +101,7 @@ describe('useAddOwner', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ config, mutationSafeClientFn: expect.any(Function), diff --git a/src/hooks/useUpdateOwners/useRemoveOwner.test.ts b/src/hooks/useUpdateOwners/useRemoveOwner.test.ts index 48ef90f..7b24b78 100644 --- a/src/hooks/useUpdateOwners/useRemoveOwner.test.ts +++ b/src/hooks/useUpdateOwners/useRemoveOwner.test.ts @@ -3,6 +3,7 @@ import { waitFor } from '@testing-library/dom' import { SafeClient } from '@safe-global/sdk-starter-kit' import * as useSendTransaction from '@/hooks/useSendTransaction.js' import * as useSignerClientMutation from '@/hooks/useSignerClientMutation.js' +import * as useConfig from '@/hooks//useConfig.js' import { useRemoveOwner } from '@/hooks/useUpdateOwners/useRemoveOwner.js' import { accounts, @@ -10,7 +11,7 @@ import { safeMultisigTransaction, signerPrivateKeys } from '@test/fixtures/index.js' -import { configPredictedSafe } from '@test/config.js' +import { configExistingSafe, configPredictedSafe } from '@test/config.js' import { createCustomMutationResult } from '@test/fixtures/mutationResult/index.js' import { renderHookInQueryClientProvider } from '@test/utils.js' import { MutationKey } from '@/constants.js' @@ -30,6 +31,7 @@ describe('useRemoveOwner', () => { const useSendTransactionSpy = jest.spyOn(useSendTransaction, 'useSendTransaction') const useSignerClientMutationSpy = jest.spyOn(useSignerClientMutation, 'useSignerClientMutation') + const useConfigSpy = jest.spyOn(useConfig, 'useConfig') const createRemoveOwnerTxResultMock = safeMultisigTransaction const createRemoveOwnerTxMock = jest.fn().mockResolvedValue(createRemoveOwnerTxResultMock) @@ -60,6 +62,8 @@ describe('useRemoveOwner', () => { useSendTransactionSpy.mockReturnValue({ sendTransactionAsync: sendTransactionAsyncMock } as unknown as useSendTransaction.UseSendTransactionReturnType) + + useConfigSpy.mockReturnValue([configExistingSafe, () => {}]) }) afterEach(() => { @@ -72,7 +76,7 @@ describe('useRemoveOwner', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config: undefined }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationSafeClientFn: expect.any(Function), mutationKey: [MutationKey.RemoveOwner] @@ -80,7 +84,7 @@ describe('useRemoveOwner', () => { expect(result.current).toEqual(mutationIdleResult) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationKey: [MutationKey.RemoveOwner], mutationSafeClientFn: expect.any(Function) @@ -98,7 +102,7 @@ describe('useRemoveOwner', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ config, mutationSafeClientFn: expect.any(Function), diff --git a/src/hooks/useUpdateOwners/useSwapOwner.test.ts b/src/hooks/useUpdateOwners/useSwapOwner.test.ts index 227241e..7d800ff 100644 --- a/src/hooks/useUpdateOwners/useSwapOwner.test.ts +++ b/src/hooks/useUpdateOwners/useSwapOwner.test.ts @@ -3,6 +3,7 @@ import { waitFor } from '@testing-library/dom' import { SafeClient } from '@safe-global/sdk-starter-kit' import * as useSendTransaction from '@/hooks/useSendTransaction.js' import * as useSignerClientMutation from '@/hooks/useSignerClientMutation.js' +import * as useConfig from '@/hooks//useConfig.js' import { useSwapOwner } from '@/hooks/useUpdateOwners/useSwapOwner.js' import { accounts, @@ -10,7 +11,7 @@ import { safeMultisigTransaction, signerPrivateKeys } from '@test/fixtures/index.js' -import { configPredictedSafe } from '@test/config.js' +import { configExistingSafe, configPredictedSafe } from '@test/config.js' import { createCustomMutationResult } from '@test/fixtures/mutationResult/index.js' import { renderHookInQueryClientProvider } from '@test/utils.js' import { MutationKey } from '@/constants.js' @@ -28,6 +29,7 @@ describe('useSwapOwner', () => { const useSendTransactionSpy = jest.spyOn(useSendTransaction, 'useSendTransaction') const useSignerClientMutationSpy = jest.spyOn(useSignerClientMutation, 'useSignerClientMutation') + const useConfigSpy = jest.spyOn(useConfig, 'useConfig') const createSwapOwnerTxResultMock = safeMultisigTransaction const createSwapOwnerTxMock = jest.fn().mockResolvedValue(createSwapOwnerTxResultMock) @@ -57,6 +59,8 @@ describe('useSwapOwner', () => { useSendTransactionSpy.mockReturnValue({ sendTransactionAsync: sendTransactionAsyncMock } as unknown as useSendTransaction.UseSendTransactionReturnType) + + useConfigSpy.mockReturnValue([configExistingSafe, () => {}]) }) afterEach(() => { @@ -69,7 +73,7 @@ describe('useSwapOwner', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config: undefined }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationSafeClientFn: expect.any(Function), mutationKey: [MutationKey.SwapOwner] @@ -77,7 +81,7 @@ describe('useSwapOwner', () => { expect(result.current).toEqual(mutationIdleResult) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationKey: [MutationKey.SwapOwner], mutationSafeClientFn: expect.any(Function) @@ -95,7 +99,7 @@ describe('useSwapOwner', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ config, mutationSafeClientFn: expect.any(Function), diff --git a/src/hooks/useUpdateThreshold.test.ts b/src/hooks/useUpdateThreshold.test.ts index 72bdf61..a3a0f99 100644 --- a/src/hooks/useUpdateThreshold.test.ts +++ b/src/hooks/useUpdateThreshold.test.ts @@ -4,8 +4,9 @@ import { SafeClient } from '@safe-global/sdk-starter-kit' import { useUpdateThreshold } from '@/hooks/useUpdateThreshold.js' import * as useSendTransaction from '@/hooks/useSendTransaction.js' import * as useSignerClientMutation from '@/hooks/useSignerClientMutation.js' +import * as useConfig from '@/hooks//useConfig.js' import { ethereumTxHash, safeMultisigTransaction, signerPrivateKeys } from '@test/fixtures/index.js' -import { configPredictedSafe } from '@test/config.js' +import { configExistingSafe, configPredictedSafe } from '@test/config.js' import { createCustomMutationResult } from '@test/fixtures/mutationResult/index.js' import { renderHookInQueryClientProvider } from '@test/utils.js' import { MutationKey } from '@/constants.js' @@ -27,6 +28,7 @@ describe('useUpdateThreshold', () => { const useSendTransactionSpy = jest.spyOn(useSendTransaction, 'useSendTransaction') const useSignerClientMutationSpy = jest.spyOn(useSignerClientMutation, 'useSignerClientMutation') + const useConfigSpy = jest.spyOn(useConfig, 'useConfig') const createChangeThresholdTxMock = jest.fn().mockResolvedValue(changeThresholdTxMock) @@ -55,6 +57,8 @@ describe('useUpdateThreshold', () => { useSendTransactionSpy.mockReturnValue({ sendTransactionAsync: sendTransactionAsyncMock } as unknown as useSendTransaction.UseSendTransactionReturnType) + + useConfigSpy.mockReturnValue([configExistingSafe, () => {}]) }) afterEach(() => { @@ -67,7 +71,7 @@ describe('useUpdateThreshold', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config: undefined }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationSafeClientFn: expect.any(Function), mutationKey: [MutationKey.UpdateThreshold] @@ -75,7 +79,7 @@ describe('useUpdateThreshold', () => { expect(result.current).toEqual(mutationIdleResult) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ mutationKey: [MutationKey.UpdateThreshold], mutationSafeClientFn: expect.any(Function) @@ -93,7 +97,7 @@ describe('useUpdateThreshold', () => { expect(useSendTransactionSpy).toHaveBeenCalledTimes(1) expect(useSendTransactionSpy).toHaveBeenCalledWith({ config }) - expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1) + expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4) expect(useSignerClientMutationSpy).toHaveBeenCalledWith({ config, mutationSafeClientFn: expect.any(Function),