diff --git a/assets/js/map_helpers.ts b/assets/js/map_helpers.ts index 1c690a0..caf1950 100644 --- a/assets/js/map_helpers.ts +++ b/assets/js/map_helpers.ts @@ -34,7 +34,7 @@ export function parseTimestamp(timestamp: string | number | Date | undefined): n /** * Get trail ID from marker data */ -export function getTrailId(data: { callsign_group?: string; callsign?: string; id: string }): string { +export function getTrailId(data: { callsign_group?: string; callsign?: string; id: string | number }): string { // Prioritize callsign_group and callsign over extracting from ID if (data.callsign_group) { return data.callsign_group; @@ -53,8 +53,8 @@ export function getTrailId(data: { callsign_group?: string; callsign?: string; i return withoutPrefix.replace(/_\d+$/, ""); } - // For regular IDs, return as-is - return data.id; + // For regular IDs, return as string + return String(data.id); } /** diff --git a/test/assets/js/map_helpers_test.ts b/test/assets/js/map_helpers_test.ts index 72e2a78..6181248 100644 --- a/test/assets/js/map_helpers_test.ts +++ b/test/assets/js/map_helpers_test.ts @@ -92,6 +92,20 @@ describe('map_helpers', () => { }; expect(getTrailId(data)).toBe('REALCALL'); }); + + test('handles numeric ID', () => { + const data = { + id: 12345 + }; + expect(getTrailId(data)).toBe('12345'); + }); + + test('handles numeric historical ID', () => { + const data = { + id: 'hist_MYCALL_12345' + }; + expect(getTrailId(data)).toBe('MYCALL'); + }); }); describe('saveMapState', () => {