← back to AbramsOS

tests/pdf-parser.test.js

28 lines

const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');

const pdf = require('../lib/pdf-parser');

// pdf-parse ships with a sample PDF. Use it as a known-good fixture.
const FIXTURE = path.join(__dirname, '..', 'node_modules', 'pdf-parse', 'test', 'data', '01-valid.pdf');

test('parseFile extracts text + page count', async (t) => {
  if (!fs.existsSync(FIXTURE)) return t.skip('pdf-parse sample fixture not installed');
  const r = await pdf.parseFile(FIXTURE);
  assert.ok(r.pages > 0, 'pages should be > 0');
  assert.ok(typeof r.text === 'string');
  assert.ok(r.text.length > 0, 'text should be extracted');
});

test('resolveDocumentPath maps drive: paths to uploads/', () => {
  const p = pdf.resolveDocumentPath('drive:abc123', 'application/pdf');
  assert.ok(p.endsWith('uploads/drive-abc123.pdf'));
});

test('resolveDocumentPath honors mime for image extensions', () => {
  const p = pdf.resolveDocumentPath('drive:xyz', 'image/png');
  assert.ok(p.endsWith('uploads/drive-xyz.png'));
});