-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforstesideV2.test.ts
102 lines (92 loc) · 3.49 KB
/
forstesideV2.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { ForstesideRequestBody, forstesideUtils } from '@navikt/skjemadigitalisering-shared-domain';
import { readFileSync } from 'fs';
import nock from 'nock';
import path from 'path';
import { config } from '../../config/config';
import { mockNext, mockRequest, mockResponse } from '../../test/requestTestHelpers';
import forstesideV2 from './forstesideV2';
import * as mottaksadresser from './mottaksadresser';
const { skjemabyggingProxyUrl, formsApiUrl } = config;
const addresses = [
{
_id: '6246de1afd03d2caeeda2825',
data: {
adresselinje1: 'Nav Arbeid og ytelser lønnsgaranti',
adresselinje2: 'Postboks 6683 St. Olavs Plass',
adresselinje3: '',
postnummer: '0129',
poststed: 'Oslo',
temakoder: 'FOS,HJE',
},
},
{
_id: '61c09f91ec962a0003c65014',
data: {
adresselinje1: 'Nav Skanning bidrag',
adresselinje2: 'PB 6215 Etterstad',
adresselinje3: '',
postnummer: '0603',
poststed: 'Oslo',
},
},
];
const formTitle = 'testskjema';
const filePathForsteside = path.join(process.cwd(), '/src/routers/api/test-forsteside.pdf');
const filePathSoknad = path.join(process.cwd(), '/src/routers/api/test-skjema.pdf');
const filePathMerged = path.join(process.cwd(), '/src/routers/api/test-merged.pdf');
describe('[endpoint] forsteside', () => {
beforeAll(() => {
vi.spyOn(mottaksadresser, 'loadMottaksadresser').mockImplementation(async () => addresses);
vi.spyOn(forstesideUtils, 'genererFoerstesideData').mockImplementation(
() =>
({
foerstesidetype: 'ETTERSENDELSE',
navSkjemaId: 'NAV 10.10.10',
spraakkode: 'NB',
overskriftstittel: 'Tittel',
arkivtittel: 'Tittel',
tema: 'HJE',
}) as ForstesideRequestBody,
);
});
it('Create front page', async () => {
const forstesidePdf = readFileSync(filePathForsteside);
const soknadPdf = readFileSync(filePathSoknad);
const mergedPdf = readFileSync(filePathMerged);
const encodedForstesidedPdf = forstesidePdf.toString('base64');
const encodedSoknadPdf = soknadPdf.toString('base64');
const recipientsMock = nock(formsApiUrl).get('/v1/recipients').reply(200, []);
const generateFileMock = nock(skjemabyggingProxyUrl!)
.post('/foersteside')
.reply(200, { foersteside: encodedForstesidedPdf });
const skjemabyggingproxyScope = nock(process.env.SKJEMABYGGING_PROXY_URL as string)
.post('/exstream')
.reply(200, { data: { result: [{ content: { data: encodedSoknadPdf } }] } });
const mergePdfScope = nock(process.env.GOTENBERG_URL as string)
.intercept('/forms/pdfengines/merge', 'POST', (body) => {
return body != null;
})
.reply(200, mergedPdf, { 'content-type': 'application/pdf' });
const req = mockRequest({
headers: {
AzureAccessToken: '',
},
body: {
form: JSON.stringify({
title: formTitle,
components: [],
properties: { mottaksadresseId: 'mottaksadresseId', path: '12345', skjemanummer: 'NAV 12.34-56' },
}),
submissionMethod: 'paper',
language: 'nb-NO',
submission: JSON.stringify({ data: {} }),
translations: JSON.stringify({}),
},
});
await forstesideV2.post(req, mockResponse(), mockNext());
expect(recipientsMock.isDone()).toBe(true);
expect(generateFileMock.isDone()).toBe(true);
expect(skjemabyggingproxyScope.isDone()).toBe(true);
expect(mergePdfScope.isDone()).toBe(true);
}, 10000);
});