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%
5.3 KB · 61 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 '../_lib/local-meta.js';7import createConnector, { closedDate, kelleherCategory, parseCategoryPage, parseFirmPage, parseGroupLinks } from './index.js';89const dir = path.dirname(fileURLToPath(import.meta.url));10const connector = createConnector(localMeta(JSON.parse(readFileSync(path.join(dir, 'meta.json'), 'utf8'))));1112const FIRM = `<li><strong>Daniel F. Kelleher Auctions, LLC - Sale 5337</strong></font> <A HREF="https://StampAuctionNetwork.com/cCatalog.cfm?SrchFirm=V&SrchSale=5337"> US, British and Worldwide Stamps and Postal History - August 30, 2026 </A>13<A NAME = "PricesRealized"></a> <li> Daniel F. Kelleher Auctions, LLC <A HREF="https://StampAuctionNetwork.com/cCatalog.cfm?SrchFirm=V&SrchSale=5303"> US, British and Worldwide Stamps and Postal History - December 28, 2025 </A> <li> Daniel F. Kelleher Auctions, LLC <A HREF="https://StampAuctionNetwork.com/V/V830.cfm"> US & Worldwide Coins & Banknotes - December 22, 2025 </A>`;14const GROUPS = `<a href="cCatalog2.cfm?MAJGROUP=United%20States&SrchFirm=V&SrchSale=5303">US</a><a href="cCatalog2.cfm?MAJGROUP=United%20States&SrchFirm=V&SrchSale=5303">dup</a>`;15const CATS = `<a href="https://StampAuctionNetwork.com/cCatalog3.cfm?MAJGROUP=United%20States&CATDESCR=1847%20Issue&SrchFirm=V&SrchSale=5303">1847</a>`;16const PAGE = `<table id="CatTable" BORDER=1><tr><td><strong><font size="+1"> Sale No: 5303 <br>Lot No: 9001 <br>Symbol: Z <br>Cat No: 1 <P> </font></strong></td><td valign="TOP" width="65%" bgcolor="EEEEEE" align="left"> <A HREF="https://StampAuctionNetwork.com/Photos/V/5303/9001.jpg" target="_blank" class="MagicZoomPlus"> <IMG ALIGN=LEFT SRC="https://StampAuctionNetwork.com/Photos/V/5303/9001.jpg" alt="image" width="150p"> </a> <B>1847, 5&cent; red brown (Scott 1),</B> red cancel; creased along 2 crossed letter folds, Fine.<BR>Scott $425. <A HREF="https://StampAuctionNetwork.com/Photos/V/5303/9001.jpg" target="_blank"> <b>(Image)</b></a> <P>Suggested Bid $62 </td><td align="right"> Opening US$ 74.00 <br>Sold...US$ 74.00 <BR><BR> <br>Closed..Dec-28-2025, 21:00:00 EST <br>Sold For 74 </td></tr></table>17<table id="CatTable" BORDER=1><tr><td><strong><font size="+1"> Sale No: 5303 <br>Lot No: 9002 <br>Cat No: 2 </font></strong></td><td valign="TOP" width="65%" bgcolor="EEEEEE" align="left"> <B>1847, 10&cent; black (Scott 2),</B> used, fine. </td><td align="right"> Opening US$ 300.00 <br>Unsold <BR><br>Closed..Dec-28-2025, 21:00:00 EST </td></tr></table>`;1819describe('kelleher', () => {20  runFixtureSuite(connector, it, expect);2122  it('discovers only cCatalog sales after the PricesRealized anchor', () => {23    const sales = parseFirmPage(FIRM);24    expect(sales).toEqual([{ sale: '5303', title: 'US, British and Worldwide Stamps and Postal History', dateText: 'December 28, 2025', url: 'https://StampAuctionNetwork.com/cCatalog.cfm?SrchFirm=V&SrchSale=5303' }]);25    expect(parseGroupLinks(GROUPS, 2)).toEqual(['https://StampAuctionNetwork.com/cCatalog2.cfm?MAJGROUP=United%20States&SrchFirm=V&SrchSale=5303']);26    expect(parseGroupLinks(CATS, 3).length).toBe(1);27  });2829  it('parses lot tables and normalises sold lots as hammer prices dated by Closed', async () => {30    const sale = parseFirmPage(FIRM)[0]!;31    const url = 'https://StampAuctionNetwork.com/cCatalog3.cfm?MAJGROUP=United%20States&CATDESCR=1847%20Issue&SrchFirm=V&SrchSale=5303';32    const p = parseCategoryPage(PAGE, sale, url);33    expect(p.majorGroup).toBe('United States');34    expect(p.category).toBe('1847 Issue');35    expect(p.lots.length).toBe(2);36    expect(p.lots[0]).toMatchObject({ lotNumber: '9001', catNo: '1', headline: '1847, 5¢ red brown (Scott 1),', soldText: 'US$ 74.00', closedText: 'Dec-28-2025', soldFor: '74', image: 'https://StampAuctionNetwork.com/Photos/V/5303/9001.jpg' });37    expect(p.lots[1]!.soldFor).toBeNull();38    const out = await connector.normalize({ url, externalId: 'a', kind: 'sale', engine: 'api', fetchedAt: new Date('2026-09-07T00:00:00Z'), payload: p });39    expect(out.length).toBe(1);40    const s = out[0]!;41    if (s.kind !== 'sale') throw new Error('sale');42    expect(s).toMatchObject({ price: 74, currency: 'USD', buyerPremiumIncluded: false, lotNumber: '9001', auctionHouse: 'Daniel F. Kelleher Auctions' });43    expect(s.saleDate.toISOString()).toBe('2025-12-28T00:00:00.000Z');44    expect(s.attributes).toMatchObject({ categorySlug: 'stamps', set: '1847 Issue', country: 'United States', year: 1847 });45    expect(s.attributes.identifiers.san_lot).toBe('V-5303-9001');46  });4748  it('helpers', () => {49    expect(closedDate('Dec-28-2025')?.toISOString()).toBe('2025-12-28T00:00:00.000Z');50    expect(kelleherCategory('United States', '1847 5c red brown')).toBe('stamps');51    expect(kelleherCategory('Coins', '1921 Morgan dollar')).toBe('coins');52    expect(kelleherCategory('Paper Money', '$5 legal tender note')).toBe('banknotes');53  });5455  it('fixture lots normalise to USD hammer sales', async () => {56    const out = await connector.normalize(loadFixture('kelleher', 'category-page').raw);57    expect(out.length).toBeGreaterThan(0);58    for (const r of out) if (r.kind === 'sale') expect(r).toMatchObject({ currency: 'USD', buyerPremiumIncluded: false });59  });60});61