overtime-live-trading-utils 2.0.55 → 2.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtime-live-trading-utils",
3
- "version": "2.0.55",
3
+ "version": "2.0.57",
4
4
  "description": "",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "@types/node": "^20.8.10",
16
16
  "bytes32": "^0.0.3",
17
17
  "oddslib": "^2.1.1",
18
- "overtime-utils": "^0.0.101",
18
+ "overtime-utils": "^0.0.102",
19
19
  "react": "^17.0.1"
20
20
  },
21
21
  "devDependencies": {
@@ -76,350 +76,3 @@ export const LEAGUES_NO_FORMAL_HOME_AWAY = [
76
76
  ];
77
77
 
78
78
  export const UFC_LEAGUE_IDS = [701, 702, 703, 704];
79
-
80
- export const LeagueIdMapRundown = {
81
- 1: 1, // NCAAF
82
- 2: 2, // NFL
83
- 3: 3, // MLB
84
- 4: 4, // NBA
85
- 5: 5, // NCAAB
86
- 6: 6, // NHL
87
- 7: 7, // UFC
88
- 8: 8, // WNBA
89
- 10: 10, // MLS
90
- 11: 11, // EPL
91
- 12: 12, // France League 1
92
- 13: 13, // Bundesliga
93
- 14: 14, // La Liga
94
- 15: 15, // Seria A
95
- 16: 16, // Champions League
96
- 17: 17, // Europa League
97
- 18: 18, // FIFA WC
98
- 19: 19, // J1
99
- 20: 20, // IPL
100
- 21: 21, // T20
101
- };
102
-
103
- export const LeagueIdMapEnetpulse = {
104
- 320: 18, // Hockey Norway
105
- 6: 24, // NHL
106
- 33: 33, // Hockey World Championship
107
- 16: 42, // Champions League
108
- 44: 44, // Copa America
109
- 45: 45, // Copa Libertadores
110
- 11: 47, // EPL
111
- 50: 50, // UEFA EURO
112
- 12: 53, // France League 1
113
- 13: 54, // Bundesliga
114
- 15: 55, // Seria A
115
- 57: 57, // Netherlands League 1
116
- 61: 61, // Portugal League 1
117
- 65: 65, // Summer Olympics Soccer Women
118
- 66: 66, // Summer Olympics Soccer
119
- 17: 73, // Europa League
120
- 76: 76, // World Cup Woman
121
- 14: 87, // La Liga
122
- 152: 152, // Tennis WTA
123
- 153: 153, // Tennis GS
124
- 156: 156, // Tennis Masters 1000
125
- 158: 158, // Summer Olympics Tennnis
126
- 132: 132, // FA Cup
127
- 134: 134, // Coupe de France
128
- 138: 138, // Copa del Rey
129
- 141: 141, // Coppa Italia
130
- 209: 209, // DFB Pokal
131
- 230: 230, // LIGA MX
132
- 268: 268, // Brazil Football League
133
- 288: 288, // EURO U21
134
- 296: 296, // FIFA WC U20
135
- 310: 310, // Hockey Czech
136
- 319: 319, // Hockey Finland
137
- 322: 322, // Hockey Germany
138
- 327: 327, // Hockey Switzerland
139
- 380: 380, // Summer Olympics Handball Women
140
- 381: 381, // Summer Olympics Handball
141
- 399: 399, // EuroLeague
142
- 406: 406, // Summer Olympics Basketball
143
- 407: 407, // Summer Olympics Basketball Women
144
- 409: 409, // FIBA World Cup
145
- 445: 445, // F1
146
- 453: 453, // Summer Olympics Beach Voleyball Women
147
- 454: 454, // Summer Olympics Beach Voleyball
148
- 497: 497, // Moto GP
149
- 536: 536, // Saudi Arabia Football League
150
- 8881: 8881, // Summer Olympics Water Polo
151
- 8893: 8893, // Summer Olympics Voleyball Women
152
- 8894: 8894, // Summer Olympics Voleyball
153
- 8910: 8910, // Summer Olympics Table Tennnis
154
- 9196: 9196, // Boxing
155
- 9578: 9578, // Summer Olympics Rugby
156
- 9588: 9588, // Summer Olympics Rugby Women
157
- 9698: 9698, // Summer Olympics Hockey Women
158
- 9699: 9699, // Summer Olympics Hockey
159
- 9806: 9806, // UEFA League of Nations
160
- 9821: 9821, // CONCACAF League of Nations
161
- 9977: 9977, // CsGo
162
- 9983: 9983, // Dota
163
- 10071: 10071, // Summer Olympics Basketball 3x3
164
- 10072: 10072, // Summer Olympics Basketball 3x3 Women
165
- 10502: 10502, // Summer Olympics Basketball Qualification
166
- 10138: 10138, // LOL
167
- 10199: 10199, // World Cup Qualifications CONMBOL
168
- 10216: 10216, // Europa Conference League
169
- 10595: 10595, // Non-Title Boxing
170
- 10611: 10611, // Champions League Qualification
171
- 10613: 10613, // Europa League Qualification
172
- 10615: 10615, // Conference League Qualification
173
- };
174
-
175
- export const LeagueIdMapOpticOdds: Record<number, string> = {
176
- 1: 'NCAAF',
177
- 2: 'NFL',
178
- 3: 'MLB',
179
- 4: 'NBA',
180
- 5: 'NCAAB',
181
- 6: 'NHL',
182
- 7: 'UFC',
183
- 8: 'WNBA',
184
- 9: 'PFL',
185
- 10: 'USA - Major League Soccer',
186
- 11: 'England - Premier League',
187
- 12: 'France - Ligue 1',
188
- 13: 'Germany - Bundesliga',
189
- 14: 'Spain - La Liga',
190
- 15: 'Italy - Serie A',
191
- 16: 'UEFA - Champions League',
192
- 17: 'UEFA - Europa League',
193
- 18: 'FIFA - World Cup Qualifiers',
194
- 19: 'Japan - J1 League',
195
- 20: 'India - IPL',
196
- 21: 'England - T20 Blast',
197
- 33: 'IIHF - World Championship',
198
- 45: 'CONMEBOL - Copa Libertadores',
199
- 57: 'Netherlands - Eredivisie',
200
- 61: 'Portugal - Primeira Liga',
201
- 132: 'England - FA Cup',
202
- 134: 'France - Coupe de France',
203
- 138: 'Spain - Copa del Rey',
204
- 152: 'WTA',
205
- 156: 'ATP',
206
- 157: 'ATP Challenger',
207
- 141: 'Italy - Coppa Italia',
208
- 209: 'Germany - DFB Pokal',
209
- 230: 'Mexico - Liga MX',
210
- 268: 'Brazil - Serie A',
211
- 301: 'NPB',
212
- 302: 'KBO',
213
- 303: 'College Baseball',
214
- 304: 'CPBL',
215
- 310: 'Czech Republic - Extraliga',
216
- 319: 'Finland - SM Liiga',
217
- 321: 'Russia - KHL',
218
- 322: 'Germany - DEL',
219
- 323: 'Austria - Ice Hockey League',
220
- 324: 'Sweden - SHL',
221
- 327: 'Switzerland - National League',
222
- 328: 'USA - AHL',
223
- 379: 'North Macedonia - Super Liga',
224
- 382: 'Croatia - HB Premijer Liga',
225
- 383: 'EHF - Champions League',
226
- 384: 'EHF - Champions League Women',
227
- 385: 'EHF - European League',
228
- 386: 'France - LNH Division 1',
229
- 387: 'Germany - HBL',
230
- 388: 'Hungary - HNB I',
231
- 389: 'Iceland - Urvalsdeild',
232
- 390: 'IHF - World Championship',
233
- 391: 'Norway - HB 1. Divisjon',
234
- 392: 'Poland - Superliga',
235
- 393: 'Russia - Super League',
236
- 394: 'Serbia - Superliga',
237
- 395: 'Slovakia - HB Extraliga',
238
- 396: 'Slovenia - 1. Liga',
239
- 397: 'Spain - ASOBAL',
240
- 398: 'Sweden - Handbollsligan',
241
- 399: 'Euroleague',
242
- 400: 'USA - NBA Summer League',
243
- 536: 'Saudi Arabia - Saudi League',
244
- 8909: 'Olympics Table Tennis Women',
245
- 8910: 'Olympics Table Tennis Men',
246
- 8911: 'Czech Republic - TT Cup Men',
247
- 8912: 'Czech Republic - TT Liga Pro Men',
248
- 8913: 'Poland - TT Elite Series Men',
249
- 8914: 'WTT Men',
250
- 9500: 'Australia - NRL',
251
- 9501: 'England - Super League',
252
- 9502: 'Oceania - Super Rugby',
253
- 9503: 'International - Six Nations',
254
- 9510: 'AFL',
255
- 9520: 'CFL',
256
- 9521: 'UFL',
257
- 9806: 'UEFA - Nations League',
258
- 9977: 'CS2',
259
- 9983: 'Dota 2',
260
- 10138: 'League of Legends',
261
- 10216: 'UEFA - Europa Conference League',
262
- 20001: 'UEFA - Super Cup',
263
- 20002: 'Brazil - Copa do Brasil',
264
- 20011: 'England - Championship',
265
- 20101: 'Scotland - Premiership',
266
- 20102: 'Belgium - Jupiler Pro League',
267
- 20103: 'Czech Republic - FNL',
268
- 20104: 'Chile - Primera Division',
269
- 20105: 'Finland - Veikkausliiga',
270
- 20106: 'Argentina - Primera Division',
271
- 20107: 'Russia - Premier League',
272
- 20108: 'Turkey - Super Lig',
273
- 20109: 'Serbia - Super Liga',
274
- 20110: 'Greece - Super League',
275
- 20111: 'India - Calcutta Premier Division',
276
- 20112: 'China - Super League',
277
- 20113: 'Australia - A-League',
278
- 20114: 'Switzerland - Super League',
279
- 20115: 'Germany - Bundesliga 2',
280
- 20116: 'Spain - La Liga 2',
281
- 20117: 'Italy - Serie B',
282
- 20118: 'India - Super League',
283
- 20119: 'France - Ligue 2',
284
- 20120: 'Austria - Bundesliga',
285
- 20121: 'Denmark - Superliga',
286
- 20122: 'Poland - Ekstraklasa',
287
- 20123: 'Sweden - Allsvenskan',
288
- 20124: 'Colombia - Primera A',
289
- 20125: 'England - EFL Cup',
290
- 20126: 'England - League 1',
291
- 20127: 'Uruguay - Primera Division',
292
- 20128: 'AFC - Champions League',
293
- 20129: 'Italy - Supercoppa',
294
- 20130: 'France - Super Cup',
295
- 20131: 'Spain - Supercopa',
296
- 20132: 'Germany - Super Cup',
297
- 20133: 'Portugal - League Cup',
298
- 20134: 'Thailand - Thai League 1',
299
- 20135: 'Netherlands - KNVB Beker',
300
- 20136: 'Portugal - Taca de Portugal',
301
- 20137: 'England - Womens Super League',
302
- 20138: 'Italy - Serie A Femminile',
303
- 20139: 'France - Premiere Ligue',
304
- 20140: 'Germany - Frauen Bundesliga',
305
- 20141: 'Spain - Liga F',
306
- 20142: 'Netherlands - Vrouwen Eredivisie',
307
- 20143: 'Belgium - Womens Super League',
308
- 20144: 'UEFA - Champions League Women',
309
- 20145: 'USA - NWSL',
310
- 20146: 'Australia - A-League Women',
311
- 20147: 'CONCACAF - Champions Cup',
312
- 20148: 'UEFA - Nations League Women',
313
- 20149: 'Canada - Premier League',
314
- 20150: 'Norway - Eliteserien',
315
- 20151: 'USA - Open Cup',
316
- 20152: 'FIFA - Club World Cup',
317
- 20200: 'Eurocup',
318
- 20201: 'Spain - Liga ACB',
319
- 20202: 'Italy - Lega Basket Serie A',
320
- 20203: 'Germany - BBL',
321
- 20204: 'France - LNB Pro A',
322
- 20205: 'China - CBA',
323
- 20206: 'Australia - NBL',
324
- 20210: 'BIG3',
325
- 20211: 'NCAAW',
326
- 20212: 'FIBA - Americup Qualifiers',
327
- 20213: 'FIBA - Asia Cup Qualifiers',
328
- 20214: 'FIBA - Eurobasket Qualifiers',
329
- 20215: 'FIBA - World Cup Qualifiers',
330
- 20216: 'FIBA - AfroBasket Qualifiers',
331
- 20217: 'Greece - A1 League',
332
- 20218: 'International - Champions League',
333
- 20219: 'Turkey - BSL',
334
- 20220: 'FIBA - Eurobasket Women',
335
- 20221: 'Philippines - Phillipine Cup',
336
- 20222: 'FIBA - World Cup U19',
337
- 20223: 'FIBA - Americup Women',
338
- 20296: 'Overwatch',
339
- 20297: 'Rocket League',
340
- 20298: 'Call of Duty',
341
- 20299: 'Starcraft',
342
- 20300: 'Valorant',
343
- 20293: 'Rainbow Six Siege',
344
- 20294: 'Starcraft 2',
345
- 20295: 'Mobile Legends Bang Bang',
346
- 20301: 'ICC - T20 World Cup',
347
- 20302: 'Australia - Big Bash League',
348
- 20303: 'USA - Major League Cricket',
349
- 20304: 'Australia - Big Bash League Women',
350
- 20305: 'Pakistan - Super League',
351
- 20320: 'England - Premier League Darts',
352
- 20321: 'PDC - World Cup of Darts',
353
- 20400: 'Argentina - Liga Argentina',
354
- 20401: 'Argentina - Liga Argentina Women',
355
- 20402: 'Austria - AVL',
356
- 20403: 'Austria - WVL',
357
- 20404: 'Belgium - Liga Dames',
358
- 20405: 'Belgium - Liga Heren',
359
- 20406: 'Brazil - Superliga',
360
- 20407: 'Brazil - Superliga Women',
361
- 20408: 'CEV - Champions League',
362
- 20409: 'CEV - Champions League Women',
363
- 20410: 'CEV - Cup',
364
- 20411: 'CEV - Cup Women',
365
- 20412: 'China - CVL',
366
- 20413: 'China - CVL Women',
367
- 20414: 'Czech Republic - VEL',
368
- 20415: 'Czech Republic - VEL Women',
369
- 20416: 'Denmark - Volleyligaen',
370
- 20417: 'Denmark - Volleyligaen Women',
371
- 20418: 'Finland - Mestaruusliiga',
372
- 20419: 'Finland - Mestaruusliiga Women',
373
- 20420: 'FIVB - Nations League',
374
- 20421: 'FIVB - Nations League Women',
375
- 20422: 'France - Ligue A',
376
- 20423: 'France - Ligue A Women',
377
- 20424: 'Germany - 1st Bundesliga',
378
- 20425: 'Germany - 1st Bundesliga Women',
379
- 20426: 'Iran - Super League',
380
- 20427: 'Italy - Coppa Italia A1 Women',
381
- 20428: 'Italy - Coppa Italia Superlega',
382
- 20429: 'Italy - Serie A1 Women',
383
- 20430: 'Italy - Superlega',
384
- 20431: 'Japan - SV League',
385
- 20432: 'Japan - SV League Women',
386
- 20433: 'Norway - NVBF',
387
- 20434: 'Philippines - PVL Women',
388
- 20435: 'Poland - PlusLiga',
389
- 20436: 'Russia - Superliga',
390
- 20437: 'Russia - Superliga Women',
391
- 20438: 'South Korea - V League',
392
- 20439: 'South Korea - V League Women',
393
- 20516: 'CONCACAF - Gold Cup',
394
- 20535: 'Ecuador - Serie A',
395
- 20555: 'COSAFA - Cup',
396
- 20578: 'Iceland - Besta Deild Karla',
397
- 20603: 'Korea - K1 League',
398
- 20651: 'Peru - Primera Division',
399
- 20712: 'UEFA - European Championship U21',
400
- 20713: 'UEFA - European Championship Women',
401
- 20870: 'FINA - World Championship',
402
- 20871: 'FINA - World Championship Women',
403
- 305: 'USA - MLB All Star',
404
- 20310: 'USA - National Lacrosse League',
405
- 20311: 'USA - Premier Lacrosse League',
406
- 20507: 'Bulgaria - Parva Liga',
407
- 20520: 'Croatia - 1. HNL',
408
- 20572: 'Hungary - NB I',
409
- 20590: 'Ireland - Premier League',
410
- 20612: 'Latvia - Virsliga',
411
- 20616: 'Lithuania - A Lyga',
412
- 20661: 'Romania - Liga I',
413
- 20682: 'Slovenia - PrvaLiga',
414
- 20714: 'Slovakia - Superliga',
415
- 20715: 'China - FA Cup',
416
- 20529: 'Czech Republic - First League',
417
- 20637: 'North America - Leagues Cup',
418
- 20503: 'Brazil - Serie B',
419
- 20166: 'Australia - Cup',
420
- 20600: 'Kazakhstan - Premier League',
421
- 20549: 'Estonia - Premium Liiga',
422
- 20702: 'USA - USL Championship',
423
- 20519: 'Costa Rica - Primera Division',
424
- 20663: 'Russia - Cup',
425
- };
@@ -0,0 +1,296 @@
1
+ import {
2
+ mapFromOpticOddsToOvertimeFormat,
3
+ formatOpticOddsLeagueName,
4
+ mapFromOvertimeToOpticOddsFormat,
5
+ mapFromOpticOddsFormatToBytes32,
6
+ mapFromBytes32ToOpticOddsFormat,
7
+ convertFromBytes32
8
+ } from '../../utils/opticOdds';
9
+ import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../../constants/common';
10
+
11
+ // Mock the overtime-utils module
12
+ jest.mock('overtime-utils', () => ({
13
+ LeagueMap: {
14
+ 9002: {
15
+ id: 9002,
16
+ name: 'Premier League',
17
+ opticOddsName: 'English Premier League',
18
+ },
19
+ 9001: {
20
+ id: 9001,
21
+ name: 'Bundesliga',
22
+ opticOddsName: 'German Bundesliga',
23
+ },
24
+ 9003: {
25
+ id: 9003,
26
+ name: 'La Liga',
27
+ opticOddsName: 'Spanish La Liga',
28
+ },
29
+ 9005: {
30
+ id: 9005,
31
+ name: 'Champions League',
32
+ opticOddsName: 'UEFA Champions League',
33
+ },
34
+ 9006: {
35
+ id: 9006,
36
+ name: 'NBA',
37
+ opticOddsName: 'National Basketball Association',
38
+ }
39
+ },
40
+ getLeagueOpticOddsName: jest.fn((leagueId: number) => {
41
+ const leagueMap: { [key: number]: string } = {
42
+ 9002: 'English Premier League',
43
+ 9001: 'German Bundesliga',
44
+ 9003: 'Spanish La Liga',
45
+ 9005: 'UEFA Champions League',
46
+ 9006: 'National Basketball Association',
47
+ };
48
+ return leagueMap[leagueId];
49
+ }),
50
+ }));
51
+
52
+ // Mock bytes32 module
53
+ jest.mock('bytes32', () => {
54
+ return jest.fn((options: { input: string }) => {
55
+ // Simple mock that converts string to a padded format
56
+ const paddedString = options.input.padEnd(32, '\0');
57
+ return paddedString;
58
+ });
59
+ });
60
+
61
+ describe('OpticOdds Utils', () => {
62
+ beforeEach(() => {
63
+ jest.clearAllMocks();
64
+ });
65
+
66
+ describe('formatOpticOddsLeagueName', () => {
67
+ it('should convert spaces to underscores and make lowercase', () => {
68
+ expect(formatOpticOddsLeagueName('English Premier League')).toBe('english_premier_league');
69
+ expect(formatOpticOddsLeagueName('UEFA Champions League')).toBe('uefa_champions_league');
70
+ expect(formatOpticOddsLeagueName('German Bundesliga')).toBe('german_bundesliga');
71
+ });
72
+
73
+ it('should handle empty string', () => {
74
+ expect(formatOpticOddsLeagueName('')).toBe('');
75
+ });
76
+
77
+ it('should handle single words', () => {
78
+ expect(formatOpticOddsLeagueName('NBA')).toBe('nba');
79
+ });
80
+ });
81
+
82
+ describe('mapFromOpticOddsToOvertimeFormat', () => {
83
+ describe('when fixture ID does not contain separator', () => {
84
+ it('should return the fixture ID unchanged', () => {
85
+ const fixtureId = 'simple-fixture-id-123';
86
+ const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
87
+ expect(result).toBe(fixtureId);
88
+ });
89
+
90
+ it('should return numeric fixture ID unchanged', () => {
91
+ const fixtureId = '12345';
92
+ const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
93
+ expect(result).toBe(fixtureId);
94
+ });
95
+ });
96
+
97
+ describe('when fixture ID contains separator and league is mapped', () => {
98
+ it('should convert Premier League fixture ID correctly', () => {
99
+ const leagueName = formatOpticOddsLeagueName('English Premier League');
100
+ const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
101
+ const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
102
+ expect(result).toBe(`9002${OVERTIME_ID_SEPARATOR}12345`);
103
+ });
104
+
105
+ it('should convert Bundesliga fixture ID correctly', () => {
106
+ const leagueName = formatOpticOddsLeagueName('German Bundesliga');
107
+ const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}67890`;
108
+ const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
109
+ expect(result).toBe(`9001${OVERTIME_ID_SEPARATOR}67890`);
110
+ });
111
+
112
+ it('should convert Champions League fixture ID correctly', () => {
113
+ const leagueName = formatOpticOddsLeagueName('UEFA Champions League');
114
+ const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}match-001`;
115
+ const result = mapFromOpticOddsToOvertimeFormat(fixtureId);
116
+ expect(result).toBe(`9005${OVERTIME_ID_SEPARATOR}match-001`);
117
+ });
118
+ });
119
+
120
+ describe('when fixture ID contains separator but league is not mapped', () => {
121
+ it('should throw error for unmapped league name', () => {
122
+ const unmappedLeague = 'unknown_league';
123
+ const fixtureId = `${unmappedLeague}${OPTIC_ODDS_ID_SEPARATOR}12345`;
124
+
125
+ expect(() => {
126
+ mapFromOpticOddsToOvertimeFormat(fixtureId);
127
+ }).toThrow('Optic Odds league unknown_league not mapped.');
128
+ });
129
+
130
+ it('should throw error for empty league name', () => {
131
+ const fixtureId = `${OPTIC_ODDS_ID_SEPARATOR}12345`;
132
+
133
+ expect(() => {
134
+ mapFromOpticOddsToOvertimeFormat(fixtureId);
135
+ }).toThrow('Optic Odds league not mapped.');
136
+ });
137
+ });
138
+ });
139
+
140
+ describe('mapFromOvertimeToOpticOddsFormat', () => {
141
+ describe('when game ID does not contain separator', () => {
142
+ it('should return the game ID unchanged', () => {
143
+ const gameId = 'simple-game-id-123';
144
+ const result = mapFromOvertimeToOpticOddsFormat(gameId);
145
+ expect(result).toBe(gameId);
146
+ });
147
+
148
+ it('should return numeric game ID unchanged', () => {
149
+ const gameId = '12345';
150
+ const result = mapFromOvertimeToOpticOddsFormat(gameId);
151
+ expect(result).toBe(gameId);
152
+ });
153
+ });
154
+
155
+ describe('when game ID contains separator and league is mapped', () => {
156
+ it('should convert Premier League game ID correctly', () => {
157
+ const gameId = `9002${OVERTIME_ID_SEPARATOR}12345`;
158
+ const result = mapFromOvertimeToOpticOddsFormat(gameId);
159
+ const expectedLeagueName = formatOpticOddsLeagueName('English Premier League');
160
+ expect(result).toBe(`${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`);
161
+ });
162
+
163
+ it('should convert Bundesliga game ID correctly', () => {
164
+ const gameId = `9001${OVERTIME_ID_SEPARATOR}67890`;
165
+ const result = mapFromOvertimeToOpticOddsFormat(gameId);
166
+ const expectedLeagueName = formatOpticOddsLeagueName('German Bundesliga');
167
+ expect(result).toBe(`${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}67890`);
168
+ });
169
+
170
+ it('should convert Champions League game ID correctly', () => {
171
+ const gameId = `9005${OVERTIME_ID_SEPARATOR}match-001`;
172
+ const result = mapFromOvertimeToOpticOddsFormat(gameId);
173
+ const expectedLeagueName = formatOpticOddsLeagueName('UEFA Champions League');
174
+ expect(result).toBe(`${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}match-001`);
175
+ });
176
+ });
177
+
178
+ describe('when game ID contains separator but league is not mapped', () => {
179
+ it('should throw error for unmapped league ID', () => {
180
+ const gameId = `9999${OVERTIME_ID_SEPARATOR}12345`;
181
+
182
+ expect(() => {
183
+ mapFromOvertimeToOpticOddsFormat(gameId);
184
+ }).toThrow('Overtime league ID 9999 not mapped.');
185
+ });
186
+
187
+ it('should throw error for invalid league ID', () => {
188
+ const gameId = `invalid${OVERTIME_ID_SEPARATOR}12345`;
189
+
190
+ expect(() => {
191
+ mapFromOvertimeToOpticOddsFormat(gameId);
192
+ }).toThrow('Overtime league ID invalid not mapped.');
193
+ });
194
+ });
195
+ });
196
+
197
+ describe('convertFromBytes32', () => {
198
+ it('should remove null characters from bytes32 string', () => {
199
+ const input = 'test\0\0\0\0';
200
+ const result = convertFromBytes32(input);
201
+ expect(result).toBe('test');
202
+ });
203
+
204
+ it('should handle string without null characters', () => {
205
+ const input = 'teststring';
206
+ const result = convertFromBytes32(input);
207
+ expect(result).toBe('teststring');
208
+ });
209
+
210
+ it('should handle empty string', () => {
211
+ const input = '';
212
+ const result = convertFromBytes32(input);
213
+ expect(result).toBe('');
214
+ });
215
+ });
216
+
217
+ describe('mapFromOpticOddsFormatToBytes32', () => {
218
+ it('should convert optic odds format to bytes32', () => {
219
+ const leagueName = formatOpticOddsLeagueName('English Premier League');
220
+ const fixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
221
+ const result = mapFromOpticOddsFormatToBytes32(fixtureId);
222
+
223
+ // Should first convert to overtime format, then to bytes32
224
+ const expectedOvertimeFormat = `9002${OVERTIME_ID_SEPARATOR}12345`;
225
+ const expectedBytes32 = expectedOvertimeFormat.padEnd(32, '\0');
226
+ expect(result).toBe(expectedBytes32);
227
+ });
228
+
229
+ it('should handle fixture ID without separator', () => {
230
+ const fixtureId = '12345';
231
+ const result = mapFromOpticOddsFormatToBytes32(fixtureId);
232
+
233
+ const expectedBytes32 = fixtureId.padEnd(32, '\0');
234
+ expect(result).toBe(expectedBytes32);
235
+ });
236
+ });
237
+
238
+ describe('mapFromBytes32ToOpticOddsFormat', () => {
239
+ it('should convert bytes32 to optic odds format', () => {
240
+ const overtimeFormat = `9002${OVERTIME_ID_SEPARATOR}12345`;
241
+ const bytes32Input = overtimeFormat.padEnd(32, '\0');
242
+ const result = mapFromBytes32ToOpticOddsFormat(bytes32Input);
243
+
244
+ const expectedLeagueName = formatOpticOddsLeagueName('English Premier League');
245
+ const expectedResult = `${expectedLeagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
246
+ expect(result).toBe(expectedResult);
247
+ });
248
+
249
+ it('should handle bytes32 without separator', () => {
250
+ const gameId = '12345';
251
+ const bytes32Input = gameId.padEnd(32, '\0');
252
+ const result = mapFromBytes32ToOpticOddsFormat(bytes32Input);
253
+
254
+ expect(result).toBe(gameId);
255
+ });
256
+ });
257
+
258
+ describe('integration tests', () => {
259
+ it('should convert from optic odds to bytes32 and back', () => {
260
+ const leagueName = formatOpticOddsLeagueName('English Premier League');
261
+ const originalFixtureId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}12345`;
262
+
263
+ // Convert to bytes32
264
+ const bytes32Result = mapFromOpticOddsFormatToBytes32(originalFixtureId);
265
+
266
+ // Convert back to optic odds format
267
+ const backToOpticOdds = mapFromBytes32ToOpticOddsFormat(bytes32Result);
268
+
269
+ expect(backToOpticOdds).toBe(originalFixtureId);
270
+ });
271
+
272
+ it('should convert between optic odds and overtime formats', () => {
273
+ const leagueName = formatOpticOddsLeagueName('German Bundesliga');
274
+ const opticOddsId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}67890`;
275
+
276
+ // Convert to overtime format
277
+ const overtimeFormat = mapFromOpticOddsToOvertimeFormat(opticOddsId);
278
+ expect(overtimeFormat).toBe(`9001${OVERTIME_ID_SEPARATOR}67890`);
279
+
280
+ // Convert back to optic odds format
281
+ const backToOpticOdds = mapFromOvertimeToOpticOddsFormat(overtimeFormat);
282
+ expect(backToOpticOdds).toBe(opticOddsId);
283
+ });
284
+
285
+ it('should handle round trip conversion with NBA league', () => {
286
+ const leagueName = formatOpticOddsLeagueName('National Basketball Association');
287
+ const originalId = `${leagueName}${OPTIC_ODDS_ID_SEPARATOR}game-456`;
288
+
289
+ // Optic Odds -> Overtime -> Optic Odds
290
+ const overtimeFormat = mapFromOpticOddsToOvertimeFormat(originalId);
291
+ const backToOpticOdds = mapFromOvertimeToOpticOddsFormat(overtimeFormat);
292
+
293
+ expect(backToOpticOdds).toBe(originalId);
294
+ });
295
+ });
296
+ });
@@ -1,6 +1,6 @@
1
1
  import bytes32 from 'bytes32';
2
+ import { getLeagueOpticOddsName, LeagueMap } from 'overtime-utils';
2
3
  import { OPTIC_ODDS_ID_SEPARATOR, OVERTIME_ID_SEPARATOR } from '../constants/common';
3
- import { LeagueIdMapOpticOdds } from '../constants/sports';
4
4
  import { Fixture, OddsObject, ScoresObject } from '../types/odds';
5
5
 
6
6
  export const mapOpticOddsApiFixtures = (fixturesData: any[]): Fixture[] =>
@@ -85,9 +85,9 @@ export const mapFromOpticOddsToOvertimeFormat = (fixtureId: string) => {
85
85
  return fixtureId;
86
86
  }
87
87
  const [leagueName, id] = fixtureId.split(OPTIC_ODDS_ID_SEPARATOR);
88
- const overtimeLeagueId = Object.keys(LeagueIdMapOpticOdds).find(
89
- (key) => formatOpticOddsLeagueName(LeagueIdMapOpticOdds[Number(key)]) === leagueName
90
- );
88
+ const overtimeLeagueId = Object.values(LeagueMap).find(
89
+ (league) => formatOpticOddsLeagueName(league.opticOddsName || '') === leagueName
90
+ )?.id;
91
91
  if (!overtimeLeagueId) {
92
92
  throw `Optic Odds league ${leagueName} not mapped.`;
93
93
  }
@@ -99,7 +99,7 @@ export const mapFromOvertimeToOpticOddsFormat = (gameId: string) => {
99
99
  return gameId;
100
100
  }
101
101
  const [leagueId, id] = gameId.split(OVERTIME_ID_SEPARATOR);
102
- const opticOddsLeagueName = LeagueIdMapOpticOdds[Number(leagueId)];
102
+ const opticOddsLeagueName = getLeagueOpticOddsName(Number(leagueId));
103
103
  if (!opticOddsLeagueName) {
104
104
  throw `Overtime league ID ${leagueId} not mapped.`;
105
105
  }