|
| 1 | +import { BigNumber } from 'ethers' |
| 2 | +import { createGetBalancesCaller } from './getBalances' |
| 3 | + |
| 4 | +describe('GetBalances.spec.ts', () => { |
| 5 | + describe('createGetBalancesCaller', () => { |
| 6 | + it('call success', async () => { |
| 7 | + const value = [ |
| 8 | + { account: '0x0', balance: BigNumber.from(1) }, |
| 9 | + { account: '0x1', balance: BigNumber.from(2) }, |
| 10 | + { account: '0x2', balance: BigNumber.from(3) }, |
| 11 | + ] |
| 12 | + |
| 13 | + const propertyContract = { |
| 14 | + GetBalances: jest |
| 15 | + .fn() |
| 16 | + .mockImplementation(async () => Promise.resolve(value)), |
| 17 | + } |
| 18 | + |
| 19 | + const expected = [ |
| 20 | + { account: '0x0', balance: '1' }, |
| 21 | + { account: '0x1', balance: '2' }, |
| 22 | + { account: '0x2', balance: '3' }, |
| 23 | + ] |
| 24 | + |
| 25 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 26 | + const caller = createGetBalancesCaller(propertyContract as any) |
| 27 | + |
| 28 | + const result = await caller() |
| 29 | + |
| 30 | + expect(result).toEqual(expected) |
| 31 | + }) |
| 32 | + |
| 33 | + it('call failure', async () => { |
| 34 | + const error = 'error' |
| 35 | + |
| 36 | + const propertyContract = { |
| 37 | + GetBalances: jest |
| 38 | + .fn() |
| 39 | + .mockImplementation(async () => Promise.reject(error)), |
| 40 | + } |
| 41 | + |
| 42 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 43 | + const caller = createGetBalancesCaller(propertyContract as any) |
| 44 | + |
| 45 | + const result = await caller().catch((err) => err) |
| 46 | + |
| 47 | + expect(result).toEqual(error) |
| 48 | + }) |
| 49 | + }) |
| 50 | +}) |
0 commit comments