feat: register ebook converter in the app so the API serves the new family
Also fixes a real bug found via the fb2 API test: file-type sniffs a real fb2 file's XML declaration as generic "xml", not "fb2" and not undetected, so it never reached the undetectable-format fallback added in the previous commit. Added an fb2->xml alias in normalizeFormat, same pattern as the existing azw3->mobi one.
This commit is contained in:
@@ -58,6 +58,43 @@ describe('GET /api/formats', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /api/formats — ebooks', () => {
|
||||
it('lists the other 9 ebook formats as targets for epub, and never lists epub as its own target', async () => {
|
||||
const response = await request(app).get('/api/formats').query({ source: 'epub' });
|
||||
|
||||
expect(response.body.targets).toEqual(
|
||||
expect.arrayContaining(['fb2', 'lrf', 'mobi', 'pdb', 'rb', 'snb', 'tcr', 'azw3', 'pdf'])
|
||||
);
|
||||
expect(response.body.targets).not.toContain('epub');
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/jobs — ebooks', () => {
|
||||
it('creates a pending job converting an fb2 upload to epub, accepting it despite file-type sniffing its XML declaration as generic "xml" rather than "fb2"', async () => {
|
||||
const fixturePath = path.join(config.storageDir, 'book.fb2');
|
||||
await fs.writeFile(
|
||||
fixturePath,
|
||||
'<?xml version="1.0" encoding="utf-8"?><FictionBook><body><p>hello</p></body></FictionBook>'
|
||||
);
|
||||
|
||||
const response = await request(app)
|
||||
.post('/api/jobs')
|
||||
.field('targetFormats', JSON.stringify(['epub']))
|
||||
.attach('files', fixturePath, 'book.fb2');
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(response.body.jobs[0].status).toBe('pending');
|
||||
|
||||
const job = await getJobByUuid(prisma, response.body.jobs[0].id);
|
||||
expect(job.sourceFormat).toBe('fb2');
|
||||
expect(job.targetFormat).toBe('epub');
|
||||
expect(job.family).toBe('ebook');
|
||||
expect(job.inputMimeType).toBe('application/xml');
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/jobs', () => {
|
||||
it('creates a pending job for a valid image upload', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
|
||||
Reference in New Issue
Block a user