Skip to content

Commit

Permalink
chore(pdf-engines): assert at least pdfa or pdfUA is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
cherfia committed Oct 4, 2024
1 parent 208fb89 commit bf13769
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/pdf-engines/tests/pdf.engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ describe('PDFEngines', () => {

describe('convert', () => {
describe('when no properties are passed', () => {
it('should return a buffer', async () => {
it('should throw an error', async () => {
mockPromisesAccess.mockResolvedValue();
mockFetch.mockResolvedValue(new Response('content'));
const buffer = await PDFEngines.convert({
files: ['path/to/file_1.pdf', 'path/to/file_2.pdf']
});
expect(buffer).toEqual(Buffer.from('content'));
expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
await expect(
PDFEngines.convert({
files: ['path/to/file_1.pdf', 'path/to/file_2.pdf']
})
).rejects.toThrow(
'At least one of pdfa or pdfUA must be provided'
);
});
});

Expand Down
7 changes: 6 additions & 1 deletion src/pdf-engines/utils/pdf-engines.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { constants, createReadStream, promises, ReadStream } from 'fs';
import path from 'path';

import FormData from 'form-data';
import { PathLikeOrReadStream } from '../../common';
import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
import {
ConversionOptions,
MergeOptions
Expand Down Expand Up @@ -55,6 +55,11 @@ export class PDFEnginesUtils {
data: FormData,
options: ConversionOptions | MergeOptions
): Promise<void> {
GotenbergUtils.assert(
!!options.pdfa || !!options.pdfUA,
'At least one of pdfa or pdfUA must be provided'
);

if (options.pdfa) {
data.append('pdfa', options.pdfa);
}
Expand Down

0 comments on commit bf13769

Please sign in to comment.