Skip to content

Commit

Permalink
nv: Test passing in placeholder-pdfkit10
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuch committed Oct 3, 2023
1 parent afb3d75 commit 306fc28
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
4 changes: 4 additions & 0 deletions packages/placeholder-pdfkit10/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const sharedConfig = require('../../jest.config.base');
module.exports = {
...sharedConfig,
};
7 changes: 6 additions & 1 deletion packages/placeholder-pdfkit10/src/pdfkitAddPlaceholder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {DEFAULT_BYTE_RANGE_PLACEHOLDER, DEFAULT_SIGNATURE_LENGTH, SUBFILTER_ADOBE_PKCS7_DETACHED} from '@signpdf/utils/const';
import {
DEFAULT_BYTE_RANGE_PLACEHOLDER,
DEFAULT_SIGNATURE_LENGTH,
SUBFILTER_ADOBE_PKCS7_DETACHED
} from '@signpdf/utils';
// eslint-disable-next-line import/no-unresolved
import PDFKitReferenceMock from './pdfkitReferenceMock';

/**
* Adds the objects that are needed for Adobe.PPKLite to read the signature.
* Also includes a placeholder for the actual signature.
Expand Down
28 changes: 22 additions & 6 deletions packages/placeholder-pdfkit10/src/pdfkitAddPlaceholder.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PDFDocument from 'pdfkit';
import {SUBFILTER_ETSI_CADES_DETACHED} from '@signpdf/utils';
import pdfkitAddPlaceholder from './pdfkitAddPlaceholder';
import {SUBFILTER_ETSI_CADES_DETACHED} from './const';
import PDFObject from './pdfkit/pdfobject';

describe('pdfkitAddPlaceholder', () => {
describe(pdfkitAddPlaceholder, () => {
it('adds placeholder to PDFKit document', () => {
const pdf = new PDFDocument({
autoFirstPage: true,
Expand All @@ -14,7 +14,11 @@ describe('pdfkitAddPlaceholder', () => {
pdf.info.CreationDate = '';

const refs = pdfkitAddPlaceholder({pdf, pdfBuffer: Buffer.from([pdf])});
expect(Object.keys(refs)).toMatchSnapshot();
expect(Object.keys(refs)).toEqual(expect.arrayContaining([
'signature',
'form',
'widget'
]))
expect(pdf.page.dictionary.data.Annots).toHaveLength(1);
expect(pdf.page.dictionary.data.Annots[0].data.Subtype).toEqual('Widget');
expect(pdf.page.dictionary.data.Annots[0].data.V.data.ByteRange).toEqual([
Expand Down Expand Up @@ -42,7 +46,11 @@ describe('pdfkitAddPlaceholder', () => {
name: 'test name',
location: 'test Location',
});
expect(Object.keys(refs)).toMatchSnapshot();
expect(Object.keys(refs)).toEqual(expect.arrayContaining([
'signature',
'form',
'widget'
]))
expect(pdf.page.dictionary.data.Annots).toHaveLength(1);
expect(pdf.page.dictionary.data.Annots[0].data.Subtype).toEqual('Widget');
const widgetData = pdf.page.dictionary.data.Annots[0].data.V.data;
Expand All @@ -66,7 +74,11 @@ describe('pdfkitAddPlaceholder', () => {
pdfBuffer: Buffer.from([pdf]),
reason: 'test reason',
});
expect(Object.keys(refs)).toMatchSnapshot();
expect(Object.keys(refs)).toEqual(expect.arrayContaining([
'signature',
'form',
'widget'
]))
expect(pdf.page.dictionary.data.Annots).toHaveLength(1);
expect(pdf.page.dictionary.data.Annots[0].data.Subtype).toEqual('Widget');
const widgetData = pdf.page.dictionary.data.Annots[0].data.V.data;
Expand All @@ -92,7 +104,11 @@ describe('pdfkitAddPlaceholder', () => {
reason: 'test reason',
subFilter: SUBFILTER_ETSI_CADES_DETACHED,
});
expect(Object.keys(refs)).toMatchSnapshot();
expect(Object.keys(refs)).toEqual(expect.arrayContaining([
'signature',
'form',
'widget'
]))
expect(pdf.page.dictionary.data.Annots).toHaveLength(1);
const widget = pdf.page.dictionary.data.Annots[0];
expect(widget.data.Subtype).toEqual('Widget');
Expand Down
4 changes: 1 addition & 3 deletions packages/placeholder-pdfkit10/src/pdfkitReferenceMock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PDFAbstractReference from './pdfkit/abstract_reference';

class PDFKitReferenceMock extends PDFAbstractReference {
export class PDFKitReferenceMock extends PDFAbstractReference {
constructor(index, additionalData = undefined) {
super();
this.index = index;
Expand All @@ -13,5 +13,3 @@ class PDFKitReferenceMock extends PDFAbstractReference {
return `${this.index} 0 R`;
}
}

export default PDFKitReferenceMock;
6 changes: 3 additions & 3 deletions packages/placeholder-pdfkit10/src/pdfkitReferenceMock.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PDFKitReferenceMock from './pdfkitReferenceMock';
import {PDFKitReferenceMock} from './pdfkitReferenceMock';

describe('pdfkitReferenceMock', () => {
describe(PDFKitReferenceMock, () => {
it('stores index', () => {
const index = 54321;
const instance = new PDFKitReferenceMock(index);
Expand All @@ -17,6 +17,6 @@ describe('pdfkitReferenceMock', () => {
it('can be converted to string', () => {
const index = 123;
const instance = new PDFKitReferenceMock(index);
expect(instance.toString()).toMatchSnapshot();
expect(instance.toString()).toBe("123 0 R");
});
});
4 changes: 1 addition & 3 deletions packages/signpdf/src/signpdf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import forge from 'node-forge';
import {DEFAULT_BYTE_RANGE_PLACEHOLDER} from '@signpdf/utils/const';
import {removeTrailingNewLine} from '@signpdf/utils/removeTrailingNewLine';
import {findByteRange} from '@signpdf/utils/findByteRange';
import {DEFAULT_BYTE_RANGE_PLACEHOLDER, removeTrailingNewLine, findByteRange} from '@signpdf/utils';
import SignPdfError from './SignPdfError';

export {default as SignPdfError} from './SignPdfError';
Expand Down

0 comments on commit 306fc28

Please sign in to comment.