61 lines
2.9 KiB
JavaScript
61 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { ScraperService } = require('../service');
|
|
|
|
async function confirm(item) {
|
|
const service = Object.create(ScraperService.prototype);
|
|
service.state = { queue: [item], currentIds: {}, sourcePaused: {} };
|
|
service.event = async () => {};
|
|
await service.control('confirm', item.id);
|
|
return item;
|
|
}
|
|
|
|
async function retry(item) {
|
|
const service = Object.create(ScraperService.prototype);
|
|
service.state = { queue: [item], currentIds: {}, sourcePaused: {}, circuits: {}, incidents: [], paused: true };
|
|
service.event = async () => {};
|
|
service.recomputeStatus = () => {};
|
|
service.resolveAdapter = () => ({ adapter: { id: item.source } });
|
|
await service.control('retry', item.id);
|
|
return item;
|
|
}
|
|
|
|
test('confirming an inspection uses the canonical title for automatic metadata lookup', async () => {
|
|
const item = await confirm({ id: 'job', seriesId: '01J76XYFHVMSQVDJPQ42TN2XYN',
|
|
title: '01J76XYFHVMSQVDJPQ42TN2XYN', metadataSearch: '01J76XYFHVMSQVDJPQ42TN2XYN',
|
|
sourceTitle: 'The Exiled Heavy Knight Knows How to Game the System', kind: 'inspection', status: 'ready' });
|
|
assert.equal(item.title, item.sourceTitle);
|
|
assert.equal(item.metadataSearch, item.sourceTitle);
|
|
assert.equal(item.metadataSearchExplicit, true);
|
|
assert.equal(item.kind, 'download');
|
|
});
|
|
|
|
test('confirming an inspection preserves an explicitly supplied metadata search', async () => {
|
|
const item = await confirm({ id: 'job', seriesId: 'series-id', title: 'Heavy Knight',
|
|
metadataSearch: 'Heavy Knight (Romanized Title)', metadataSearchExplicit: true,
|
|
sourceTitle: 'The Exiled Heavy Knight Knows How to Game the System', kind: 'inspection', status: 'ready' });
|
|
assert.equal(item.metadataSearch, 'Heavy Knight (Romanized Title)');
|
|
assert.equal(item.title, 'Heavy Knight');
|
|
});
|
|
|
|
test('legacy automatic title searches are replaced with the inspected canonical title', async () => {
|
|
const item = await confirm({ id: 'job', seriesId: 'series-id', title: 'heavy-knight-slug',
|
|
metadataSearch: 'heavy-knight-slug', sourceTitle: 'The Exiled Heavy Knight Knows How to Game the System',
|
|
kind: 'inspection', status: 'ready' });
|
|
assert.equal(item.metadataSearch, item.sourceTitle);
|
|
});
|
|
|
|
test('retry repairs a legacy URL-ID lookup before requeueing it', async () => {
|
|
const item = await retry({ id: 'job', seriesId: '01J76XYFHVMSQVDJPQ42TN2XYN',
|
|
title: '01J76XYFHVMSQVDJPQ42TN2XYN', metadataSearch: '01J76XYFHVMSQVDJPQ42TN2XYN',
|
|
sourceTitle: 'The Exiled Heavy Knight Knows How to Game the System', source: 'weebcentral',
|
|
status: 'unavailable', error: 'AniList HTTP 404', stallRecoveries: 1 });
|
|
assert.equal(item.metadataSearch, item.sourceTitle);
|
|
assert.equal(item.title, item.sourceTitle);
|
|
assert.equal(item.status, 'queued');
|
|
assert.equal(item.error, undefined);
|
|
assert.equal(item.stallRecoveries, 0);
|
|
});
|