-
Notifications
You must be signed in to change notification settings - Fork 0
POC for bruk av Gotenberg til å generere PDF av søknad #1380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c507751
POC for bruk av Gotenberg til å generere PDF av søknad
nils-arne c8417ed
Merge remote-tracking branch 'refs/remotes/origin/master' into poc/go…
nils-arne 9d14a3c
POC for bruk av Gotenberg til å generere PDF av søknad
nils-arne 53a4f9e
Endringer etter PR
nils-arne 1cc5d45
Endringer etter PR. Fikse feil env parametere
nils-arne 2c56a3e
Endringer etter PR. Fikse feil endring sti til nav-logo.svg
nils-arne 0508cbb
Test endringer
nils-arne d656e64
Test endringer
nils-arne 734f3a4
Test endringer
nils-arne 8c47a66
Test endringer
nils-arne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,83 @@ | ||
import nock from 'nock'; | ||
import { config } from '../../config/config'; | ||
import { mockRequest, mockResponse } from '../../test/testHelpers'; | ||
import gotenberg from './gotenberg'; | ||
|
||
const formTitle = 'testskjema'; | ||
const defaultBody = { | ||
form: JSON.stringify({ title: formTitle, components: [], properties: { skjemanummer: 'NAV 12.34-56' } }), | ||
submission: JSON.stringify({ data: {} }), | ||
submissionMethod: 'paper', | ||
translations: JSON.stringify({}), | ||
language: 'nb-NO', | ||
}; | ||
const mockSuccessResponse = new Uint8Array([37, 80, 68, 70, 45]); // A minimal valid PDF file header | ||
|
||
/* | ||
const hexToString = hex => { | ||
let str = ''; | ||
for (let i = 0; i < hex.length; i += 2) | ||
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); | ||
return str; | ||
} | ||
*/ | ||
|
||
describe('gotenberg', () => { | ||
afterEach(() => { | ||
expect(nock.isDone()).toBe(true); | ||
}); | ||
|
||
it('decodes and sends the pdf on success', async () => { | ||
//, 'Content-Disposition': 'attachment; filename=\"index.html\"' | ||
const url = config.gotenbergUrl; | ||
//const url = config.gotenbergUrl; | ||
const uri = '/forms/chromium/convert/html'; | ||
|
||
console.log(`${url}${uri}`); | ||
const gotenbergScope = nock(`${url}` as string) | ||
.post(`${uri}`) | ||
.matchHeader('Content-Type', 'multipart/form-data') | ||
.reply(200, mockSuccessResponse); | ||
|
||
nock.recorder.rec(); | ||
console.log(gotenbergScope.activeMocks()); | ||
|
||
// Test | ||
try { | ||
const response = await fetch(`${url}${uri}`, { | ||
method: 'POST', | ||
//headers: { 'Accept': 'application/pdf, text/plain', 'Content-Type': 'multipart/form-data' }, | ||
body: JSON.stringify(defaultBody), | ||
}); | ||
console.log(response.status); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
// end test | ||
|
||
const req = mockRequest({ headers: {}, body: defaultBody }); | ||
const res = mockResponse(); | ||
const next = vi.fn(); | ||
await gotenberg.post(req, res, next); | ||
expect(next).not.toHaveBeenCalled(); | ||
expect(res.send).toHaveBeenCalledTimes(1); | ||
expect(res.send).toHaveReturned(); | ||
gotenbergScope.done(); | ||
}); | ||
|
||
it('calls next if skjemabygging-proxy returns error', async () => { | ||
const url = config.gotenbergUrl; | ||
const gotenbergScope = nock(url).post('/forms/chromium/convert/html').reply(500, 'error body'); | ||
const req = mockRequest({ headers: {}, body: defaultBody }); | ||
const res = mockResponse(); | ||
const next = vi.fn(); | ||
await gotenberg.post(req, res, next); | ||
|
||
//expect(next).toHaveBeenCalledTimes(1); | ||
const error = next.mock.calls[0][0]; | ||
expect(error?.message).toBe('Generering av PDF feilet'); | ||
expect(error?.render_html).toBe(true); | ||
expect(res.send).not.toHaveBeenCalled(); | ||
gotenbergScope.done(); | ||
}); | ||
}); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.