-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automatically encode
page.html
, pdf.headerTemplate
and `pdf…
….footerTemplate`
- Loading branch information
Showing
6 changed files
with
97 additions
and
4 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
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,29 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import Doczilla from '../Doczilla' | ||
|
||
describe('Page', () => { | ||
|
||
const client = new Doczilla('fake-api-token') | ||
// @ts-expect-error private property | ||
const axiosMock = new MockAdapter(client.client) | ||
|
||
axiosMock.onAny().reply(200, Buffer.from('')) | ||
|
||
test('it encode the page.html option', async () => { | ||
await client.pdf.direct({ | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>' | ||
} | ||
}) | ||
|
||
expect(axiosMock.history.post.length).toBe(1) | ||
expect(axiosMock.history.post[0].data).toEqual(JSON.stringify({ | ||
page: { | ||
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==' | ||
} | ||
})) | ||
}) | ||
|
||
}) |
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,37 @@ | ||
import { describe, expect, test } from '@jest/globals' | ||
import MockAdapter from 'axios-mock-adapter' | ||
|
||
import Doczilla from '../Doczilla' | ||
|
||
describe('PDF', () => { | ||
|
||
const client = new Doczilla('fake-api-token') | ||
// @ts-expect-error private property | ||
const axiosMock = new MockAdapter(client.client) | ||
|
||
axiosMock.onAny().reply(200, Buffer.from('')) | ||
|
||
test('it should encode the pdf.headerTemplate and pdf.footerTemplate options', async () => { | ||
await client.pdf.direct({ | ||
page: { | ||
html: '<div>Your first Doczilla PDF</div>' | ||
}, | ||
pdf: { | ||
headerTemplate: '<div>Header template</div>', | ||
footerTemplate: '<div>Footer template</div>' | ||
} | ||
}) | ||
|
||
expect(axiosMock.history.post.length).toBe(1) | ||
expect(axiosMock.history.post[0].data).toEqual(JSON.stringify({ | ||
page: { | ||
html: 'PGRpdj5Zb3VyIGZpcnN0IERvY3ppbGxhIFBERjwvZGl2Pg==' | ||
}, | ||
pdf: { | ||
headerTemplate: 'PGRpdj5IZWFkZXIgdGVtcGxhdGU8L2Rpdj4=', | ||
footerTemplate: 'PGRpdj5Gb290ZXIgdGVtcGxhdGU8L2Rpdj4=' | ||
} | ||
})) | ||
}) | ||
|
||
}) |
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
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