From 6f01fb437a290399feb2e900b38691fa43b7be2c Mon Sep 17 00:00:00 2001 From: Tor Idland Date: Tue, 27 Feb 2024 14:21:37 +0100 Subject: [PATCH] =?UTF-8?q?:fire:=20fjerner=20labs/isLabs=20fra=20koden.?= =?UTF-8?q?=20env=20FUNCTIONAL=5FTESTS=20m=C3=A5=20brukes=20for=20=C3=A5?= =?UTF-8?q?=20f=C3=A5=20mocket=20s=C3=B8knad(brukes=20i=20playwright-test)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .nais/dev-mock.env | 1 + .../standard/Kvittering/Kvittering.tsx | 10 ++++------ pages/api/buckets/lagre.ts | 4 ++-- pages/api/buckets/les.ts | 4 ++-- pages/api/innsending/soknadapi.ts | 4 ++-- pages/api/innsending/soknadinnsending.ts | 4 ++-- pages/api/mellomlagring/lagre.ts | 4 ++-- pages/api/mellomlagring/les.ts | 4 ++-- pages/index.tsx | 4 ++-- utils/environments.ts | 13 +++---------- 10 files changed, 22 insertions(+), 30 deletions(-) diff --git a/.nais/dev-mock.env b/.nais/dev-mock.env index acd4d46c..94521b2f 100644 --- a/.nais/dev-mock.env +++ b/.nais/dev-mock.env @@ -1,4 +1,5 @@ RUNTIME_ENVIRONMENT="localhost" +FUNCTIONAL_TESTS=enabled DECORATOR_ENV="dev" SOKNAD_API_URL="https://aap-soknad-api.dev.intern.nav.no" SOKNAD_API_AUDIENCE="dev-gcp:aap:soknad-api" diff --git a/components/pageComponents/standard/Kvittering/Kvittering.tsx b/components/pageComponents/standard/Kvittering/Kvittering.tsx index e02a76cd..8a3cf012 100644 --- a/components/pageComponents/standard/Kvittering/Kvittering.tsx +++ b/components/pageComponents/standard/Kvittering/Kvittering.tsx @@ -3,7 +3,7 @@ import React from 'react'; import * as classes from './Kvittering.module.css'; import { KontaktInfoView, SøkerView } from 'context/sokerOppslagContext'; import { SuccessStroke } from '@navikt/ds-icons'; -import { clientSideIsLabs, clientSideIsProd } from 'utils/environments'; +import { clientSideIsProd } from 'utils/environments'; import { FormattedMessage, useIntl } from 'react-intl'; interface StudentProps { @@ -14,11 +14,9 @@ interface StudentProps { const Kvittering = ({ søker, kontaktinformasjon }: StudentProps) => { const { formatMessage } = useIntl(); - const mineAapUrl = clientSideIsLabs() - ? process.env.NEXT_PUBLIC_MINE_AAP_URL - : clientSideIsProd() - ? 'https://nav.no/aap/mine-aap' - : 'https://aap-mine-aap.intern.dev.nav.no/aap/mine-aap'; + const mineAapUrl = clientSideIsProd() + ? 'https://nav.no/aap/mine-aap' + : 'https://aap-mine-aap.intern.dev.nav.no/aap/mine-aap'; const dittNavUrl = clientSideIsProd() ? 'https://www.nav.no/person/dittnav/' : 'https://www.dev.nav.no/person/dittnav/'; diff --git a/pages/api/buckets/lagre.ts b/pages/api/buckets/lagre.ts index 447b0772..34080f8c 100644 --- a/pages/api/buckets/lagre.ts +++ b/pages/api/buckets/lagre.ts @@ -4,7 +4,7 @@ import { beskyttetApi } from 'auth/beskyttetApi'; import { tokenXApiProxy, logger } from '@navikt/aap-felles-utils'; import { lagreCache } from 'mock/mellomlagringsCache'; import { erGyldigSøknadsType, GYLDIGE_SØKNADS_TYPER, SøknadsType } from 'utils/api'; -import { isLabs, isMock } from 'utils/environments'; +import { isFunctionalTest, isMock } from 'utils/environments'; import { getStringFromPossiblyArrayQuery } from 'utils/string'; import metrics from 'utils/metrics'; import { lesBucket } from './les'; @@ -37,7 +37,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = }); export const lagreBucket = async (type: SøknadsType, data: string, accessToken?: string) => { - if (isLabs()) return; + if (isFunctionalTest()) return; if (isMock()) return await lagreCache(JSON.stringify(data)); await tokenXApiProxy({ url: `${process.env.SOKNAD_API_URL}/buckets/lagre/${type}`, diff --git a/pages/api/buckets/les.ts b/pages/api/buckets/les.ts index 477fd9d9..3dd4782b 100644 --- a/pages/api/buckets/les.ts +++ b/pages/api/buckets/les.ts @@ -4,7 +4,7 @@ import { beskyttetApi } from 'auth/beskyttetApi'; import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { erGyldigSøknadsType, GYLDIGE_SØKNADS_TYPER, SøknadsType } from 'utils/api'; -import { isLabs, isMock } from 'utils/environments'; +import { isMock } from 'utils/environments'; import { getStringFromPossiblyArrayQuery } from 'utils/string'; import { SoknadContextState } from 'context/soknadcontext/soknadContext'; @@ -28,7 +28,7 @@ export const lesBucket = async ( } // Returnerer undefined ettersom vi heller bruker mellomlagring fra innsending lokalt - if (isLabs() || isMock()) { + if (isMock()) { return; } try { diff --git a/pages/api/innsending/soknadapi.ts b/pages/api/innsending/soknadapi.ts index daf41525..e731387f 100644 --- a/pages/api/innsending/soknadapi.ts +++ b/pages/api/innsending/soknadapi.ts @@ -3,7 +3,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; import { tokenXApiProxy, logger } from '@navikt/aap-felles-utils'; -import { isMock, isLabs } from 'utils/environments'; +import { isFunctionalTest, isMock } from 'utils/environments'; import { slettBucket } from '../buckets/slett'; import { ErrorMedStatus } from 'auth/ErrorMedStatus'; import metrics from 'utils/metrics'; @@ -24,7 +24,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = }); export const sendSoknad = async (data: string, accessToken?: string) => { - if (isLabs()) { + if (isFunctionalTest()) { return { uri: `https://localhost:3000/aap/soknad/api/vedlegg/les?uuid=${randomUUID()}` }; } if (isMock()) { diff --git a/pages/api/innsending/soknadinnsending.ts b/pages/api/innsending/soknadinnsending.ts index 951c60cf..6f0db24d 100644 --- a/pages/api/innsending/soknadinnsending.ts +++ b/pages/api/innsending/soknadinnsending.ts @@ -3,7 +3,7 @@ import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; import { NextApiRequest, NextApiResponse } from 'next'; import metrics from 'utils/metrics'; import { ErrorMedStatus } from 'auth/ErrorMedStatus'; -import { isLabs, isMock } from 'utils/environments'; +import { isFunctionalTest, isMock } from 'utils/environments'; import { slettBucket } from 'pages/api/buckets/slett'; import { createIntl } from 'react-intl'; import { flattenMessages, messages } from 'utils/message'; @@ -148,7 +148,7 @@ export const sendSoknadViaAapInnsending = async ( innsending: SoknadInnsendingRequestBody, accessToken?: string, ) => { - if (isLabs()) { + if (isFunctionalTest()) { return 'Vi har mottat søknaden din.'; } if (isMock()) { diff --git a/pages/api/mellomlagring/lagre.ts b/pages/api/mellomlagring/lagre.ts index dcc7dd33..fe3ff7c0 100644 --- a/pages/api/mellomlagring/lagre.ts +++ b/pages/api/mellomlagring/lagre.ts @@ -3,7 +3,7 @@ import { getAccessTokenFromRequest } from 'auth/accessToken'; import { beskyttetApi } from 'auth/beskyttetApi'; import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; import { lagreCache } from 'mock/mellomlagringsCache'; -import { isLabs, isMock } from 'utils/environments'; +import { isFunctionalTest, isMock } from 'utils/environments'; import metrics from 'utils/metrics'; import { StepType } from 'components/StepWizard/Step'; @@ -32,7 +32,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = }); export const lagreBucket = async (data: string, accessToken?: string) => { - if (isLabs()) return; + if (isFunctionalTest()) return; if (isMock()) return await lagreCache(JSON.stringify(data)); await tokenXApiProxy({ url: `${process.env.INNSENDING_URL}/mellomlagring/søknad`, diff --git a/pages/api/mellomlagring/les.ts b/pages/api/mellomlagring/les.ts index 6edab821..37777e65 100644 --- a/pages/api/mellomlagring/les.ts +++ b/pages/api/mellomlagring/les.ts @@ -4,7 +4,7 @@ import { beskyttetApi } from 'auth/beskyttetApi'; import { logger, tokenXApiProxy } from '@navikt/aap-felles-utils'; import metrics from 'utils/metrics'; import { lesCache } from 'mock/mellomlagringsCache'; -import { isLabs, isMock } from 'utils/environments'; +import { isFunctionalTest, isMock } from 'utils/environments'; import { defaultStepList } from 'pages'; import { SOKNAD_VERSION, SoknadContextState } from 'context/soknadcontext/soknadContext'; @@ -17,7 +17,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) = export const hentMellomlagring = async ( accessToken?: string, ): Promise => { - if (isLabs()) { + if (isFunctionalTest()) { return { version: SOKNAD_VERSION, brukerMellomLagretSøknadFraAApInnsending: true, diff --git a/pages/index.tsx b/pages/index.tsx index d3ff4661..23f60229 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -8,7 +8,6 @@ import { getAccessToken } from 'auth/accessToken'; import { fetchPOST } from 'api/fetch'; import { lesBucket } from 'pages/api/buckets/les'; import { StepType } from 'components/StepWizard/Step'; -import { isLabs } from 'utils/environments'; import { logSkjemaStartetEvent } from 'utils/amplitude'; import metrics from 'utils/metrics'; import { scrollRefIntoView } from 'utils/dom'; @@ -17,6 +16,7 @@ import { logger } from '@navikt/aap-felles-utils'; import { getFulltNavn } from 'lib/søker'; import { SOKNAD_VERSION, SoknadContextState } from 'context/soknadcontext/soknadContext'; import { hentMellomlagring } from 'pages/api/mellomlagring/les'; +import { isFunctionalTest } from 'utils/environments'; interface PageProps { søker: Soker; @@ -141,7 +141,7 @@ export const getServerSideProps = beskyttetSide( const activeIndex = activeStep?.stepIndex; stopTimer(); - if (activeIndex && !isLabs()) { + if (activeIndex && !isFunctionalTest()) { logger.info('Starter påbegynt søknad'); return { redirect: { diff --git a/utils/environments.ts b/utils/environments.ts index 222cb5f3..ff649966 100644 --- a/utils/environments.ts +++ b/utils/environments.ts @@ -1,15 +1,8 @@ -const MOCK_ENVIRONMENTS = ['localhost', 'labs']; +const MOCK_ENVIRONMENTS = ['localhost']; -export const isLabs = () => - ['labs'].includes(process.env.RUNTIME_ENVIRONMENT ?? '') || - process.env.FUNCTIONAL_TESTS === 'enabled'; +export const isMock = () => MOCK_ENVIRONMENTS.includes(process.env.RUNTIME_ENVIRONMENT ?? ''); -export const isMock = () => - MOCK_ENVIRONMENTS.includes(process.env.RUNTIME_ENVIRONMENT ?? '') || - process.env.FUNCTIONAL_TESTS === 'enabled'; +export const isFunctionalTest = () => process.env.FUNCTIONAL_TESTS === 'enabled'; export const clientSideIsProd = () => typeof window !== 'undefined' && window.location.href.includes('www.nav.no'); - -export const clientSideIsLabs = () => - typeof window !== 'undefined' && window.location.href.includes('ekstern.dev.nav.no');