Skip to content

Commit 71af10c

Browse files
fix: use json.results path in all bulk-enrich tests
1 parent 2bdba5a commit 71af10c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tests/bulk-enrich.spec.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ test.describe.serial('Bulk Enrichment', () => {
274274
});
275275
expect(resp.status()).toBe(200);
276276
const json = await resp.json();
277+
const results = json.results ?? json;
277278
expect(json.success ?? json.ok).toBeTruthy();
278279

279280
// Verify in DB
@@ -291,6 +292,7 @@ test.describe.serial('Bulk Enrichment', () => {
291292
});
292293
expect(resp.status()).toBe(200);
293294
const json = await resp.json();
295+
const results = json.results ?? json;
294296
expect(json.success ?? json.ok).toBeTruthy();
295297

296298
const val = dbQuery(
@@ -380,10 +382,11 @@ test.describe.serial('Bulk Enrichment', () => {
380382

381383
expect(resp.status()).toBe(200);
382384
const json = await resp.json();
385+
const results = json.results ?? json;
383386

384387
// After batch, check if cover was populated (may depend on API availability)
385388
const cover = dbQuery(`SELECT IFNULL(copertina_url, '') FROM libri WHERE id = ${targetId}`);
386-
if (json.enriched > 0) {
389+
if (results.enriched > 0) {
387390
expect(cover.length).toBeGreaterThan(0);
388391
}
389392
// If enriched === 0, API may be rate-limited — acceptable
@@ -494,10 +497,11 @@ test.describe.serial('Bulk Enrichment', () => {
494497

495498
expect(resp.status()).toBe(200);
496499
const json = await resp.json();
500+
const results = json.results ?? json;
497501

498-
// Response should indicate at least one not_found (or the fake ISBN was skipped)
499-
expect(json).toHaveProperty('not_found');
500-
expect(json.not_found).toBeGreaterThanOrEqual(0);
502+
// Response has results nested under 'results' key
503+
expect(results).toHaveProperty('not_found');
504+
expect(results.not_found).toBeGreaterThanOrEqual(0);
501505
// No crash — server returned valid JSON
502506
});
503507

@@ -517,20 +521,21 @@ test.describe.serial('Bulk Enrichment', () => {
517521

518522
expect(resp.status()).toBe(200);
519523
const json = await resp.json();
524+
const results = json.results ?? json;
520525

521526
// Response must contain progress counters
522-
expect(json).toHaveProperty('processed');
523-
expect(json).toHaveProperty('enriched');
524-
expect(json).toHaveProperty('not_found');
525-
expect(json).toHaveProperty('errors');
527+
expect(results).toHaveProperty('processed');
528+
expect(results).toHaveProperty('enriched');
529+
expect(results).toHaveProperty('not_found');
530+
expect(results).toHaveProperty('errors');
526531

527532
// processed must be a non-negative number
528-
expect(typeof json.processed).toBe('number');
529-
expect(json.processed).toBeGreaterThanOrEqual(0);
533+
expect(typeof results.processed).toBe('number');
534+
expect(results.processed).toBeGreaterThanOrEqual(0);
530535

531536
// enriched + not_found + errors should equal processed
532-
const sum = (json.enriched || 0) + (json.not_found || 0) + (json.errors || 0);
533-
expect(sum).toBe(json.processed);
537+
const sum = (results.enriched || 0) + (results.not_found || 0) + (results.errors || 0);
538+
expect(sum).toBe(results.processed);
534539
});
535540

536541
test('15. Batch preserves tipo_media after enrichment', async () => {

0 commit comments

Comments
 (0)