Skip to content

Commit

Permalink
Test endringer
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-arne committed Jan 23, 2025
1 parent 0508cbb commit d656e64
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 27 deletions.
3 changes: 2 additions & 1 deletion packages/bygger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"devDependencies": {
"@testing-library/react": "^16.0.1",
"lodash.template": "^4.5.0"
"lodash.template": "^4.5.0",
"vite-plugin-static-copy": "^2.2.0"
}
}
9 changes: 5 additions & 4 deletions packages/fyllut-backend/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('app', () => {
skjemabyggingproxyScope.done();
});

it('Performs TokenX exchange and retrieves pdf from exstream before calling SendInn', async () => {
it('Performs TokenX exchange and retrieves pdf from Gotenberg before calling SendInn', async () => {
const key = await generateJwk();
nock('https://testoidc.unittest.no')
.get('/idporten-oidc-provider/jwk')
Expand All @@ -247,10 +247,11 @@ describe('app', () => {
submissionMethod: 'digital',
innsendingsId,
};

const mockSuccessResponse = new Uint8Array([37, 80, 68, 70, 45]);
console.log(process.env.GOTENBERG_URL as string);
const skjemabyggingproxyScope = nock(process.env.GOTENBERG_URL as string)
.post('/gotenberg')
.reply(200, { data: { result: [{ content: { data: '' } }] } });
.post('/forms/chromium/convert/html')
.reply(200, mockSuccessResponse);
const tokenxWellKnownScope = nock(extractHost(tokenxConfig?.wellKnownUrl))
.get(extractPath(tokenxConfig?.wellKnownUrl))
.reply(200, { token_endpoint: tokenxEndpoint });
Expand Down
36 changes: 20 additions & 16 deletions packages/fyllut-backend/src/routers/api/helpers/pdfService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { config, defaultConfig } from '../../../config/config';
import { logger } from '../../../logger';
import { appMetrics } from '../../../services';
import { synchronousResponseToError } from '../../../utils/errorHandling';
//import fetchWithRetry, { HeadersInit } from '../../../utils/fetchWithRetry';
import fetch from 'node-fetch';
//import fetch from 'node-fetch';
import fetchWithRetry from '../../../utils/fetchWithRetry';
import { generateFooterHtml } from './footerBuilder';
import { createHtmlFromSubmission } from './htmlBuilder';

Expand Down Expand Up @@ -42,6 +42,7 @@ export const createPdf = async (
};

const filePath = path.join(process.cwd(), '', '/icons/nav-logo.svg');
//const filePath = '../../../../public/icons/nav-logo.svg';

const navIcon = readFileSync(filePath, { encoding: 'utf-8', flag: 'r' });

Expand Down Expand Up @@ -125,30 +126,33 @@ const createPdfCallingGotenberg = async (
formData.append('pdfua', options.pdfua ? 'true' : '');
formData.append('skipNetworkIdleEvent', 'false');

console.log(`${gotenbergUrl}/forms/chromium/convert/html`);

try {
// Send the request to Gotenberg
const gotenbergResponse = await fetchWithRetry(`${gotenbergUrl}/forms/chromium/convert/html`, {
retry: 3,
headers: {
...formData.getHeaders(),
//Authorization: `Bearer ${azureAccessToken}`,
contentType: 'multipart/form-data',
accept: 'application/pdf, text/plain',
} as HeadersInit,
method: 'POST',
body: formData,
});

/*
const gotenbergResponse = await fetchWithRetry(`${gotenbergUrl}/forms/chromium/convert/html`, {
retry: 3,
headers: {
...formData.getHeaders(),
//Authorization: `Bearer ${azureAccessToken}`,
'x-correlation-id': correlator.getId(),
} as HeadersInit,
method: 'POST',
body: formData,
});
*/
//, 'content-type': 'multipart/form-data'
const gotenbergResponse = await fetch(`${gotenbergUrl}/forms/chromium/convert/html`, {
method: 'POST',
headers: {
...formData.getHeaders(),
//'x-correlation-id': correlator.getId(),
accept: 'application/pdf, application/text',
contentType: 'multipart/form-data',
accept: 'application/pdf, text/plain',
} as HeadersInit,
body: formData,
});
*/

if (!gotenbergResponse.ok) {
const errorText = await gotenbergResponse.text();
Expand Down
2 changes: 1 addition & 1 deletion packages/fyllut-backend/src/test/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NORG2_URL=https://norg2.unittest.nav.no
SEND_INN_TOKEN_X_CLIENT_ID=test-gcp:soknad:send-inn
FORMS_API_URL=https://forms-api-test.nav.no
#GOTENBERG_URL=https://convert-to-pdf.intern.dev.nav.no
GOTENBERG_URL=http://127.0.0.1:3000
GOTENBERG_URL=http://www.gotenberg.no

# FYLLUT_BACKEND_LOGLEVEL=debug

Expand Down
4 changes: 3 additions & 1 deletion packages/fyllut-backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"@navikt/skjemadigitalisering-shared-domain": ["../shared-domain/src"]
}
},
"include": ["src", "icons"]
"include": ["src",
"icons"
]
}
9 changes: 9 additions & 0 deletions packages/fyllut-backend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="vitest" />
import { defineConfig, PluginOption } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig(({ mode }) => {
Expand All @@ -9,6 +10,14 @@ export default defineConfig(({ mode }) => {
adapter: 'express',
appPath: './src/server.js',
}),
viteStaticCopy({
targets: [
{
src: './icons/nav-logo.svg', // src folder
dest: './icons/nav-logo.svg', // Destination folder in `dist`
},
],
}),
];

if (mode !== 'production') {
Expand Down
74 changes: 70 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,14 @@ ansi-styles@^6.0.0, ansi-styles@^6.1.0, ansi-styles@^6.2.1:
resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz"
integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==

anymatch@~3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"
integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==
dependencies:
normalize-path "^3.0.0"
picomatch "^2.0.4"

arch@^2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/arch/-/arch-2.2.0.tgz"
Expand Down Expand Up @@ -2400,6 +2408,11 @@ before-after-hook@^3.0.2:
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-3.0.2.tgz#d5665a5fa8b62294a5aa0a499f933f4a1016195d"
integrity sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==

binary-extensions@^2.0.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522"
integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==

[email protected]:
version "1.0.2"
resolved "https://registry.npmjs.org/bintrees/-/bintrees-1.0.2.tgz"
Expand Down Expand Up @@ -2453,7 +2466,7 @@ brace-expansion@^2.0.1:
dependencies:
balanced-match "^1.0.0"

braces@^3.0.3:
braces@^3.0.3, braces@~3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
Expand Down Expand Up @@ -2630,6 +2643,21 @@ check-more-types@^2.24.0:
resolved "https://registry.npmjs.org/check-more-types/-/check-more-types-2.24.0.tgz"
integrity sha512-Pj779qHxV2tuapviy1bSZNEL1maXr13bPYpsvSDB68HlYcYuhlDrmGd63i0JHMCLKzc7rUSNIrpdJlhVlNwrxA==

chokidar@^3.5.3:
version "3.6.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b"
integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==
dependencies:
anymatch "~3.1.2"
braces "~3.0.2"
glob-parent "~5.1.2"
is-binary-path "~2.1.0"
is-glob "~4.0.1"
normalize-path "~3.0.0"
readdirp "~3.6.0"
optionalDependencies:
fsevents "~2.3.2"

ci-info@^3.2.0:
version "3.8.0"
resolved "https://registry.npmjs.org/ci-info/-/ci-info-3.8.0.tgz"
Expand Down Expand Up @@ -4623,6 +4651,15 @@ fs-extra@^10.0.1:
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^11.1.0:
version "11.3.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.3.0.tgz#0daced136bbaf65a555a326719af931adc7a314d"
integrity sha512-Z4XaCL6dUDHfP/jT25jJKMmtxvuwbkrD1vNSMFlo9lNLY2c5FHYSQgHPRZUjAB26TpDEoW9HCOgplrdbaPV/ew==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^9.1.0:
version "9.1.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz"
Expand Down Expand Up @@ -4757,7 +4794,7 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"

glob-parent@^5.1.2:
glob-parent@^5.1.2, glob-parent@~5.1.2:
version "5.1.2"
resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz"
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
Expand Down Expand Up @@ -5255,6 +5292,13 @@ is-bigint@^1.0.1:
dependencies:
has-bigints "^1.0.1"

is-binary-path@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==
dependencies:
binary-extensions "^2.0.0"

is-boolean-object@^1.1.0:
version "1.1.2"
resolved "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz"
Expand Down Expand Up @@ -5332,7 +5376,7 @@ is-generator-function@^1.0.10:
dependencies:
has-tostringtag "^1.0.0"

is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3:
is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1:
version "4.0.3"
resolved "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz"
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
Expand Down Expand Up @@ -6547,6 +6591,11 @@ node-releases@^2.0.18:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.18.tgz#f010e8d35e2fe8d6b2944f03f70213ecedc4ca3f"
integrity sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

npm-run-path@^4.0.0:
version "4.0.1"
resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz"
Expand Down Expand Up @@ -6895,7 +6944,7 @@ picocolors@^1.1.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59"
integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==

picomatch@^2.2.2, picomatch@^2.2.3, picomatch@^2.3.1:
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.2, picomatch@^2.2.3, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
Expand Down Expand Up @@ -7339,6 +7388,13 @@ readable-stream@^3.4.0, readable-stream@^3.6.0:
string_decoder "^1.1.1"
util-deprecate "^1.0.1"

readdirp@~3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"
integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==
dependencies:
picomatch "^2.2.1"

redent@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz"
Expand Down Expand Up @@ -8688,6 +8744,16 @@ vite-plugin-node@^3.1.0:
chalk "^4.1.2"
debug "^4.3.2"

vite-plugin-static-copy@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/vite-plugin-static-copy/-/vite-plugin-static-copy-2.2.0.tgz#8eec750f016e508b09234da880e9310cd1367b9b"
integrity sha512-ytMrKdR9iWEYHbUxs6x53m+MRl4SJsOSoMu1U1+Pfg0DjPeMlsRVx3RR5jvoonineDquIue83Oq69JvNsFSU5w==
dependencies:
chokidar "^3.5.3"
fast-glob "^3.2.11"
fs-extra "^11.1.0"
picocolors "^1.0.0"

vite-tsconfig-paths@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/vite-tsconfig-paths/-/vite-tsconfig-paths-5.0.1.tgz#c9387a29c32fd586e4c7f4e2b2da1f0b5c9a7403"
Expand Down

0 comments on commit d656e64

Please sign in to comment.