// Self-test: calls the live API and checks the shape of the answer. Run: node test.mjs import { pathToFileURL } from "node:url"; import { trends } from "./scripts/trends.mjs"; export default async function test() { const r = await trends({ limit: 5 }); const checks = []; const check = (name, ok) => checks.push({ name, ok: Boolean(ok) }); check("returns a token list", Array.isArray(r.tokens)); check("list is not empty", r.tokens.length > 0); check("respects the limit", r.tokens.length <= 5); check("every token has chain and address", r.tokens.every((t) => t.chainId && t.address)); check("ranks start at 1", r.tokens[0]?.rank === 1); check("at least one token has a live price", r.tokens.some((t) => typeof t.priceUsd === "number" && t.priceUsd > 0)); return { ok: checks.every((c) => c.ok), checks }; } if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { test().then((r) => { console.log(JSON.stringify(r, null, 2)); process.exit(r.ok ? 0 : 1); }, (e) => { console.log(JSON.stringify({ ok: false, error: String(e?.message ?? e) })); process.exit(1); }); }