Skip to content

Commit

Permalink
Snapshots in createBufferTrailer
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuch committed Oct 4, 2023
1 parent 24bba7d commit 0d2cef4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/placeholder-plain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"lint": "eslint -c .eslintrc --ignore-path ../../.eslintignore ./"
},
"dependencies": {
"@signpdf/internal-utils": "*",
"@signpdf/placeholder-pdfkit010": "*",
"@signpdf/utils": "*"
},
Expand All @@ -49,6 +50,7 @@
"@babel/node": "^7.0.0",
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.4.2",
"@signpdf/internal-utils": "*",
"@types/node": ">=12.0.0",
"@types/node-forge": "^1.2.1",
"assertion-error": "^1.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createBufferTrailer creates expected outputs 1`] = `
"xref
0 1
0000000000 65535 f
trailer
<<
/Size 3
/Root 1 0 R
/Info 2 0 R
/Prev 4220
>>
startxref
4654
%%EOF"
`;

exports[`createBufferTrailer creates expected outputs 2`] = `
"xref
0 1
0000000000 65535 f
trailer
<<
/Size 3
/Root 1 0 R
/Prev 4220
>>
startxref
4654
%%EOF"
`;

exports[`createBufferTrailer creates expected outputs 3`] = `
"xref
0 1
0000000000 65535 f
3 1
0000004077 00000 n
4 1
0000003812 00000 n
trailer
<<
/Size 3
/Root 1 0 R
/Prev 4220
>>
startxref
4654
%%EOF"
`;
36 changes: 36 additions & 0 deletions packages/placeholder-plain/src/createBufferTrailer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {readTestResource} from '@signpdf/internal-utils';
import createBufferTrailer from './createBufferTrailer';

describe(createBufferTrailer, () => {
it('creates expected outputs', () => {
const pdfBuffer = readTestResource('signed.pdf');

/** @type {import("./readPdf").ReadPdfReturnType} */
const info = {
xref: {
startingIndex: 0,
maxIndex: 2,
offsets: new Map([
[1, 4163],
[2, 4098],
]),
},
rootRef: '1 0 R',
root: '\n/Type /Catalog\n/Pages 1 0 R\n/AcroForm 9 0 R\n',
infoRef: '2 0 R',
trailerStart: 4510,
previousXrefs: [],
xRefPosition: 4220,
};
const addedReferences = new Map();

expect(createBufferTrailer(pdfBuffer, info, addedReferences).toString()).toMatchSnapshot();

info.infoRef = undefined;
expect(createBufferTrailer(pdfBuffer, info, addedReferences).toString()).toMatchSnapshot();

addedReferences.set(3, 4077);
addedReferences.set(4, 3812);
expect(createBufferTrailer(pdfBuffer, info, addedReferences).toString()).toMatchSnapshot();
});
});

0 comments on commit 0d2cef4

Please sign in to comment.