'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const { discoverMangaDexCatalog, discoverMangaDexChapter } = require('../adapters/mangadex'); const { parse } = require('../plugins/registry'); 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 parses a catalog and pages in the scraper process', async () => { const catalog = await discoverMangaDexCatalog(seriesUrl, fakeHttp()); const chapter = await discoverMangaDexChapter(catalog.chapters[0], fakeHttp()); assert.equal(catalog.title, 'Fixture'); assert.deepEqual(catalog.chapters.map(ref => ref.number), ['1', '2']); assert.equal(chapter.pages.length, 2); assert.match(chapter.pages[0].url, /^https:\/\/uploads\.mangadex\.org\/data\//); assert.throws(() => parse('mangadex', 'metadata', { data: manga.data, url: 'https://other.example/manga/x' }), /does not belong/); });