Skip to content

Commit

Permalink
PEK-459: Legg til feilhåndtering av kryptering av fnr
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorngi committed Aug 2, 2024
1 parent c6bccf7 commit 7ae2bdc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ export const getHandlers = (baseUrl: string = API_PATH) => [

http.post(`${baseUrl}/v1/encrypt`, async ({ request }) => {

Check warning on line 125 in src/mocks/handlers.ts

View workflow job for this annotation

GitHub Actions / Build application

'request' is defined but never used

Check warning on line 125 in src/mocks/handlers.ts

View workflow job for this annotation

GitHub Actions / Build application

'request' is defined but never used
await delay(TEST_DELAY)
// const FAILING_FNR = '40100000000'
// const reqFnr = request.body.fnr
// if (reqFnr === FAILING_FNR) {
// return HttpResponse.json({}, { status: 401 })
// }

return HttpResponse.text('this-is-just-jibbrish-encrypted-fnr')
}),

Expand Down
31 changes: 25 additions & 6 deletions src/pages/VeilederInput/VeilederInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export const VeilederInput = () => {
skip: !veilederBorgerFnr.fnr || !veilederBorgerFnr.encryptedFnr,
})

const [encryptedRequestLoading, setEncryptedRequestLoading] = React.useState<
'IDLE' | 'LOADING' | 'SUCCESS' | 'ERROR'
>('IDLE')

const isLoading = React.useMemo(
() => personLoading || encryptedRequestLoading === 'LOADING',
[personLoading, encryptedRequestLoading]
)

const hasTimedOut = React.useMemo(() => {
const queryParams = new URLSearchParams(window.location.search)
return queryParams.has('timeout')
Expand All @@ -74,10 +83,19 @@ export const VeilederInput = () => {
}

const encryptFnr = (fnr: string) => {
setEncryptedRequestLoading('LOADING')
return fetch(`${API_BASEURL}/v1/encrypt`, {
method: 'POST',
body: fnr,
}).then((res) => res.text())
})
.then((res) => {
setEncryptedRequestLoading('SUCCESS')
return res.text()
})
.catch(() => {
setEncryptedRequestLoading('ERROR')
throw new Error('Kunne ikke hente kryptert fnr.')
})
}

const onSubmit = (event: React.FormEvent<HTMLFormElement>) => {
Expand Down Expand Up @@ -116,11 +134,7 @@ export const VeilederInput = () => {
)
}

if (
(!personSuccess && !veilederBorgerFnr.fnr) ||
personError ||
personLoading
) {
if ((!personSuccess && !veilederBorgerFnr.fnr) || personError || isLoading) {
return (
<div data-testid="veileder-uten-borger">
<InternalHeader>
Expand All @@ -142,6 +156,11 @@ export const VeilederInput = () => {
<br /> Logg inn på bruker på nytt.
</Alert>
)}
{encryptedRequestLoading === 'ERROR' && (
<Alert variant="error" data-testid="inaktiv-alert">
Feil ved kryptering av fødselsnummer
</Alert>
)}
<VeilederInputRequestError personError={personError} />
<BodyLong>
Logg inn i pensjonskalkulator på vegne av bruker.
Expand Down

0 comments on commit 7ae2bdc

Please sign in to comment.