deckhearth/test/lib/pricing/overpass.test.js
Randall Stillwell d0468015eb
Some checks failed
CI / Lint (pull_request) Has been cancelled
CI / Schema map up to date (pull_request) Has been cancelled
CI / Forbidden patterns (9 checks) (pull_request) Has been cancelled
CI / Migrations apply (node-pg-migrate) (pull_request) Has been cancelled
Visual diff / Should run? (pull_request) Has been cancelled
CI / Unit tests (vitest) (pull_request) Has been cancelled
Convoy metrics gate / Require role-event telemetry on convoy PRs (pull_request) Has been cancelled
PR Health rollup / Aggregate gate status (pull_request) Has been cancelled
Preview smoke / Should run? (pull_request) Has been cancelled
Preview smoke / Playwright smoke (pull_request) Has been cancelled
Visual diff / Screenshot diff (pull_request) Has been cancelled
feat(pricing): convoy for online prices and local stores
Add pricing schema, free API integrations (MTG bulk, TCGdex, Foolio),
valuation and sort-by-price, card detail pricing UI, and nearby store
discovery via home zip and OSM geo clients.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 22:47:46 -05:00

64 lines
1.8 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import {
buildOverpassQuery,
clampRadiusMiles,
milesToMeters,
parseOverpassResponse,
} from '../../../lib/pricing/overpass.js';
describe('overpass', () => {
it('clamps radius miles between 1 and 50', () => {
expect(clampRadiusMiles(0)).toBe(1);
expect(clampRadiusMiles(100)).toBe(50);
expect(clampRadiusMiles(25)).toBe(25);
});
it('builds fixed-template query with numeric injection only', () => {
const query = buildOverpassQuery({ lat: 40.1, lng: -74.2, radiusMeters: 16093 });
expect(query).toContain('around:16093,40.1,-74.2');
expect(query).toContain('shop"="games"');
expect(query).toContain('shop"="hobby"');
expect(query).not.toContain('; DROP');
});
it('parses elements with distance-ready coordinates', () => {
const stores = parseOverpassResponse(
{
elements: [
{
type: 'node',
id: 42,
lat: 40.11,
lon: -74.21,
tags: {
name: 'Game Haven',
'addr:street': 'Main St',
'addr:city': 'Town',
phone: '555-0100',
website: 'https://example.com',
},
},
],
},
{ originLat: 40.1, originLng: -74.2 }
);
expect(stores).toHaveLength(1);
expect(stores[0]).toMatchObject({
name: 'Game Haven',
lat: 40.11,
lng: -74.21,
phone: '555-0100',
website: 'https://example.com',
osmUrl: 'https://www.openstreetmap.org/node/42',
});
expect(stores[0].distanceMiles).toBeGreaterThan(0);
expect(stores[0].address).toContain('Main St');
});
it('converts miles to meters with clamping', () => {
expect(milesToMeters(25)).toBe(Math.round(25 * 1609.344));
expect(milesToMeters(0)).toBe(Math.round(1 * 1609.344));
});
});