Skip to content

Commit

Permalink
test: add useWaitForTransactionReport test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiawpohr committed Sep 10, 2024
1 parent 2879469 commit 1852acd
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { SERVER } from '@/constants/config'
import { wrapper } from '@/utils/test-helpers/wrapper'
import { renderHook, waitFor } from '@testing-library/react'
import nock from 'nock'
import { useWaitForTransactionReport } from './useWaitForTransactionReport'

jest.mock('@/features/core/hooks/useUserState/useUserState', () => ({
useUserState: () => ({
getGuaranteedUserState: () => ({
id: {
secret: '0x123',
},
genProveReputationProof: jest.fn().mockResolvedValue({
publicSignals: 'mocked_signals',
proof: 'mocked_proof',
epoch: 0,
epochKey: 'mocked_epockKey',
}),
genEpochKeyLiteProof: jest.fn().mockResolvedValue({
publicSignals: 'mocked_signals',
proof: 'mocked_proof',
epoch: 0,
epochKey: 'mocked_epockKey',
}),
}),
}),
}))

jest.mock('@/features/core/hooks/useEpoch/useEpoch', () => ({
useEpoch: () => ({
currentEpoch: 2,
}),
}))

describe('useWaitForTransactionReport', () => {
afterEach(() => {
nock.restore()
})

it('should fetch pending reports', async () => {
const reports = [
{
reportId: '1',
objectId: '1',
category: 2,
reason: '偷偷置入性廣告,不OK餒!',
reportorEpochKey: '',
respondentEpochKey: '',
adjudicatorsNullifier: [],
createdAt: '2022-01-01T00:00:00.000Z',
updatedAt: '2022-01-01T00:00:00.000Z',
},
]

const expectation = nock(SERVER)
.get(
'/api/report?status=1&publicSignals=%22mocked_signals%22&proof=%22mocked_proof%22',
)
.reply(200, reports)

const { result } = renderHook(useWaitForTransactionReport, {
wrapper,
})

await waitFor(() => expect(result.current.isSuccess).toBe(true))

expect(result.current.data).toEqual(reports)

expectation.done()
})
})

0 comments on commit 1852acd

Please sign in to comment.