Skip to content

Commit

Permalink
🔥 fjerner labs/isLabs fra koden. env FUNCTIONAL_TESTS må brukes for å…
Browse files Browse the repository at this point in the history
… få mocket søknad(brukes i playwright-test)
  • Loading branch information
tidnav committed Feb 27, 2024
1 parent dac4918 commit 6f01fb4
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 30 deletions.
1 change: 1 addition & 0 deletions .nais/dev-mock.env
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 4 additions & 6 deletions components/pageComponents/standard/Kvittering/Kvittering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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/';
Expand Down
4 changes: 2 additions & 2 deletions pages/api/buckets/lagre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`,
Expand Down
4 changes: 2 additions & 2 deletions pages/api/buckets/les.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 { 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';

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/innsending/soknadapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/innsending/soknadinnsending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions pages/api/mellomlagring/lagre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`,
Expand Down
4 changes: 2 additions & 2 deletions pages/api/mellomlagring/les.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 { 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';

Expand All @@ -17,7 +17,7 @@ const handler = beskyttetApi(async (req: NextApiRequest, res: NextApiResponse) =
export const hentMellomlagring = async (
accessToken?: string,
): Promise<SoknadContextState | undefined> => {
if (isLabs()) {
if (isFunctionalTest()) {
return {
version: SOKNAD_VERSION,
brukerMellomLagretSøknadFraAApInnsending: true,
Expand Down
4 changes: 2 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down
13 changes: 3 additions & 10 deletions utils/environments.ts
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 6f01fb4

Please sign in to comment.