|
| 1 | +import { addBinaryOutcomes } from '../../src/utils/market-utils'; |
| 2 | +import { UnifiedMarket, MarketOutcome } from '../../src/types'; |
| 3 | + |
| 4 | +describe('addBinaryOutcomes', () => { |
| 5 | + const createMockMarket = (outcomeLabels: string[]): UnifiedMarket => { |
| 6 | + const outcomes: MarketOutcome[] = outcomeLabels.map((label, index) => ({ |
| 7 | + id: `id-${index}`, |
| 8 | + label, |
| 9 | + price: 0.5 |
| 10 | + })); |
| 11 | + |
| 12 | + return { |
| 13 | + id: 'market-1', |
| 14 | + title: 'Test Market', |
| 15 | + description: 'Test Description', |
| 16 | + outcomes, |
| 17 | + resolutionDate: new Date(), |
| 18 | + volume24h: 1000, |
| 19 | + liquidity: 5000, |
| 20 | + url: 'https://example.com' |
| 21 | + } as UnifiedMarket; |
| 22 | + }; |
| 23 | + |
| 24 | + test('should map explicit Yes/No outcomes', () => { |
| 25 | + const market = createMockMarket(['Yes', 'No']); |
| 26 | + addBinaryOutcomes(market); |
| 27 | + |
| 28 | + expect(market.yes?.label).toBe('Yes'); |
| 29 | + expect(market.no?.label).toBe('No'); |
| 30 | + }); |
| 31 | + |
| 32 | + test('should map explicit Up/Down outcomes', () => { |
| 33 | + const market = createMockMarket(['Up', 'Down']); |
| 34 | + addBinaryOutcomes(market); |
| 35 | + |
| 36 | + expect(market.up?.label).toBe('Up'); |
| 37 | + expect(market.down?.label).toBe('Down'); |
| 38 | + expect(market.yes?.label).toBe('Up'); |
| 39 | + expect(market.no?.label).toBe('Down'); |
| 40 | + }); |
| 41 | + |
| 42 | + test('should map "Not" patterns correctly', () => { |
| 43 | + const market = createMockMarket(['Kevin Warsh', 'Not Kevin Warsh']); |
| 44 | + addBinaryOutcomes(market); |
| 45 | + |
| 46 | + expect(market.yes?.label).toBe('Kevin Warsh'); |
| 47 | + expect(market.no?.label).toBe('Not Kevin Warsh'); |
| 48 | + }); |
| 49 | + |
| 50 | + test('should handle reversed order correctly', () => { |
| 51 | + const market = createMockMarket(['No', 'Yes']); |
| 52 | + addBinaryOutcomes(market); |
| 53 | + |
| 54 | + expect(market.yes?.label).toBe('Yes'); |
| 55 | + expect(market.no?.label).toBe('No'); |
| 56 | + }); |
| 57 | + |
| 58 | + test('should handle reversed "Not" order correctly', () => { |
| 59 | + const market = createMockMarket(['Not Trump', 'Trump']); |
| 60 | + addBinaryOutcomes(market); |
| 61 | + |
| 62 | + expect(market.yes?.label).toBe('Trump'); |
| 63 | + expect(market.no?.label).toBe('Not Trump'); |
| 64 | + }); |
| 65 | + |
| 66 | + test('should map Over/Under correctly', () => { |
| 67 | + const market = createMockMarket(['Over 2.5', 'Under 2.5']); |
| 68 | + addBinaryOutcomes(market); |
| 69 | + |
| 70 | + expect(market.yes?.label).toBe('Over 2.5'); |
| 71 | + expect(market.no?.label).toBe('Under 2.5'); |
| 72 | + }); |
| 73 | + |
| 74 | + test('should do nothing for non-binary markets', () => { |
| 75 | + const market = createMockMarket(['Home', 'Away', 'Draw']); |
| 76 | + addBinaryOutcomes(market); |
| 77 | + |
| 78 | + expect(market.yes).toBeUndefined(); |
| 79 | + expect(market.no).toBeUndefined(); |
| 80 | + }); |
| 81 | + |
| 82 | + test('should fallback to first index if "Not" cannot be determined', () => { |
| 83 | + // Obscure labels that don't match any patterns |
| 84 | + const market = createMockMarket(['Alpha', 'Beta']); |
| 85 | + addBinaryOutcomes(market); |
| 86 | + |
| 87 | + expect(market.yes?.label).toBe('Alpha'); |
| 88 | + expect(market.no?.label).toBe('Beta'); |
| 89 | + }); |
| 90 | +}); |
0 commit comments