Skip to content

Commit

Permalink
F - Legger til validator for epost, som sjekker om den inneholder und…
Browse files Browse the repository at this point in the history
…erscore
  • Loading branch information
dskarpas committed Oct 31, 2024
1 parent 88f80a0 commit b1d967a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/main/kotlin/no/nav/eessi/pensjon/prefill/PrefillService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package no.nav.eessi.pensjon.prefill
import io.micrometer.core.instrument.Metrics
import no.nav.eessi.pensjon.eux.model.sed.SED.Companion.setSEDVersion
import no.nav.eessi.pensjon.metrics.MetricsHelper
import no.nav.eessi.pensjon.prefill.models.KrrPerson
import no.nav.eessi.pensjon.prefill.models.KrrPerson.Companion.validateEmail
import no.nav.eessi.pensjon.prefill.sed.PrefillSEDService
import no.nav.eessi.pensjon.shared.api.ApiRequest
import no.nav.eessi.pensjon.shared.api.PersonInfo
Expand Down Expand Up @@ -39,7 +41,13 @@ class PrefillService(

try {
val norskIdent = innhentingService.hentFnrEllerNpidFraAktoerService(request.aktoerId)!!
val krrPerson = krrService.hentPersonFraKrr(norskIdent)
val krrPerson = krrService.hentPersonFraKrr(norskIdent).also { personResponse ->
KrrPerson(
reservert = personResponse.reservert,
epostadresse = personResponse.epostadresse.validateEmail(),
mobiltelefonnummer = personResponse.mobiltelefonnummer
)
}

val personInfo = if (krrPerson.reservert == true) {
PersonInfo(norskIdent, request.aktoerId).also { logger.info("Personen har reservert seg mot digital kommunikasjon")}
Expand Down
15 changes: 11 additions & 4 deletions src/main/kotlin/no/nav/eessi/pensjon/prefill/models/KrrPerson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties

@JsonIgnoreProperties(ignoreUnknown = true)
data class KrrPerson(
val reservert: Boolean? = true,
val epostadresse: String? = null,
val mobiltelefonnummer: String? = null
)
val reservert: Boolean? = true,
val epostadresse: String? = null,
val mobiltelefonnummer: String? = null
) {
companion object {
fun String?.validateEmail(): String? {
val emailRegex = Regex("""[\w.-]+@[\w.-]+\.[a-zA-Z]{2,15}""")
return if (this != null && emailRegex.matches(this)) this else null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import no.nav.eessi.pensjon.utils.mapJsonToAny
*
* services: pdl, person, pen, maybe joark, eux-basis.
*/
class PersonInfo(val norskIdent: String,
data class PersonInfo(val norskIdent: String,
val aktorId: String,
val reservert: Boolean? = true,
val epostKrr: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import no.nav.eessi.pensjon.prefill.InnhentingService
import no.nav.eessi.pensjon.prefill.PersonPDLMock
import no.nav.eessi.pensjon.prefill.PersonPDLMock.medFodsel
import no.nav.eessi.pensjon.prefill.models.EessiInformasjon
import no.nav.eessi.pensjon.prefill.models.KrrPerson.Companion.validateEmail
import no.nav.eessi.pensjon.prefill.models.PensjonCollection
import no.nav.eessi.pensjon.prefill.models.PersonDataCollection
import no.nav.eessi.pensjon.prefill.models.PrefillDataModelMother.initialPrefillDataModel
Expand Down Expand Up @@ -91,6 +92,19 @@ class PrefillP2000_AP_21975717Test {
assertEquals(prefillData.bruker.epostKrr, p2000.nav?.bruker?.person?.kontakt?.email?.get(0)?.adresse)
}

@Test
fun `forventet korrekt utfylt P2000 med telefonummer og uten epost som inkluderer underscore`() {
val edited = prefillData.copy(
bruker = prefillData.bruker.copy(
epostKrr = prefillData.bruker.epostKrr.validateEmail()
)
)
val p2000 = prefillSEDService.prefill(edited, persondataCollection, pensjonCollection)

assertEquals(edited.bruker.telefonKrr, p2000.nav?.bruker?.person?.kontakt?.telefon?.get(0)?.nummer)
assertEquals(edited.bruker.epostKrr, p2000.nav?.bruker?.person?.kontakt?.email?.get(0)?.adresse)
}


@Test
fun `forventet korrekt utfylt P2000 alderpersjon med mockdata fra testfiler`() {
Expand Down

0 comments on commit b1d967a

Please sign in to comment.