From f7ab157df9c110a45ac35c69c138fc2c199e1ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ivind=20Stensrud?= Date: Fri, 23 Feb 2024 09:09:21 +0100 Subject: [PATCH] :recycle: Mocker data for testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vanskelig å få satt fastlege i testdata, tester derfor en liten mock --- pages/api/oppslag/fastlege.ts | 8 +++++--- utils/environments.ts | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pages/api/oppslag/fastlege.ts b/pages/api/oppslag/fastlege.ts index 50617ec4..d9ca8dbf 100644 --- a/pages/api/oppslag/fastlege.ts +++ b/pages/api/oppslag/fastlege.ts @@ -4,7 +4,7 @@ import { beskyttetApi } from 'auth/beskyttetApi'; import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { z } from 'zod'; -import { isMock } from 'utils/environments'; +import { isDev, isMock } from 'utils/environments'; import { mockFastlege } from 'mock/fastlege'; const Fastlege = z.object({ @@ -24,7 +24,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = res.status(200).json(await getFastlege(accessToken)); }); export const getFastlege = async (accessToken?: string): Promise => { - if (isMock()) return mockFastlege; + if (isMock() || isDev()) return mockFastlege; const fastlege: Fastlege = await tokenXApiProxy({ url: `${process.env.OPPSLAG_URL}/fastlege`, @@ -39,7 +39,9 @@ export const getFastlege = async (accessToken?: string): Promise => const validatedResponse = z.array(Fastlege).safeParse(fastlege); if (!validatedResponse.success) { - logger.error({ message: `oppslag/person valideringsfeil: ${validatedResponse.error.message}` }); + logger.error({ + message: `oppslag/fastlege valideringsfeil: ${validatedResponse.error.message}`, + }); return []; } return validatedResponse.data; diff --git a/utils/environments.ts b/utils/environments.ts index 222cb5f3..84ae7904 100644 --- a/utils/environments.ts +++ b/utils/environments.ts @@ -8,6 +8,8 @@ export const isMock = () => MOCK_ENVIRONMENTS.includes(process.env.RUNTIME_ENVIRONMENT ?? '') || process.env.FUNCTIONAL_TESTS === 'enabled'; +export const isDev = () => process.env.RUNTIME_ENVIRONMENT === 'dev'; + export const clientSideIsProd = () => typeof window !== 'undefined' && window.location.href.includes('www.nav.no');