import { describe, expect, it } from 'vitest'; import metaJson from './meta.json' with { type: 'json' }; import { loadFixture, runFixtureSuite } from '@rareindex/connectors/testing'; import { localMeta } from '../_lib/local-meta.js'; import createConnector, { trimEdition } from './index.js'; const connector = createConnector(localMeta(metaJson)); describe('openlibrary', () => { runFixtureSuite(connector, it, expect); it('emits a catalog item with isbn + Open Library ids', async () => { const e = trimEdition({ key: '/books/OL1M', title: 'T', publishers: ['P'], publish_date: '1997', isbn_10: ['0747532699'], works: [{ key: '/works/OL2W' }], covers: [1, -1] }); expect(e).toMatchObject({ key: '/books/OL1M', publishers: ['P'], isbn10: ['0747532699'], workKey: '/works/OL2W', covers: [1] }); const fx = loadFixture('openlibrary', 'hp-philosophers-stone'); const out = await connector.normalize(fx.raw); expect(out).toHaveLength(1); const c = out[0]!; if (c.kind !== 'catalog_item') throw new Error('expected catalog_item'); expect(c.attributes).toMatchObject({ categorySlug: 'books', brand: 'J. K. Rowling', year: 1997 }); expect(c.attributes.identifiers.isbn).toBeTruthy(); expect(c.attributes.identifiers.openlibrary_id).toMatch(/^OL\d+M$/); expect(c.sourceUrl).toMatch(/openlibrary\.org\/books\/OL/); }); });