SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
3.8 KB · 54 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { readFileSync } from 'node:fs';3import path from 'node:path';4import { fileURLToPath } from 'node:url';5import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';6import { localMeta } from '../../api/_lib/local-meta.js';7import createConnector, { parseGallery } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const meta = localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8')));11const connector = createConnector(meta);1213const PAGE = `<html><body>14<div class="sidebar-widget"><h5 class="title"><span class="closed">&bull;</span> 2026 Summer Classic </h5><p> Start: 7/26/2026 12:00 PM EST <br> End: 8/15/2026 10:00 PM EST </p><p><span style="color:red;">Prices Shown Include Buyer's Premium.</span></p></div>15<select name="ctl00$Auction"><option value="-1">All Auctions</option><option selected="selected" value="1008">2026 Summer Classic</option><option value="1005">2026 Spring Classic</option></select>16<div class="item"><h5 class="boxed">1</h5><div class="item-details clearfix"><p class="description"><a href="https://auction.lelands.com/bids/bidplace.aspx?itemid=135734">Late 1930s Lou Gehrig Single-Signed Baseball (PSA)</a></p><div class="item-image"><a href="#"><img src="https://auction.lelands.com/images_items/thumbs/thumb_item_135734_1.jpg"/></a></div><p> Bids: <strong>49</strong> <br> Opening Bid: <strong>$5,000</strong> <br> Status: <strong>Sold</strong> </p></div><div class="item-price"><a href="#">SOLD FOR $92,050</a></div></div>17<div class="item"><h5 class="boxed">2</h5><div class="item-details clearfix"><p class="description"><a href="https://auction.lelands.com/bids/bidplace.aspx?itemid=135794">Signed 1949 Bowman Baseball #82 Joe Page Card (PSA)</a></p><p> Bids: <strong>0</strong> <br> Opening Bid: <strong>$300</strong> <br> Status: <strong>Unsold</strong> </p></div><div class="item-price"></div></div>18<ul class="pagination pagination-sm"><li class="active"><a href="?size=250&page=1">1</a></li><li><a href="?size=250&page=2">2</a></li><li><a href="?size=250&page=5">5</a></li></ul>19</body></html>`;2021describe('lelands', () => {22  runFixtureSuite(connector, it, expect);2324  it('parses the gallery: auction dates, premium note, items and pagination', () => {25    const p = parseGallery(PAGE, 1);26    expect(p.auction.id).toBe('1008');27    expect(p.auction.name).toContain('2026 Summer Classic');28    expect(p.auction.endText).toBe('8/15/2026 10:00 PM EST');29    expect(p.auction.premiumIncluded).toBe(true);30    expect(p.totalPages).toBe(5);31    expect(p.items[0]).toMatchObject({ itemId: '135734', bids: 49, openingBid: 5000, status: 'Sold', soldPrice: 92050, lotNumber: '1' });32    expect(p.items[1]!.soldPrice).toBeNull();33  });3435  it('normalises sold lots dated by the auction end with premium included', async () => {36    const out = await connector.normalize({ url: 'x', externalId: 'a', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: parseGallery(PAGE, 1) });37    expect(out.length).toBe(1);38    const s = out[0]!;39    if (s.kind !== 'sale') throw new Error('sale');40    expect(s).toMatchObject({ price: 92050, currency: 'USD', buyerPremiumIncluded: true, auctionHouse: 'Lelands', lotNumber: '1' });41    expect(s.saleDate.toISOString()).toBe('2026-08-15T00:00:00.000Z');42    expect(s.attributes.categorySlug).toBe('sports_memorabilia');43  });4445  it('emits nothing while the displayed auction is still open', async () => {46    const future = PAGE.replace('End: 8/15/2026', 'End: 8/15/2099');47    expect(await connector.normalize({ url: 'x', externalId: 'a', kind: 'sale', engine: 'firecrawl', fetchedAt: new Date(), payload: parseGallery(future, 1) })).toEqual([]);48  });4950  it('fixture normalises', async () => {51    expect((await connector.normalize(loadFixture('lelands', 'gallery-page').raw)).length).toBeGreaterThan(0);52  });53});54