Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Nov 7, 2024
1 parent 79fed23 commit 231ec7f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/hooks/useUpdateOwners/useAddOwner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -59,6 +61,8 @@ describe('useAddOwner', () => {
useSendTransactionSpy.mockReturnValue({
sendTransactionAsync: sendTransactionAsyncMock
} as unknown as useSendTransaction.UseSendTransactionReturnType)

useConfigSpy.mockReturnValue([configExistingSafe, () => {}])
})

afterEach(() => {
Expand All @@ -71,15 +75,15 @@ 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]
})

expect(result.current).toEqual(mutationIdleResult)

expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1)
expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4)
expect(useSignerClientMutationSpy).toHaveBeenCalledWith({
mutationKey: [MutationKey.AddOwner],
mutationSafeClientFn: expect.any(Function)
Expand All @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/useUpdateOwners/useRemoveOwner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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,
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'
Expand All @@ -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)
Expand Down Expand Up @@ -60,6 +62,8 @@ describe('useRemoveOwner', () => {
useSendTransactionSpy.mockReturnValue({
sendTransactionAsync: sendTransactionAsyncMock
} as unknown as useSendTransaction.UseSendTransactionReturnType)

useConfigSpy.mockReturnValue([configExistingSafe, () => {}])
})

afterEach(() => {
Expand All @@ -72,15 +76,15 @@ 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]
})

expect(result.current).toEqual(mutationIdleResult)

expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1)
expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4)
expect(useSignerClientMutationSpy).toHaveBeenCalledWith({
mutationKey: [MutationKey.RemoveOwner],
mutationSafeClientFn: expect.any(Function)
Expand All @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/useUpdateOwners/useSwapOwner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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,
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'
Expand All @@ -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)
Expand Down Expand Up @@ -57,6 +59,8 @@ describe('useSwapOwner', () => {
useSendTransactionSpy.mockReturnValue({
sendTransactionAsync: sendTransactionAsyncMock
} as unknown as useSendTransaction.UseSendTransactionReturnType)

useConfigSpy.mockReturnValue([configExistingSafe, () => {}])
})

afterEach(() => {
Expand All @@ -69,15 +73,15 @@ 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]
})

expect(result.current).toEqual(mutationIdleResult)

expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1)
expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4)
expect(useSignerClientMutationSpy).toHaveBeenCalledWith({
mutationKey: [MutationKey.SwapOwner],
mutationSafeClientFn: expect.any(Function)
Expand All @@ -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),
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/useUpdateThreshold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)

Expand Down Expand Up @@ -55,6 +57,8 @@ describe('useUpdateThreshold', () => {
useSendTransactionSpy.mockReturnValue({
sendTransactionAsync: sendTransactionAsyncMock
} as unknown as useSendTransaction.UseSendTransactionReturnType)

useConfigSpy.mockReturnValue([configExistingSafe, () => {}])
})

afterEach(() => {
Expand All @@ -67,15 +71,15 @@ 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]
})

expect(result.current).toEqual(mutationIdleResult)

expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(1)
expect(useSignerClientMutationSpy).toHaveBeenCalledTimes(4)
expect(useSignerClientMutationSpy).toHaveBeenCalledWith({
mutationKey: [MutationKey.UpdateThreshold],
mutationSafeClientFn: expect.any(Function)
Expand All @@ -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),
Expand Down

0 comments on commit 231ec7f

Please sign in to comment.