'use strict'; /** * Markets (plan §L.1): the search over Deals (each price "as of" its time, its store and source, a was-price, "Can I * afford it?" to Finance), the marketplaces opened with the words filled in (new tab, nothing fetched), Deals down or * empty said plainly with the links still there, the JSON API, the home page, noindex on searches, robots and llms.txt. */ const assert = require('assert'); const http = require('node:http'); const { createApp } = require('../server/app'); const { createDeals } = require('../server/deals'); const { linksFor, PLACES } = require('../server/elsewhere'); const NOW = Date.parse('2026-11-18T12:00:00Z'); const OFFERS = [ { title: 'Noise cancelling headphones, over-ear', url: 'https://openvibe.deals/d/nc-1', latest_observation: { observed_at: '2026-11-18T09:00:00Z', currency: 'USD', condition: 'new' }, feed: { price: { amount: 149.99, currency: 'USD' }, was: 199.99, store: 'Shop Example', media: { thumb: 'https://img.example/nc.jpg' } } }, { title: 'Refurbished studio headphones', url: 'https://openvibe.deals/d/st-2', latest_observation: { observed_at: '2026-11-10T09:00:00Z', currency: 'USD', condition: 'refurbished' }, feed: { price: { amount: 59, currency: 'USD' }, store: 'Refurb Co' } }, { title: 'A deal with no price', url: 'https://openvibe.deals/d/np-3', latest_observation: null, feed: { price: null, store: null } }, { title: 'Not a safe link', url: 'javascript:alert(1)', feed: {} }, ]; (async () => { // A stand-in Deals: /api/v1/search answers OFFERS for "headphones", nothing for anything else; "boom" is a 500. let asked = []; const fake = http.createServer((req, res) => { const u = new URL(req.url, 'http://x'); asked.push(u.pathname + u.search); const q = u.searchParams.get('q'); if (u.pathname !== '/api/v1/search') { res.writeHead(404); return res.end(); } if (q === 'boom') { res.writeHead(500, { 'content-type': 'application/json' }); return res.end('{}'); } const offers = q === 'headphones' ? OFFERS : []; res.writeHead(200, { 'content-type': 'application/json' }); res.end(JSON.stringify({ q, total: q === 'headphones' ? 31 : 0, offers })); }); await new Promise((r) => fake.listen(0, '127.0.0.1', r)); const deals = createDeals({ baseUrl: `http://127.0.0.1:${fake.address().port}` }); const server = createApp({ deals, now: () => NOW }).listen(0, '127.0.0.1'); await new Promise((r) => server.once('listening', r)); const base = `http://127.0.0.1:${server.address().port}`; const get = (p) => fetch(base + p, { redirect: 'manual' }).then(async (r) => ({ status: r.status, headers: r.headers, location: r.headers.get('location'), text: await r.text() })); try { // The marketplaces, with the words in, encoded. const links = linksFor('used road bike & helmet'); assert.ok(PLACES.length >= 12, 'at least ten ways in besides Deals'); assert.strictEqual(links.find((l) => l.id === 'ebay').url, 'https://www.ebay.com/sch/i.html?_nkw=used%20road%20bike%20%26%20helmet'); assert.ok(links.every((l) => /^https:\/\//.test(l.url) && l.url.includes('used%20road%20bike'))); let r = await get('/'); assert.strictEqual(r.status, 200); assert.match(r.text, /Every marketplace, one search/); assert.match(r.text, /