Skip to content

Commit

Permalink
100% in placeholder-plain
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuch committed Oct 4, 2023
1 parent 1fdee99 commit c9d1bdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions packages/placeholder-plain/src/plainAddPlaceholder.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import fs from 'fs';
import {readTestResource} from '@signpdf/internal-utils';
import {plainAddPlaceholder} from './plainAddPlaceholder';

describe(plainAddPlaceholder, () => {
it('adds placeholder to a prepared document', () => {
const input = fs.readFileSync(`${__dirname}/../../../resources/w3dummy.pdf`);
const input = readTestResource('w3dummy.pdf');
expect(input.indexOf('/ByteRange')).toBe(-1);
const output = plainAddPlaceholder({
pdfBuffer: input,
Expand All @@ -15,6 +15,16 @@ describe(plainAddPlaceholder, () => {
expect(output).toBeInstanceOf(Buffer);
expect(output.indexOf('/ByteRange')).not.toBe(-1);
});
it('adds placeholder when there already is one', () => {
const input = readTestResource('signed-once.pdf');
expect(input.indexOf('/ByteRange')).toBe(13342);
expect(input.indexOf('/ByteRange', 13350)).toBe(-1);

// TODO: This is quite limited testing. Need more.
const output = plainAddPlaceholder({
pdfBuffer: input,
reason: 'Because I can',
});
expect(output).toBeInstanceOf(Buffer);
expect(output.indexOf('/ByteRange', 13350)).toBe(19489);
});
});
8 changes: 4 additions & 4 deletions packages/placeholder-plain/src/readRefTable.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import {readTestResource} from '@signpdf/internal-utils';
import {SignPdfError} from '@signpdf/utils';
import readRefTable, {getXref} from './readRefTable';

describe('getXref', () => {
describe(getXref, () => {
it('Throws an error when xref is not found at position', () => {
const pdf = Buffer.from('Not containing an X R E F.');
const position = 0;
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('getXref', () => {
});
});

describe('readRefTable', () => {
describe(readRefTable, () => {
it('Expects to merge correctly the refTable of resources', () => {
[
'signed-once.pdf',
Expand All @@ -76,7 +76,7 @@ describe('readRefTable', () => {
'signed.pdf',
'w3dummy.pdf',
].forEach((fileName) => {
const pdf = fs.readFileSync(`${__dirname}/../../../resources/${fileName}`);
const pdf = readTestResource(fileName);
const r = readRefTable(pdf);
expect(r).toMatchSnapshot();
});
Expand Down

0 comments on commit c9d1bdb

Please sign in to comment.