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%
1.8 KB · 41 lines typescript
Raw Blame History
1import { describe, expect, it } from 'vitest';2import { parseQuery, toTsQuery } from './parse.js';34describe('parseQuery', () => {5  it('extracts grade, year and category', () => {6    const q = parseQuery('1999 Charizard PSA 10');7    expect(q.grader).toBe('psa');8    expect(q.grade).toBe('10');9    expect(q.year).toBe(1999);10    expect(q.text).toContain('Charizard');11    expect(q.text.toLowerCase()).not.toContain('psa');12  });13  it('extracts price bounds', () => {14    expect(parseQuery('Rolex Daytona under $20,000')).toMatchObject({ priceMax: 20000, currency: 'USD', categorySlugs: ['rolex'] });15    expect(parseQuery('pokemon cards between $500 and $1,000')).toMatchObject({ priceMin: 500, priceMax: 1000 });16    expect(parseQuery('lego over 2k')).toMatchObject({ priceMin: 2000 });17    expect(parseQuery('Rolex Daytona under $20,000').text.toLowerCase()).not.toContain('under');18  });19  it('detects conditions and editions', () => {20    const q = parseQuery('sealed Mario 64');21    expect(q.conditions).toContain('sealed');22    expect(q.categorySlugs).toContain('nintendo_games');23    const h = parseQuery('first edition Harry Potter UK');24    expect(h.editions).toContain('1st edition');25    expect(h.categorySlugs).toContain('harry_potter');26    expect(parseQuery('Michael Jordan rookie PSA 10').editions).toContain('rookie');27    expect(parseQuery('LEGO Millennium Falcon retired').categorySlugs).toContain('lego');28  });29  it('does not invent filters', () => {30    const q = parseQuery('Charizard');31    expect(q.grader).toBeNull();32    expect(q.priceMax).toBeNull();33    expect(q.year).toBeNull();34  });35  it('builds tsquery', () => {36    expect(toTsQuery('Charizard 4/102')).toBe('charizard:* & 4/102:*');37    expect(toTsQuery('')).toBeNull();38    expect(toTsQuery("o'neal")).toBe('oneal:*');39  });40});41