const fs = require('fs');
const path = require('path');
const JSZip = require('jszip');
const EpubFontEmbedder = require('../src/main/EpubFontEmbedder');
describe('EpubFontEmbedder.patchManifest', () => {
const fixturesDir = path.join(__dirname, 'fixtures');
const epubPath = path.join(fixturesDir, 'fake.epub');
const fontPath = path.join(fixturesDir, 'fake.ttf');
beforeAll(async () => {
fs.mkdirSync(fixturesDir, { recursive: true });
fs.writeFileSync(fontPath, 'fake-ttf-binary');
const zip = new JSZip();
zip.file('OEBPS/content.opf', '');
fs.writeFileSync(epubPath, await zip.generateAsync({ type: 'nodebuffer' }));
});
afterAll(() => fs.rmSync(fixturesDir, { recursive: true, force: true }));
test('adds a manifest entry referencing the TTF when missing', async () => {
const patched = await EpubFontEmbedder.patchManifest(epubPath, [
{ path: fontPath, family: 'JetBrains Mono', weight: 400 },
]);
const out = fs.readFileSync(patched);
const zip = await JSZip.loadAsync(out);
const opf = await zip.file('OEBPS/content.opf').async('string');
expect(opf).toMatch(/- ]*href="OEBPS\/fonts\/fake\.ttf"/);
expect(opf).toMatch(/
- ]*media-type="application\/x-font-ttf"/);
});
});