-
-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dockerfile-1
- Loading branch information
Showing
7 changed files
with
122 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { generate } from './generator'; | ||
import type { Template } from '@pdfme/common'; | ||
|
||
describe('Testing mock generate util', () => { | ||
test('should return a Promise', async () => { | ||
const result = generate({ | ||
template: { schemas: [] } as Template, | ||
inputs: [], | ||
}); | ||
expect(result).toBeInstanceOf(Promise); | ||
}); | ||
|
||
test('should resolve to a Uint8Array', async () => { | ||
const result = generate({ | ||
template: { schemas: [] } as Template, | ||
inputs: [], | ||
}); | ||
expect(result).toBeInstanceOf(Uint8Array); | ||
}); | ||
|
||
it('should throw an error when template is empty', async () => { | ||
const emptyTemplate = { schemas: [] } as Template; | ||
const validInputs = [{ field1: 'value1' }]; | ||
|
||
await expect( | ||
generate({ template: emptyTemplate, inputs: validInputs }), | ||
).rejects.toThrow('Template or inputs cannot be empty.'); | ||
}); | ||
|
||
it('should throw an error when inputs are empty', async () => { | ||
const validTemplate = { schemas: [{ name: 'field1' }] } as Template; | ||
const emptyInputs: Record<string, string>[] = []; | ||
|
||
await expect( | ||
generate({ template: validTemplate, inputs: emptyInputs }), | ||
).rejects.toThrow('Template or inputs cannot be empty.'); | ||
}); | ||
|
||
it('should throw an error when both template and inputs are empty', async () => { | ||
const emptyTemplate = { schemas: [] } as Template; | ||
const emptyInputs: Record<string, string>[] = []; | ||
|
||
await expect( | ||
generate({ template: emptyTemplate, inputs: emptyInputs }), | ||
).rejects.toThrow('Template or inputs cannot be empty.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Template } from '@pdfme/common'; | ||
|
||
export const generate = async ({ | ||
template, | ||
inputs, | ||
}: { | ||
template: Template; | ||
inputs: Record<string, string>[]; | ||
}): Promise<Uint8Array> => { | ||
if (template.schemas.length === 0 || inputs.length === 0) { | ||
// console.log('pdf error: length : ', template, inputs, inputs.length); | ||
throw new Error('Template or inputs cannot be empty.'); | ||
} | ||
// Generate mock PDF-like header bytes | ||
const pdfHeader = [0x25, 0x50, 0x44, 0x46]; // %PDF | ||
// Add some random content based on input size | ||
const contentSize = Math.min(template.schemas.length, inputs.length) * 10; | ||
const mockContent = Array.from({ length: contentSize }, () => | ||
Math.floor(Math.random() * 256), | ||
); | ||
return Promise.resolve(new Uint8Array([...pdfHeader, ...mockContent])); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters