import assert from 'node:assert/strict'; import test from 'node:test'; import { getPublicListing } from '../src/services/catalog-service.js'; test('fetches a public listing detail through the API service', async () => { const originalFetch = globalThis.fetch; globalThis.fetch = async (url) => { assert.equal(url, 'http://localhost:3000/api/v1/public/listings/listing-1'); return { ok: true, async json() { return { data: { id: 'listing-1' } }; } }; }; try { assert.deepEqual(await getPublicListing('listing-1'), { id: 'listing-1' }); } finally { globalThis.fetch = originalFetch; } }); test('encodes catalog search pagination in the API request', async () => { const originalFetch = globalThis.fetch; globalThis.fetch = async (url) => { assert.equal(url, 'http://localhost:3000/api/v1/public/search?query=card+set&page=3&limit=20'); return { ok: true, async json() { return { data: { items: [], pagination: {} } }; } }; }; try { const { searchCatalog } = await import('../src/services/catalog-service.js'); await searchCatalog({ query: 'card set', page: 3 }); } finally { globalThis.fetch = originalFetch; } }); test('fetches a public product using its stable slug URL', async () => { const originalFetch = globalThis.fetch; globalThis.fetch = async (url) => { assert.equal(url, 'http://localhost:3000/api/v1/public/products/pikachu-plush'); return { ok: true, async json() { return { data: { slug: 'pikachu-plush' } }; } }; }; try { const { getPublicProduct } = await import('../src/services/catalog-service.js'); assert.deepEqual(await getPublicProduct('pikachu-plush'), { slug: 'pikachu-plush' }); } finally { globalThis.fetch = originalFetch; } });