Skip to content

Commit

Permalink
Merge pull request #2097 from navikt/dev
Browse files Browse the repository at this point in the history
[PROD][KAIZEN-0] Oppdatere mock responser
  • Loading branch information
Jesperpaulsen authored Jan 11, 2024
2 parents 830fc2b + 9203876 commit 6043de0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
13 changes: 4 additions & 9 deletions src/mock/dialoger/sf-dialoger-mock.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import FetchMock, { MockRequest } from 'yet-another-fetch-mock';
import { apiBaseUri } from '../../api/config';
import { mockGeneratorMedFodselsnummer, verify, withDelayedResponse } from '../utils/fetch-utils';
import { randomDelay } from '../index';
import { mockGeneratorMedFodselsnummerV2, verify, withDelayedResponse } from '../utils/fetch-utils';
import { fodselsNummerErGyldigStatus, randomDelay } from '../index';
import { MeldingerBackendMock } from '../mockBackend/meldingerBackendMock';
import { erGyldigFødselsnummer } from 'nav-faker/dist/personidentifikator/helpers/fodselsnummer-utils';
import { Melding, Meldingstype, Traad } from '../../models/meldinger/meldinger';
import { guid } from 'nav-frontend-js-utils';
import {
Expand All @@ -13,7 +12,6 @@ import {
} from '../../app/personside/infotabs/meldinger/utils/meldingerUtils';

const STATUS_OK = () => 200;
const STATUS_BAD_REQUEST = () => 400;
let meldingerBackendMock: MeldingerBackendMock = null as unknown as MeldingerBackendMock;

const harEnhetIdSomQueryParam = (req: MockRequest) => {
Expand All @@ -24,18 +22,15 @@ const harEnhetIdSomQueryParam = (req: MockRequest) => {
return undefined;
};

const fodselsNummerErGyldigStatus = (req: MockRequest) =>
erGyldigFødselsnummer(req.pathParams.fodselsnummer) ? STATUS_OK() : STATUS_BAD_REQUEST();

function setupMeldingerMock(mock: FetchMock) {
mock.post(
apiBaseUri + '/dialog/meldinger',
apiBaseUri + '/v2/dialog/meldinger',
verify(
harEnhetIdSomQueryParam,
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
mockGeneratorMedFodselsnummer((fodselsnummer) =>
mockGeneratorMedFodselsnummerV2((fodselsnummer) =>
simulateSf(meldingerBackendMock.getMeldinger(fodselsnummer))
)
)
Expand Down
2 changes: 2 additions & 0 deletions src/mock/featureToggle-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export function mockFeatureToggle(toggleId: FeatureToggles): FeatureToggleRespon
switch (toggleId) {
case FeatureToggles.BrukSoknadsstatus:
return true;
case FeatureToggles.IkkeFnrIPath:
return true;
default:
return Math.random() > 0.5;
}
Expand Down
47 changes: 29 additions & 18 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { apiBaseUri } from '../api/config';
import {
mockGeneratorMedEnhetId,
mockGeneratorMedFodselsnummer,
mockGeneratorMedFodselsnummerV2,
verify,
withDelayedResponse
} from './utils/fetch-utils';
Expand Down Expand Up @@ -57,8 +58,9 @@ export function randomDelay() {
return faker.random.number(750);
}

const fodselsNummerErGyldigStatus = (req: MockRequest) =>
erGyldigFødselsnummer(req.pathParams.fodselsnummer) ? STATUS_OK() : STATUS_BAD_REQUEST();
export const fodselsNummerErGyldigStatus = (req: MockRequest) => {
return erGyldigFødselsnummer(req.body.fnr) ? STATUS_OK() : STATUS_BAD_REQUEST();
};

function setupInnloggetSaksbehandlerMock(mock: FetchMock) {
mock.get(
Expand All @@ -85,6 +87,15 @@ function setupTilgangskontroll(mock: FetchMock) {
mockGeneratorMedFodselsnummer(tilgangskontrollMock)
)
);

mock.post(
apiBaseUri + '/v2/tilgang',
withDelayedResponse(
randomDelay(),
() => (Math.random() > 0.98 ? 400 : 200),
mockGeneratorMedFodselsnummerV2(tilgangskontrollMock)
)
);
}

function setupPersondataMock(mock: FetchMock) {
Expand All @@ -93,7 +104,7 @@ function setupPersondataMock(mock: FetchMock) {
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
mockGeneratorMedFodselsnummer((fodselsnummer) => hentPersondata(fodselsnummer))
mockGeneratorMedFodselsnummerV2((fodselsnummer) => hentPersondata(fodselsnummer))
)
);
}
Expand All @@ -104,7 +115,7 @@ function setupAktorIdMock(mock: FetchMock) {
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
mockGeneratorMedFodselsnummer((fodselsnummer) => getAktorId(fodselsnummer))
mockGeneratorMedFodselsnummerV2((fodselsnummer) => getAktorId(fodselsnummer))
)
);
}
Expand Down Expand Up @@ -145,24 +156,24 @@ function setupSaksoversiktV3Mock(mock: FetchMock) {
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
mockGeneratorMedFodselsnummer(getMockSaksoversiktV2)
mockGeneratorMedFodselsnummerV2(getMockSaksoversiktV2)
)
)
);
}

function setupUtbetalingerMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/utbetaling/:fodselsnummer',
mock.post(
apiBaseUri + '/v2/utbetaling',
withDelayedResponse(randomDelay(), fodselsNummerErGyldigStatus, (args) =>
getMockUtbetalinger(args.pathParams.fodselsnummer, args.queryParams.startDato, args.queryParams.sluttDato)
)
);
}

function setupSykepengerMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/ytelse/sykepenger/:fodselsnummer',
mock.post(
apiBaseUri + '/v2/ytelse/sykepenger',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -172,8 +183,8 @@ function setupSykepengerMock(mock: FetchMock) {
}

function setupForeldrepengerMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/ytelse/foreldrepenger/:fodselsnummer',
mock.post(
apiBaseUri + '/v2/ytelse/foreldrepenger',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -183,8 +194,8 @@ function setupForeldrepengerMock(mock: FetchMock) {
}

function setupPleiepengerMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/ytelse/pleiepenger/:fodselsnummer',
mock.post(
apiBaseUri + '/v2/ytelse/pleiepenger',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -195,7 +206,7 @@ function setupPleiepengerMock(mock: FetchMock) {

function setupOppfolgingMock(mock: FetchMock) {
mock.post(
apiBaseUri + '/oppfolging',
apiBaseUri + '/v2/oppfolging',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -206,7 +217,7 @@ function setupOppfolgingMock(mock: FetchMock) {

function setupYtelserOgKontrakter(mock: FetchMock) {
mock.post(
apiBaseUri + '/oppfolging/ytelserogkontrakter',
apiBaseUri + '/v2/oppfolging/ytelserogkontrakter',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -216,8 +227,8 @@ function setupYtelserOgKontrakter(mock: FetchMock) {
}

function setupVarselMock(mock: FetchMock) {
mock.get(apiBaseUri + '/v2/varsler/:fodselsnummer', (req, res, ctx) => {
const fnr = req.pathParams.fodselsnummer;
mock.post(apiBaseUri + '/v3/varsler', (req, res, ctx) => {
const fnr = req.body.fnr;
if (!erGyldigFødselsnummer(fnr)) {
return res(ctx.status(400));
}
Expand Down Expand Up @@ -270,7 +281,7 @@ function setupPersonsokMock(mock: FetchMock) {

function setupTildelteOppgaverMock(mock: FetchMock) {
mock.post(
apiBaseUri + '/oppgaver/tildelt',
apiBaseUri + '/v2/oppgaver/tildelt',
withDelayedResponse(randomDelay(), STATUS_OK, () => oppgaveBackendMock.getTildelteOppgaver())
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/mock/utils/fetch-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export function mockGeneratorMedFodselsnummer(
return (args: MockRequest) => fn(args.pathParams.fodselsnummer);
}

export function mockGeneratorMedFodselsnummerV2(
fn: (fodselsnummer: string) => object | object[] | undefined | string | null
) {
return (args: MockRequest) => fn(args.body.fnr);
}

export function mockGeneratorMedEnhetId(fn: (enhetId: string) => object | object[] | undefined) {
return (args: MockRequest) => fn(args.pathParams.enhetId);
}
2 changes: 1 addition & 1 deletion src/rest/resources/dialogResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function url(fnr: string, enhet: string | undefined): string {

function urlUtenFnrIPath(enhet?: string) {
const header = enhet ? `?enhet=${enhet}` : '';
return `${apiBaseUri}/v2/dialog/meldinger/${header}`;
return `${apiBaseUri}/v2/dialog/meldinger${header}`;
}

const defaults: DefaultConfig = {
Expand Down

0 comments on commit 6043de0

Please sign in to comment.