deckhearth/test/lib/pricing/geo-cache.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

31 lines
1,013 B
JavaScript

import { describe, expect, it } from 'vitest';
import {
STORES_CACHE_TTL_MS,
buildStoresCacheKey,
isStoresCacheFresh,
} from '../../../lib/pricing/geo-cache.js';
describe('geo-cache', () => {
it('builds stable cache keys for the same coordinates', () => {
const a = buildStoresCacheKey(40.12345, -74.98765, 16093);
const b = buildStoresCacheKey(40.12345, -74.98765, 16093);
expect(a).toBe(b);
expect(a.length).toBeLessThanOrEqual(64);
});
it('treats fresh cache entries as valid within TTL', () => {
const fetchedAt = new Date(Date.now() - STORES_CACHE_TTL_MS + 1000);
expect(isStoresCacheFresh(fetchedAt)).toBe(true);
});
it('expires cache entries after TTL', () => {
const fetchedAt = new Date(Date.now() - STORES_CACHE_TTL_MS - 1);
expect(isStoresCacheFresh(fetchedAt)).toBe(false);
});
it('rejects invalid fetched_at values', () => {
expect(isStoresCacheFresh(null)).toBe(false);
expect(isStoresCacheFresh('not-a-date')).toBe(false);
});
});