|
| 1 | +import { getProposal } from '../../../src/helpers/utils'; |
| 2 | + |
| 3 | +const PROPOSAL = { id: '0x0', flagged: false }; |
| 4 | + |
| 5 | +const mockSnapshotUtilsSubgraphRequest = jest.fn((): any => { |
| 6 | + return {}; |
| 7 | +}); |
| 8 | +jest.mock('@snapshot-labs/snapshot.js', () => { |
| 9 | + const originalModule = jest.requireActual('@snapshot-labs/snapshot.js'); |
| 10 | + |
| 11 | + return { |
| 12 | + ...originalModule, |
| 13 | + utils: { |
| 14 | + ...originalModule.utils, |
| 15 | + subgraphRequest: () => mockSnapshotUtilsSubgraphRequest() |
| 16 | + } |
| 17 | + }; |
| 18 | +}); |
| 19 | + |
| 20 | +describe('getProposal()', () => { |
| 21 | + it('returns null when the proposal is flagged', () => { |
| 22 | + mockSnapshotUtilsSubgraphRequest.mockResolvedValueOnce({ |
| 23 | + proposal: { ...PROPOSAL, flagged: true } |
| 24 | + }); |
| 25 | + expect(getProposal('')).resolves.toBeNull(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('returns null when the proposal does not exist', () => { |
| 29 | + mockSnapshotUtilsSubgraphRequest.mockResolvedValueOnce({ proposal: null }); |
| 30 | + expect(getProposal('')).resolves.toBeNull(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('returns null on missing response', () => { |
| 34 | + mockSnapshotUtilsSubgraphRequest.mockResolvedValueOnce({}); |
| 35 | + expect(getProposal('')).resolves.toBeNull(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('returns the proposal', () => { |
| 39 | + mockSnapshotUtilsSubgraphRequest.mockResolvedValueOnce({ proposal: PROPOSAL }); |
| 40 | + expect(getProposal('')).resolves.toEqual(PROPOSAL); |
| 41 | + }); |
| 42 | +}); |
0 commit comments