TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { describe, expect, it } from 'vitest';2import { getConnectorMeta } from '@rareindex/connectors';3import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';4import createConnector, { brandCategory, parseBrowsePage } from './index.js';56const connector = createConnector(getConnectorMeta('novelship'));78describe('novelship', () => {9 runFixtureSuite(connector, it, expect);1011 it('maps browse products to catalog + last sale + lowest ask', async () => {12 const fx = loadFixture('novelship', 'jordan-browse-page1');13 const out = await connector.normalize(fx.raw);14 const cats = out.filter((r) => r.kind === 'catalog_item');15 expect(cats.length).toBeGreaterThanOrEqual(30);16 for (const c of cats) {17 if (c.kind !== 'catalog_item') throw new Error();18 expect(c.attributes.categorySlug).toBe('nike_jordan');19 expect(c.attributes.identifiers.style_code).toMatch(/^[A-Z0-9][A-Z0-9\/ -]{3,}$/i);20 expect(c.sourceUrl).toMatch(/^https:\/\/novelship\.com\/[a-z0-9-]+$/);21 }22 const sales = out.filter((r) => r.kind === 'price_observation' && r.priceKind === 'last_sale_reported');23 const asks = out.filter((r) => r.kind === 'listing' && r.listingType === 'ask');24 expect(sales.length).toBeGreaterThan(10);25 expect(asks.length).toBeGreaterThan(10);26 for (const s of sales) if (s.kind === 'price_observation') expect(s.currency).toBe('USD');27 });2829 it('parses a product page and keeps only that product on lookup', async () => {30 const fx = loadFixture('novelship', 'aj1-low-midnight-navy-product');31 const out = await connector.normalize(fx.raw);32 const cat = out.find((r) => r.kind === 'catalog_item');33 if (cat?.kind !== 'catalog_item') throw new Error();34 expect(cat.attributes.identifiers.style_code).toBe('553558-404');35 expect(cat.attributes.color).toContain('Midnight Navy');36 expect(cat.attributes.originalMsrp).toBe(120);37 });3839 it('helpers', () => {40 expect(brandCategory('Jordan', 'Air Jordan 1')).toBe('nike_jordan');41 expect(brandCategory('adidas', 'Yeezy Boost 350')).toBe('adidas_yeezy');42 expect(brandCategory('New Balance', '550')).toBe('new_balance_asics_other');43 const html = `x {"cost_retail":100,"drop_date":"2024-01-02","id":7,"image":"https://i/x.jpg","last_sale_price":150.5,"lowest_listing_price":"120.000000","main_brand":"Nike","name":"Nike Dunk Low Panda DD1391-100","name_slug":"nike-dunk-low-panda-dd1391-100","sales_count_180":12,"sku":"DD1391-100","sub_brand":""} y`;44 const p = parseBrowsePage(html, 'u', 'nike', 1);45 expect(p.products).toHaveLength(1);46 expect(p.products[0]).toMatchObject({ id: 7, sku: 'DD1391-100', lastSalePrice: 150.5, lowestListingPrice: 120, costRetail: 100, salesCount180: 12, mainBrand: 'Nike' });47 });48});49