Checkpoint opt-in MangaDex parser worker
This commit is contained in:
1 parent
93f07e838e
commit
1c61686c9b
11 files changed
+298
-24
No files matched your search
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createServer } = require('../plugins/worker');
|
||||
const { discoverMangaDexCatalog, discoverMangaDexChapter } = require('../adapters/mangadex');
|
||||
|
||||
const mangaId = '123e4567-e89b-42d3-a456-426614174000';
|
||||
const chapterIds = [
|
||||
'123e4567-e89b-42d3-a456-426614174001',
|
||||
'123e4567-e89b-42d3-a456-426614174002',
|
||||
];
|
||||
const seriesUrl = `https://mangadex.org/title/${mangaId}/Fixture`;
|
||||
const manga = { data: { type: 'manga', attributes: {
|
||||
title: { en: 'Fixture' }, originalLanguage: 'ja', lastChapter: '2',
|
||||
availableTranslatedLanguages: ['en'], links: {}, tags: [],
|
||||
} } };
|
||||
const feed = { total: 2, data: chapterIds.map((id, index) => ({
|
||||
id, attributes: { chapter: String(index + 1), title: `Part ${index + 1}`, pages: 2,
|
||||
publishAt: `2026-01-0${index + 1}T00:00:00Z` }, relationships: [],
|
||||
})) };
|
||||
|
||||
function fakeHttp() {
|
||||
return { async get(url) {
|
||||
const body = url.includes('/at-home/server/') ? {
|
||||
baseUrl: 'https://uploads.mangadex.org', chapter: { hash: 'HASH', data: ['1.jpg', '2.jpg'] },
|
||||
} : url.includes('/feed?') ? feed : manga;
|
||||
return { json: async () => body };
|
||||
} };
|
||||
}
|
||||
|
||||
test('MangaDex isolated parser matches the existing catalog and page behavior', async () => {
|
||||
const server = createServer('mangadex');
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
const previous = process.env.MANGADEX_PLUGIN_URL;
|
||||
delete process.env.MANGADEX_PLUGIN_URL;
|
||||
try {
|
||||
const baseline = await discoverMangaDexCatalog(seriesUrl, fakeHttp());
|
||||
const baselineChapter = await discoverMangaDexChapter(baseline.chapters[0], fakeHttp());
|
||||
process.env.MANGADEX_PLUGIN_URL = `http://127.0.0.1:${server.address().port}`;
|
||||
const isolated = await discoverMangaDexCatalog(seriesUrl, fakeHttp());
|
||||
const isolatedChapter = await discoverMangaDexChapter(isolated.chapters[0], fakeHttp());
|
||||
assert.deepEqual(isolated, baseline);
|
||||
assert.deepEqual(isolatedChapter, baselineChapter);
|
||||
const rejected = await fetch(`${process.env.MANGADEX_PLUGIN_URL}/v1/parse`, {
|
||||
method: 'POST', headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ plugin: 'weebcentral', operation: 'series', input: { html: '<h1>X</h1>', url: 'https://weebcentral.com/series/X' } }),
|
||||
});
|
||||
assert.equal(rejected.status, 400);
|
||||
} finally {
|
||||
if (previous === undefined) delete process.env.MANGADEX_PLUGIN_URL;
|
||||
else process.env.MANGADEX_PLUGIN_URL = previous;
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user