Skip to content

Commit

Permalink
Bugfix/underholdskostnad (#625)
Browse files Browse the repository at this point in the history
* Underholdskostnad: Validere at oppgitt personident for andre barn eksisterer i PDL
  • Loading branch information
s148719 authored Dec 2, 2024
1 parent 5a0b099 commit b823e26
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class UnderholdService(
private val personRepository: PersonRepository,
private val notatService: NotatService,
private val dtomapper: Dtomapper,
private val personService: PersonService,
) {
fun oppdatereBegrunnelse(
behandling: Behandling,
Expand Down Expand Up @@ -118,7 +119,7 @@ class UnderholdService(
behandling: Behandling,
gjelderBarn: BarnDto,
): Underholdskostnad {
gjelderBarn.validere(behandling)
gjelderBarn.validere(behandling, personService)

return gjelderBarn.personident?.let { personidentBarn ->
val rolleSøknadsbarn = behandling.søknadsbarn.find { it.ident == personidentBarn.verdi }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import no.nav.bidrag.behandling.dto.v2.underhold.StønadTilBarnetilsynDto
import no.nav.bidrag.behandling.dto.v2.underhold.Underholdselement
import no.nav.bidrag.behandling.dto.v2.underhold.ValideringsfeilUnderhold
import no.nav.bidrag.behandling.ressursIkkeFunnetException
import no.nav.bidrag.behandling.service.PersonService
import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpClientErrorException

Expand All @@ -24,7 +25,10 @@ fun OppdatereUnderholdRequest.validere() {
}
}

fun BarnDto.validere(behandling: Behandling) {
fun BarnDto.validere(
behandling: Behandling,
personService: PersonService,
) {
if ((navn.isNullOrBlank() || fødselsdato == null) && (personident == null || personident.verdi.isEmpty())) {
throw HttpClientErrorException(
HttpStatus.BAD_REQUEST,
Expand Down Expand Up @@ -57,6 +61,12 @@ fun BarnDto.validere(behandling: Behandling) {
"Det finnes allerede underhold for barn med samme navn og fødselsdato i behandling ${behandling.id}.",
)
}

this.personident?.let {
if (personService.hentPerson(it.verdi) == null) {
throw HttpClientErrorException(HttpStatus.BAD_REQUEST, "Fant ikke barn med oppgitt personident.")
}
}
}

fun SletteUnderholdselement.validere(behandling: Behandling) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ abstract class CommonVedtakTilBehandlingTest {
personRepository,
notatService,
dtomapper,
personService,
)
val vedtakTilBehandlingMapping = VedtakTilBehandlingMapping(validerBeregning, underholdService = underholdService)
beregningService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class UnderholdServiceTest {
personRepository,
notatService,
dtomapper,
personService,
)

stubUnderholdskostnadRepository(underholdskostnadRepository)
Expand Down Expand Up @@ -391,6 +392,31 @@ class UnderholdServiceTest {
//
respons.statusCode shouldBe HttpStatus.CONFLICT
}

@Test
open fun `feil dersom barns personident ikke finnes`() {
// gitt
val personidentBarn = "12345678910"
every { personConsumer.hentPerson(personidentBarn) }.throws(HttpClientErrorException(HttpStatus.NOT_FOUND))

val behandling =
oppretteTestbehandling(
setteDatabaseider = true,
inkludereBp = true,
behandlingstype = TypeBehandling.BIDRAG,
)

val request = BarnDto(personident = Personident(personidentBarn))

// hvis
val respons =
assertFailsWith<HttpClientErrorException> {
underholdService.oppretteUnderholdskostnad(behandling, request)
}

//
respons.statusCode shouldBe HttpStatus.BAD_REQUEST
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class VedtakserviceTest : TestContainerRunner() {
personRepository,
notatService,
dtomapper,
personService,
)
val vedtakTilBehandlingMapping = VedtakTilBehandlingMapping(validerBeregning, underholdService)

Expand Down

0 comments on commit b823e26

Please sign in to comment.