|
| 1 | +import * as strategies from '../../../src/helpers/strategies'; |
| 2 | +import { hasStrategyOverride } from '../../../src/helpers/utils'; |
| 3 | +import { STRATEGIES_FIXTURE } from '../../fixtures/strategies'; |
| 4 | + |
| 5 | +// Mock the getStrategies function |
| 6 | +jest.mock('../../../src/helpers/strategies'); |
| 7 | +const mockGetStrategies = jest.mocked(strategies.getStrategies); |
| 8 | + |
| 9 | +describe('Utils', () => { |
| 10 | + describe('hasStrategyOverride()', () => { |
| 11 | + beforeEach(() => { |
| 12 | + jest.clearAllMocks(); |
| 13 | + mockGetStrategies.mockReturnValue(STRATEGIES_FIXTURE); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should return false when strategies array is empty', () => { |
| 17 | + expect(hasStrategyOverride([])).toBe(false); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should return false when no overriding strategies exist', () => { |
| 21 | + const strategies = [ |
| 22 | + { name: 'whitelist', network: '1', params: {} }, |
| 23 | + { name: 'ticket', network: '1', params: {} } |
| 24 | + ]; |
| 25 | + |
| 26 | + expect(hasStrategyOverride(strategies)).toBe(false); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return true when an overriding strategy is used', () => { |
| 30 | + const strategies = [ |
| 31 | + { name: 'whitelist', network: '1', params: {} }, |
| 32 | + { name: 'delegation', network: '1', params: {} } |
| 33 | + ]; |
| 34 | + |
| 35 | + expect(hasStrategyOverride(strategies)).toBe(true); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should return true when multiple overriding strategies are used', () => { |
| 39 | + const strategies = [ |
| 40 | + { name: 'delegation', network: '1', params: {} }, |
| 41 | + { name: 'delegation-with-cap', network: '1', params: {} } |
| 42 | + ]; |
| 43 | + |
| 44 | + expect(hasStrategyOverride(strategies)).toBe(true); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should handle mixed case strategy names correctly', () => { |
| 48 | + const strategies = [{ name: 'Delegation', network: '1', params: {} }]; |
| 49 | + |
| 50 | + expect(hasStrategyOverride(strategies)).toBe(true); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should handle case where overriding strategy is disabled', () => { |
| 54 | + mockGetStrategies.mockReturnValue({ |
| 55 | + delegation: { id: 'delegation', override: true, disabled: true } |
| 56 | + }); |
| 57 | + |
| 58 | + const strategies = [{ name: 'delegation', network: '1', params: {} }]; |
| 59 | + |
| 60 | + expect(hasStrategyOverride(strategies)).toBe(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should handle inner strategies', () => { |
| 64 | + const strategies = [ |
| 65 | + { |
| 66 | + name: 'multichain', |
| 67 | + network: '1', |
| 68 | + params: { |
| 69 | + symbol: 'MULTI', |
| 70 | + strategies: [ |
| 71 | + { |
| 72 | + name: 'erc20-balance-of', |
| 73 | + network: '1', |
| 74 | + params: { |
| 75 | + address: '0x579cea1889991f68acc35ff5c3dd0621ff29b0c9', |
| 76 | + decimals: 18 |
| 77 | + } |
| 78 | + }, |
| 79 | + { |
| 80 | + name: 'delegation', |
| 81 | + network: '137', |
| 82 | + params: { |
| 83 | + delegationSpace: 'test.eth', |
| 84 | + strategies: [ |
| 85 | + { |
| 86 | + name: 'erc20-balance-of', |
| 87 | + params: { |
| 88 | + address: '0xB9638272aD6998708de56BBC0A290a1dE534a578', |
| 89 | + decimals: 18 |
| 90 | + } |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + } |
| 95 | + ] |
| 96 | + } |
| 97 | + } |
| 98 | + ]; |
| 99 | + |
| 100 | + expect(hasStrategyOverride(strategies)).toBe(true); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should not match when strategy id appears in other fields', () => { |
| 104 | + const strategies = [ |
| 105 | + { |
| 106 | + name: 'whitelist', |
| 107 | + network: '1', |
| 108 | + params: { description: 'delegation' } |
| 109 | + } |
| 110 | + ]; |
| 111 | + |
| 112 | + expect(hasStrategyOverride(strategies)).toBe(false); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should handle empty getStrategies result', () => { |
| 116 | + mockGetStrategies.mockReturnValue({}); |
| 117 | + |
| 118 | + const strategies = [{ name: 'delegation', network: '1', params: {} }]; |
| 119 | + |
| 120 | + expect(hasStrategyOverride(strategies)).toBe(false); |
| 121 | + }); |
| 122 | + }); |
| 123 | +}); |
0 commit comments