Skip to content

Commit

Permalink
♻️ Mocker data for testing
Browse files Browse the repository at this point in the history
Vanskelig å få satt fastlege i testdata, tester derfor en liten mock
  • Loading branch information
steoiv committed Feb 23, 2024
1 parent c6929e9 commit f7ab157
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pages/api/oppslag/fastlege.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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<Fastlege[]> => {
if (isMock()) return mockFastlege;
if (isMock() || isDev()) return mockFastlege;

const fastlege: Fastlege = await tokenXApiProxy({
url: `${process.env.OPPSLAG_URL}/fastlege`,
Expand All @@ -39,7 +39,9 @@ export const getFastlege = async (accessToken?: string): Promise<Fastlege[]> =>

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;
Expand Down
2 changes: 2 additions & 0 deletions utils/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit f7ab157

Please sign in to comment.