-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathfeed.test.ts
More file actions
152 lines (127 loc) · 4.27 KB
/
feed.test.ts
File metadata and controls
152 lines (127 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { deduplicateSeriesMarkets, filterStandaloneMarkets } from './feed';
import { Recurrence, type PredictMarket } from '../types';
const createMockMarket = (
id: string,
overrides: Partial<PredictMarket> = {},
): PredictMarket =>
({
id,
providerId: 'polymarket',
slug: `market-${id}`,
title: `Market ${id}`,
description: 'Description',
image: 'https://example.com/img.png',
status: 'open',
recurrence: Recurrence.NONE,
category: 'crypto',
tags: [],
outcomes: [],
liquidity: 100,
volume: 200,
...overrides,
}) as PredictMarket;
const createUpDownMarket = (id: string, seriesSlug: string): PredictMarket =>
createMockMarket(id, {
series: {
id: `s-${seriesSlug}`,
slug: seriesSlug,
title: seriesSlug,
recurrence: '5m',
},
tags: ['crypto', 'up-or-down'],
});
describe('deduplicateSeriesMarkets', () => {
it('returns empty array for empty input', () => {
const result = deduplicateSeriesMarkets([]);
expect(result).toEqual([]);
});
it('passes through non-series markets unchanged', () => {
const marketA = createMockMarket('a');
const marketB = createMockMarket('b');
const marketC = createMockMarket('c');
const result = deduplicateSeriesMarkets([marketA, marketB, marketC]);
expect(result).toEqual([marketA, marketB, marketC]);
});
it('keeps first occurrence of a Crypto Up/Down series slug', () => {
const first = createUpDownMarket('event-1', 'btc-up-or-down-5m');
const duplicate = createUpDownMarket('event-2', 'btc-up-or-down-5m');
const regular = createMockMarket('regular');
const result = deduplicateSeriesMarkets([first, regular, duplicate]);
expect(result).toEqual([first, regular]);
});
it('deduplicates multiple series independently', () => {
const btc1 = createUpDownMarket('btc-1', 'btc-up-or-down-5m');
const eth1 = createUpDownMarket('eth-1', 'eth-up-or-down-1h');
const btc2 = createUpDownMarket('btc-2', 'btc-up-or-down-5m');
const eth2 = createUpDownMarket('eth-2', 'eth-up-or-down-1h');
const result = deduplicateSeriesMarkets([btc1, eth1, btc2, eth2]);
expect(result).toEqual([btc1, eth1]);
});
it('preserves order of non-series markets mixed with series', () => {
const regular1 = createMockMarket('r1');
const btc1 = createUpDownMarket('btc-1', 'btc-up-or-down-5m');
const regular2 = createMockMarket('r2');
const btc2 = createUpDownMarket('btc-2', 'btc-up-or-down-5m');
const regular3 = createMockMarket('r3');
const result = deduplicateSeriesMarkets([
regular1,
btc1,
regular2,
btc2,
regular3,
]);
expect(result).toEqual([regular1, btc1, regular2, regular3]);
});
it('does not deduplicate non-Up/Down series markets', () => {
const tweet1 = createMockMarket('tweet-1', {
series: {
id: 's-tweets',
slug: 'elon-tweets',
title: 'Elon Tweets',
recurrence: 'monthly',
},
tags: ['entertainment'],
});
const tweet2 = createMockMarket('tweet-2', {
series: {
id: 's-tweets',
slug: 'elon-tweets',
title: 'Elon Tweets',
recurrence: 'monthly',
},
tags: ['entertainment'],
});
const result = deduplicateSeriesMarkets([tweet1, tweet2]);
expect(result).toEqual([tweet1, tweet2]);
});
it('handles single Up/Down market without removing it', () => {
const single = createUpDownMarket('only-one', 'btc-up-or-down-5m');
const result = deduplicateSeriesMarkets([single]);
expect(result).toEqual([single]);
});
});
describe('filterStandaloneMarkets', () => {
it('removes markets with a parent market id', () => {
const parent = createMockMarket('parent');
const emptyParent = createMockMarket('empty-parent', {
parentMarketId: '',
});
const nullParent = createMockMarket('null-parent', {
parentMarketId: null,
});
const child = createMockMarket('child', {
parentMarketId: 'parent',
});
const numericChild = createMockMarket('numeric-child', {
parentMarketId: 123,
});
const result = filterStandaloneMarkets([
parent,
emptyParent,
nullParent,
child,
numericChild,
]);
expect(result).toEqual([parent, emptyParent, nullParent]);
});
});