Skip to content
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

Rewrite #660

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ MIN_SIDE_ARBEIDSGIVER="https://arbeidsgiver.intern.dev.nav.no/min-side-arbeidsgi
TELEMETRY_URL=http://localhost:12347/collect
SAKSOVERSIKT_URL="https://arbeidsgiver.intern.dev.nav.no/min-side-arbeidsgiver/sak-restore-session"
MIN_SIDE_ARBEIDSGIVER="https://arbeidsgiver.intern.dev.nav.no/min-side-arbeidsgiver"
NEXT_PUBLIC_API_MOCKING=enabled
17 changes: 17 additions & 0 deletions __mocks__/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { setupWorker } from 'msw/browser';
import { handlers } from './handlers';

export const worker = setupWorker(...handlers);

worker.start({
serviceWorker: {
// Specify the worker script URL relative to the _root_.
url: '/im-dialog/mockServiceWorker.js',
options: {
// Override the scope to the root ("/").
// By default, the worker is scoped to its location on your server,
// which in this case would be "/prefix".
scope: '/im-dialog'
}
}
});
43 changes: 0 additions & 43 deletions __mocks__/handlers.js

This file was deleted.

25 changes: 25 additions & 0 deletions __mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { http, HttpResponse } from 'msw';

import trenger from '../mockdata/trenger-originalen-16dager.json';

export const handlers = [
http.post('/im-dialog/api/trenger', (request) => {
// Persist user's authentication in the session

return HttpResponse.json(trenger);
}),

http.get('/im-dialog/api/logger', (request) => {
// Check if the user is authenticated in this session

return HttpResponse.json({ ok: 'ok' });
}),

http.get('/im-dialog/api/hentKvittering/8d50ef20-37b5-4829-ad83-56219e70b375', (request) => {
// Check if the user is authenticated in this session

return new HttpResponse(null, {
status: 404
});
})
];
13 changes: 13 additions & 0 deletions __mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
async function initMocks() {
if (typeof window === 'undefined') {
const { server } = await import('./server');
server.listen();
} else {
const { worker } = await import('./browser');
// worker.start();
}
}

initMocks();

export {};
1 change: 1 addition & 0 deletions development.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ AKTIVE_ORGNR_API="/api/v1/aktiveorgnr"
INNSENDING_SELVBESTEMT_INNTEKTSMELDING_API="/api/v1/selvbestemt-inntektsmelding"
IM_API_URI="im-api.helsearbeidsgiver"
INNTEKTSDATA_SELVBESTEMT_API="/api/v1/inntekt-selvbestemt"
NEXT_PUBLIC_API_MOCKING=enabled
26 changes: 26 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @type {import('next').NextConfig} */
const { buildCspHeader } = require('@navikt/nav-dekoratoren-moduler/ssr');
const { version } = require('./package.json');
const { source } = require('axe-core');
const { destination } = require('pino');

const appDirectives = {
'connect-src': ["'self'", process.env.TELEMETRY_URL],
Expand Down Expand Up @@ -33,6 +35,17 @@ const nextConfig = {
value: 'private, no-cache, no-store, max-age=0, must-revalidate'
}
]
},
{
// Append the "Service-Worker-Allowed" header
// to each response, overriding the default worker's scope.
source: '/(.*)',
headers: [
{
key: 'Service-Worker-Allowed',
value: '/'
}
]
}
];
},
Expand Down Expand Up @@ -79,6 +92,19 @@ const nextConfig = {
innsendingSelvbestemtInntektsmeldingApi: process.env.INNSENDING_SELVBESTEMT_INNTEKTSMELDING_API,
version,
loggingDisabled: process.env.DISABLE_DECORATOR
},
rewrites: async () => {
return [
{
source: '/api/trenger/:path*',
destination:
'http://' + global.process.env.IM_API_URI + global.process.env.PREUTFYLT_INNTEKTSMELDING_API + '/:path*'
},
{
source: '/api/hentKvittering/:path*',
destination: 'http://' + global.process.env.IM_API_URI + global.process.env.KVITTERINGSDATA_API + ':path*'
}
];
}
};

Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"core-js-pure": "3.37.1",
"date-fns": "2.30.0",
"immer": "10.1.1",
"msw": "^2.4.4",
"nanoid": "5.0.7",
"next": "^14.2.5",
"next-http-proxy-middleware": "1.2.6",
Expand All @@ -49,6 +50,7 @@
"@testing-library/jest-dom": "6.4.8",
"@testing-library/react": "16.0.0",
"@testing-library/user-event": "14.5.2",
"@types/jest": "^29.5.12",
"@types/jest-axe": "3.5.9",
"@types/node": "^22.5.0",
"@types/react": "18.3.3",
Expand All @@ -69,7 +71,6 @@
"jsdom": "24.1.1",
"knip": "5.27.4",
"lint-staged": "15.2.7",
"msw": "^2.3.1",
"next-router-mock": "0.9.13",
"pino-pretty": "^11.2.2",
"prettier": "^3.3.3",
Expand All @@ -80,5 +81,11 @@
"vitest-fetch-mock": "0.3.0",
"vitest-sonar-reporter": "^2.0.0"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"msw": {
"workerDirectory": [
"public",
"__mocks__"
]
}
}
4 changes: 4 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import '../components/PageContent/PageContent.css';
import { configureLogger } from '@navikt/next-logger';
import env from '../config/environment';

if (process.env.NEXT_PUBLIC_API_MOCKING === 'enabled') {
require('../__mocks__');
}

initInstrumentation();
configureLogger({
basePath: env.baseUrl,
Expand Down
37 changes: 0 additions & 37 deletions pages/api/hentKvittering/[postId].ts

This file was deleted.

3 changes: 0 additions & 3 deletions pages/api/hentKvittering/index.ts

This file was deleted.

40 changes: 0 additions & 40 deletions pages/api/trenger.ts

This file was deleted.

20 changes: 11 additions & 9 deletions pages/kvittering/agi/[kvittid].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import testdata from '../../../mockdata/selvbestemt-kvittering.json';
import testdata from '../../../mockdata/selvbestemt-kvittering.json';

import { InferGetServerSidePropsType, NextPage } from 'next';
import Head from 'next/head';
Expand Down Expand Up @@ -466,14 +466,16 @@ function prepareForInitiering(kvitteringData: any, personData: PersonData) {
}

export async function getServerSideProps(context: any) {
// return {
// props: {
// kvittid: context.query.kvittid,
// kvittering: testdata,
// kvitteringStatus: 200,
// dataFraBackend: true
// }
// };
if (process.env.NODE_ENV == 'development') {
return {
props: {
kvittid: context.query.kvittid,
kvittering: testdata,
kvitteringStatus: 200,
dataFraBackend: true
}
};
}
const kvittid = context.query.kvittid;

let kvittering: { status: number; data: { success: any } };
Expand Down
1 change: 1 addition & 0 deletions production.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ AKTIVE_ORGNR_API="/api/v1/aktiveorgnr"
INNSENDING_SELVBESTEMT_INNTEKTSMELDING_API="/api/v1/selvbestemt-inntektsmelding"
IM_API_URI="im-api.helsearbeidsgiver"
INNTEKTSDATA_SELVBESTEMT_API="/api/v1/inntekt-selvbestemt"
NEXT_PUBLIC_API_MOCKING=disabled
Loading