import { describe, expect, it } from 'vitest';
import meta from './meta.json' with { type: 'json' };
import { localMeta } from '../../api/_lib/local-meta.js';
import { listFixtures, loadFixture, runFixtureSuite } from '@rareindex/connectors/testing';
import createConnector, { parseSetMarkdown } from './index.js';
const connector = createConnector(localMeta(meta));
const SAMPLE = `## 1999 WOTC Pokémon Base Set
| Card # | NameGrade | VA | 1 | 9 | 10 | 10P | Total |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1/102 | [Alakazam](https://my.taggrading.com/pop-report/Pokemon/1999/WOTC%20Pok%C3%A9mon/Alakazam/1%2F102?setName=Base+Set&variation=Holo)
Holo | [2](x) | [2](x) | [27](x) | [5](x) | 0 | [36](x) |
| 4/102 | [Charizard](https://my.taggrading.com/x)
Holo | 0 | 1 | 40 | 12 | 1 | 54 |
`;
describe('tag-pop', () => {
runFixtureSuite(connector, it, expect);
it('parses the population table', () => {
const { grades, rows } = parseSetMarkdown(SAMPLE);
expect(grades).toEqual(['authentic', '1', '9', '10', '10P']);
expect(rows).toHaveLength(2);
expect(rows[0]).toMatchObject({ number: '1/102', name: 'Alakazam', variation: 'Holo', total: 36 });
expect(rows[0]!.counts).toEqual({ authentic: 2, '1': 2, '9': 27, '10': 5 });
expect(rows[1]!.counts['10P']).toBe(1);
});
it('emits one population report per card row with grader tag', async () => {
for (const name of listFixtures('tag-pop')) {
const out = await connector.normalize(loadFixture('tag-pop', name).raw);
expect(out.length).toBeGreaterThan(0);
for (const r of out) {
expect(r.kind).toBe('population_report');
if (r.kind === 'population_report') {
expect(r.grader).toBe('tag');
expect(r.total).toBeGreaterThan(0);
expect(r.attributes.set).toBeTruthy();
}
}
}
});
});