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%
2.7 KB · 55 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import metaJson from './meta.json' with { type: 'json' };3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import { localMeta } from '../_lib/local-meta.js';5import { conditionFromParens, normalizeConditionWord } from '../_g10-lib/index.js';6import createConnector, { pageUrl, parseCategoryHtml, parsePenTitle } from './index.js';78const connector = createConnector(localMeta(metaJson));910describe('peyton-street-pens', () => {11  runFixtureSuite(connector, it, expect);1213  it('parses BigCommerce product cards and pagination', () => {14    const html = String((loadFixture('peyton-street-pens', 'parker-p1').raw.payload as { snapshot?: string }).snapshot ?? '');15    const p = parseCategoryHtml(html);16    expect(p.cards.length).toBeGreaterThanOrEqual(2);17    const c = p.cards[0]!;18    expect(c.url).toMatch(/^https:\/\/www\.peytonstreetpens\.com\/.+\.html$/);19    expect(c.sku).toMatch(/^\d+/);20    expect(c.price).toBeGreaterThan(0);21    expect(c.image).toMatch(/cdn11\.bigcommerce\.com/);22    expect(p.totalPages).toBeGreaterThan(1);23    expect(pageUrl('/pens-by-brand/parker/', 2)).toBe('https://www.peytonstreetpens.com/pens-by-brand/parker/?page=2');24  });2526  it('parses pen titles, conditions and eras', () => {27    const t = parsePenTitle('Sheaffer Craftsman Fountain Pen & Pencil Set (1950s) - Burgundy w/GT, Touchdown, Fine 14k #33 Nib (Near Mint, Restored)', 'PEN SET');28    expect(t.brand).toBe('Sheaffer');29    expect(t.model).toBe('Craftsman');30    expect(t.penType).toBe('fountain pen');31    expect(t.variant).toMatch(/^Burgundy w\/GT/);32    const cond = conditionFromParens('Parker 51 Aerometric Fountain Pen (1950s) - Black w/Lustraloy Cap, Fine (Excellent, Works Well)');33    expect(cond).toBe('Excellent, Works Well');34    expect(normalizeConditionWord(cond)).toBe('excellent');35    expect(normalizeConditionWord('Near Mint, Restored')).toBe('near_mint');36    const m = parsePenTitle('Montblanc Meisterstuck 149 Fountain Pen - Black w/GT, Medium 18k Nib (Excellent, Works Well)', 'MONTBLANC');37    expect(m.brand).toBe('Montblanc');38    expect(m.model).toBe('Meisterstuck 149');39  });4041  it('normalises cards into USD dealer listings (pens only, accessories skipped)', async () => {42    const fx = loadFixture('peyton-street-pens', 'parker-p1');43    const out = await connector.normalize(fx.raw);44    expect(out.length).toBeGreaterThan(0);45    for (const r of out) {46      if (r.kind !== 'listing') throw new Error('expected listing');47      expect(r.currency).toBe('USD');48      expect(r.price).toBeGreaterThan(0);49      expect(['pens', 'lighters']).toContain(r.attributes.categorySlug);50      expect(r.seller).toBe('Peyton Street Pens');51      expect(r.attributes.brand).toBeTruthy();52    }53  });54});55