Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEK-1081 Use brukFremtidigInntekt flag #79

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object TpoFolketrygdberegnetAfpSpecMapperV0 {
foedselAar = 0,
utlandAntallAar = source.utenlandsopphold ?: 0,
utlandPeriodeListe = mutableListOf(),
fremtidigInntektListe = null, // NB: not mutableListOf()
fremtidigInntektListe = mutableListOf(),
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0, // used for anonym only
flyktning = null,
epsHarInntektOver2G = source.eps2G == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object FolketrygdberegnetAfpSpecMapperV1 {
foedselAar = 0,
utlandAntallAar = source.utenlandsopphold ?: 0,
utlandPeriodeListe = mutableListOf(),
fremtidigInntektListe = null, // NB: not mutableListOf()
fremtidigInntektListe = mutableListOf(),
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0, // used for anonym only
flyktning = null,
epsHarInntektOver2G = source.eps2G == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class LivsvarigOffentligAfpService(
pid: Pid,
foedselsdato: LocalDate,
forventetAarligInntektBeloep: Int,
fremtidigeInntekter: List<FremtidigInntekt>?,
fremtidigeInntekter: List<FremtidigInntekt>,
brukFremtidigInntekt: Boolean,
virkningDato: LocalDate,
): LivsvarigOffentligAfpResult? {
if (valid(foedselsdato.year, virkningDato.year).not()) return null
Expand All @@ -33,8 +34,8 @@ class LivsvarigOffentligAfpService(
val til: LocalDate = sisteAarMedAfpOpptjeningInntekt(foedselsdato)

val fremtidigInntektListe: List<Inntekt> =
fremtidigeInntekter?.map { Inntekt(it.aarligInntektBeloep, it.fom) }
?: forventedeInntekter(fom, til, forventetAarligInntektBeloep)
if (brukFremtidigInntekt) fremtidigeInntekter.map { Inntekt(it.aarligInntektBeloep, it.fom) }
else forventedeInntekter(fom, til, forventetAarligInntektBeloep)

return client.simuler(
LivsvarigOffentligAfpSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object AlderspensjonSpecMapper {
utlandAntallAar = source.antallAarUtenlandsEtter16,
utlandPeriodeListe = mutableListOf(), // utenlandsopphold is in V4 specified by utlandAntallAar
fremtidigInntektListe = source.fremtidigInntektListe.map(::fremtidigInntekt).toMutableList(),
brukFremtidigInntekt = true,
inntektOver1GAntallAar = 0,
flyktning = false,
epsHarInntektOver2G = source.epsHarInntektOver2G,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ object NavSimuleringSpecMapperV3 {
flyktning = false,
utlandPeriodeListe = utlandPeriodeListe.toMutableList(),
// Inntekt angis før/etter gradert/helt uttak istedenfor via liste:
fremtidigInntektListe = null, // NB: Must be null (not empty list)
fremtidigInntektListe = mutableListOf(),
brukFremtidigInntekt = false,
rettTilOffentligAfpFom = null,
afpOrdning = null,
afpInntektMaanedFoerUttak = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ object AnonymSimuleringSpecMapperV1 {
simulerForTp = false,
flyktning = false,
utlandPeriodeListe = mutableListOf(),
fremtidigInntektListe = null, // NB: not mutableListOf()
fremtidigInntektListe = mutableListOf(),
brukFremtidigInntekt = false,
rettTilOffentligAfpFom = null,
afpOrdning = null,
afpInntektMaanedFoerUttak = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ object NavSimuleringSpecMapperV2 {
foedselAar = source.fodselsar ?: 0,
utlandAntallAar = source.utenlandsopphold ?: 0,
utlandPeriodeListe = source.utenlandsperiodeForSimuleringList.map(::utlandPeriode).toMutableList(),
fremtidigInntektListe = null, // not used in PSELV; NB: not mutableListOf()
fremtidigInntektListe = mutableListOf(),
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0, // used for anonym only
flyktning = source.flyktning,
epsHarInntektOver2G = source.eps2G == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ object TpoSimuleringSpecMapperV1 {
foedselAar = 0,
utlandAntallAar = source.utenlandsopphold ?: 0,
utlandPeriodeListe = mutableListOf(),
fremtidigInntektListe = null, // V2, V3 only; NB: not mutableListOf()
fremtidigInntektListe = mutableListOf(), // V2, V3 only
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0,
flyktning = null,
epsHarInntektOver2G = source.eps2G == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object TpoSimuleringSpecMapperV2 {
utlandPeriodeListe = mutableListOf(),
fremtidigInntektListe = source.fremtidigInntektList.orEmpty()
.map(TpoSimuleringSpecMapperV2::inntekt).toMutableList(), // V2, V3 only
brukFremtidigInntekt = true,
inntektOver1GAntallAar = 0,
flyktning = null,
epsHarInntektOver2G = source.eps2G == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object TpoSimuleringSpecMapperV3 {
utlandAntallAar = source.utenlandsopphold ?: 0,
utlandPeriodeListe = mutableListOf(),
fremtidigInntektListe = source.fremtidigInntektList.orEmpty().map(::inntekt).toMutableList(),
brukFremtidigInntekt = true,
inntektOver1GAntallAar = 0,
flyktning = null,
epsHarInntektOver2G = source.eps2G == true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import no.nav.pensjon.simulator.tech.web.BadRequestException
object SimuleringSpecValidator {

fun validate(spec: SimuleringSpec){
spec.fremtidigInntektListe?.let(::validateInntekt)
validateInntekt(spec.fremtidigInntektListe)
validateUttak(spec)
}

Expand All @@ -34,9 +34,5 @@ object SimuleringSpecValidator {
if (spec.foersteUttakDato.isAfter(spec.heltUttakDato))
throw BadRequestException("Andre uttak (100 %) starter ikke etter første uttak (gradert)")
}

// if (spec.heltUttakDato?.let { spec.foersteUttakDato.isAfter(it).not() } == true) {
// throw BadRequestException("Andre uttak (100 %) starter ikke etter første uttak (gradert)")
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class FolketrygdBeholdningService(
epsHarPensjon = beholdningSpec.epsHarPensjon,
epsHarInntektOver2G = beholdningSpec.epsHarInntektOver2G,
fremtidigInntektListe = beholdningSpec.fremtidigInntektListe.map(::fremtidigInntekt).toMutableList(),
brukFremtidigInntekt = true,
type = if (erFoerstegangsuttak) SimuleringType.ALDER else SimuleringType.ENDR_ALDER, // inkluderAfpPrivat = false
foedselAar = 0, // only for anonym
forventetInntektBeloep = 0, // inntekt instead given by fremtidigInntektListe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class SimulatorCore(
foedselsdato = it,
forventetAarligInntektBeloep = spec.forventetInntektBeloep,
fremtidigeInntekter = spec.fremtidigInntektListe,
brukFremtidigInntekt = spec.brukFremtidigInntekt,
virkningDato = spec.rettTilOffentligAfpFom ?: spec.foersteUttakDato!!
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,9 @@ class KravhodeCreator(
}

val persongrunnlag = kravhode.hentPersongrunnlagForSoker()
val brukFremtidigInntekt = spec.fremtidigInntektListe != null // NB: true if empty list
val inntektListe: MutableList<Inntekt>

if (brukFremtidigInntekt) {
if (spec.brukFremtidigInntekt) {
val gjeldendeAar = SISTE_GYLDIGE_OPPTJENING_AAR + 1
val sisteOpptjeningAar = MAX_OPPTJENING_ALDER + foedselAar(person, spec)
val fom: LocalDate = foersteDag(gjeldendeAar)
Expand Down Expand Up @@ -708,7 +707,7 @@ class KravhodeCreator(
sisteOpptjeningAar: Int,
fom: LocalDate
): List<Inntektsgrunnlag> {
val fremtidigInntektListe = spec.fremtidigInntektListe ?: mutableListOf()
val fremtidigInntektListe = spec.fremtidigInntektListe

// NB: The original fremtidigInntektListe is here modified (as is done in PEN):
if (fremtidigInntektListe.isEmpty() || doesNotHaveFremtidigInntektBeforeFom(spec, fom)) {
Expand Down Expand Up @@ -772,7 +771,7 @@ class KravhodeCreator(
}

private fun doesNotHaveFremtidigInntektBeforeFom(spec: SimuleringSpec, fom: LocalDate) =
spec.fremtidigInntektListe.orEmpty().none { isBeforeByDay(it.fom, fom, true) }
spec.fremtidigInntektListe.none { isBeforeByDay(it.fom, fom, true) }

private fun foedselsdato(person: PenPerson?, spec: SimuleringSpec): LocalDate =
person?.foedselsdato ?: spec.foedselDato ?: foersteDag(spec.foedselAar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class SimuleringSpec(
val foedselAar: Int,
val utlandAntallAar: Int, // PEN: SimuleringEtter2011.utenlandsopphold
val utlandPeriodeListe: MutableList<UtlandPeriode>,
val fremtidigInntektListe: MutableList<FremtidigInntekt>?, // must be nullable
val fremtidigInntektListe: MutableList<FremtidigInntekt>,
val brukFremtidigInntekt: Boolean,
val inntektOver1GAntallAar: Int,
val flyktning: Boolean?,
val epsHarInntektOver2G: Boolean,
Expand Down Expand Up @@ -130,6 +131,7 @@ data class SimuleringSpec(
utlandAntallAar = utlandAntallAar,
utlandPeriodeListe = utlandPeriodeListe,
fremtidigInntektListe = fremtidigInntektListe,
brukFremtidigInntekt = brukFremtidigInntekt,
inntektOver1GAntallAar = inntektOver1GAntallAar,
flyktning = flyktning,
epsHarInntektOver2G = epsHarInntektOver2G,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ object SimuleringSpecUtil {
utlandAntallAar = source.utlandAntallAar,
utlandPeriodeListe = source.utlandPeriodeListe,
fremtidigInntektListe = source.fremtidigInntektListe,
brukFremtidigInntekt = source.brukFremtidigInntekt,
inntektOver1GAntallAar = source.inntektOver1GAntallAar,
flyktning = source.flyktning,
epsHarInntektOver2G = source.epsHarInntektOver2G,
Expand Down Expand Up @@ -127,6 +128,7 @@ object SimuleringSpecUtil {
utlandAntallAar = source.utlandAntallAar,
utlandPeriodeListe = source.utlandPeriodeListe,
fremtidigInntektListe = source.fremtidigInntektListe,
brukFremtidigInntekt = source.brukFremtidigInntekt,
inntektOver1GAntallAar = source.inntektOver1GAntallAar,
flyktning = source.flyktning,
epsHarInntektOver2G = source.epsHarInntektOver2G,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ object UttakSpecMapperV1 {
utlandAntallAar = 0, // not taken into account
utlandPeriodeListe = mutableListOf(), // not taken into account
fremtidigInntektListe = source.fremtidigInntektListe.orEmpty().map(::inntekt).toMutableList(),
brukFremtidigInntekt = true,
inntektOver1GAntallAar = 0,
flyktning = false,
epsHarInntektOver2G = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class LivsvarigOffentligAfpServiceTest : FunSpec({
pid,
foedselsdato = LocalDate.of(1962, 12, 31),
forventetAarligInntektBeloep = 0,
fremtidigeInntekter = null,
fremtidigeInntekter = emptyList(),
brukFremtidigInntekt = false,
virkningDato
) shouldBe null

Expand All @@ -37,7 +38,8 @@ class LivsvarigOffentligAfpServiceTest : FunSpec({
pid,
foedselsdato = LocalDate.of(1970, 1, 1),
forventetAarligInntektBeloep = 0,
fremtidigeInntekter = null,
fremtidigeInntekter = emptyList(),
brukFremtidigInntekt = false,
virkningDato = LocalDate.of(2031, 12, 31)
) shouldBe null

Expand All @@ -49,7 +51,8 @@ class LivsvarigOffentligAfpServiceTest : FunSpec({
pid,
foedselsdato,
forventetAarligInntektBeloep = 123000,
fremtidigeInntekter = null,
fremtidigeInntekter = emptyList(),
brukFremtidigInntekt = false,
virkningDato
)

Expand All @@ -72,6 +75,7 @@ class LivsvarigOffentligAfpServiceTest : FunSpec({
foedselsdato,
forventetAarligInntektBeloep = 123000,
fremtidigeInntekter = emptyList(),
brukFremtidigInntekt = true,
virkningDato
)

Expand All @@ -94,6 +98,7 @@ class LivsvarigOffentligAfpServiceTest : FunSpec({
FremtidigInntekt(aarligInntektBeloep = 234000, fom = LocalDate.of(2024, 2, 1)),
FremtidigInntekt(aarligInntektBeloep = 123000, fom = LocalDate.of(2025, 3, 1))
),
brukFremtidigInntekt = true,
virkningDato
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private fun simuleringSpec(type: SimuleringType, livsvarigOffentligAfpRettFom: L
fom = LocalDate.of(2029, 5, 6)
)
),
brukFremtidigInntekt = true,
inntektOver1GAntallAar = 0,
flyktning = false,
epsHarInntektOver2G = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class NavSimuleringSpecMapperV3Test : FunSpec({
arbeidet = true
)
),
fremtidigInntektListe = null, // null in this context
fremtidigInntektListe = mutableListOf(), // empty in this context
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0,
flyktning = false,
epsHarInntektOver2G = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class NavSimuleringSpecMapperV2Test : FunSpec({
arbeidet = true
)
),
fremtidigInntektListe = null, // ikke brukt i PSELV
fremtidigInntektListe = mutableListOf(), // ikke brukt i PSELV
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0, // kun for anonym simulering
flyktning = false,
epsHarInntektOver2G = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package no.nav.pensjon.simulator.alderspensjon.spec

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import no.nav.pensjon.simulator.core.krav.FremtidigInntekt
import no.nav.pensjon.simulator.tech.web.BadRequestException
import no.nav.pensjon.simulator.testutil.TestObjects.simuleringSpec
import java.time.LocalDate

class SimuleringSpecValidatorTest : FunSpec({

test("validate should throw exception if: En fremtidig inntekt har f.o.m.-dato som ikke er den 1. i måneden") {
shouldThrow<BadRequestException> {
SimuleringSpecValidator.validate(
simuleringSpec(
inntektSpecListe = listOf(
FremtidigInntekt(
aarligInntektBeloep = 1,
fom = LocalDate.of(2025, 1, 2) // ikke den 1. i måneden
)
)
)
)
}.message shouldBe "En fremtidig inntekt har f.o.m.-dato som ikke er den 1. i måneden"
}

test("validate should throw exception if: To fremtidige inntekter har samme f.o.m.-dato") {
shouldThrow<BadRequestException> {
SimuleringSpecValidator.validate(
simuleringSpec(
inntektSpecListe = listOf(
FremtidigInntekt(
aarligInntektBeloep = 1,
fom = LocalDate.of(2025, 1, 1)
),
FremtidigInntekt(
aarligInntektBeloep = 2,
fom = LocalDate.of(2025, 1, 1) // samme f.o.m.-dato
)
)
)
)
}.message shouldBe "To fremtidige inntekter har samme f.o.m.-dato"
}

test("validate should throw exception if: Dato for første uttak mangler") {
shouldThrow<BadRequestException> {
SimuleringSpecValidator.validate(
simuleringSpec(foersteUttakDato = null)
)
}.message shouldBe "Dato for første uttak mangler"
}

test("validate should throw exception if: Andre uttak (100 %) starter ikke etter første uttak (gradert)") {
shouldThrow<BadRequestException> {
SimuleringSpecValidator.validate(
simuleringSpec(
foersteUttakDato = LocalDate.of(2032, 6, 2)
// heltUttakDato = LocalDate.of(2032, 6, 1) // starter ikke etter første uttak
)
)
}.message shouldBe "Andre uttak (100 %) starter ikke etter første uttak (gradert)"
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private fun simuleringSpec() =
fom = LocalDate.of(2027, 8, 1)
)
),
brukFremtidigInntekt = true,
type = SimuleringType.ALDER,
foedselAar = 0, // only for anonym
forventetInntektBeloep = 0, // inntekt instead given by fremtidigInntektListe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private fun simuleringSpec(utlandPeriodeListe: MutableList<UtlandPeriode>) =
foedselAar = 0,
utlandAntallAar = 0,
utlandPeriodeListe = utlandPeriodeListe,
fremtidigInntektListe = null,
fremtidigInntektListe = mutableListOf(),
brukFremtidigInntekt = false,
inntektOver1GAntallAar = 0,
flyktning = null,
epsHarInntektOver2G = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ object TestObjects {
type: SimuleringType = SimuleringType.ALDER_M_AFP_PRIVAT,
sivilstatus: SivilstatusType = SivilstatusType.UGIF,
epsHarPensjon: Boolean = false,
foersteUttakDato: LocalDate? = LocalDate.of(2029, 1, 1),
inntektSpecListe: List<FremtidigInntekt> = emptyList()
) = SimuleringSpec(
type,
sivilstatus,
epsHarPensjon,
foersteUttakDato = LocalDate.of(2029, 1, 1),
foersteUttakDato,
heltUttakDato = LocalDate.of(2032, 6, 1),
pid = pid,
foedselDato = null,
Expand Down Expand Up @@ -67,6 +68,7 @@ object TestObjects {
)
),
fremtidigInntektListe = inntektSpecListe.toMutableList(),
brukFremtidigInntekt = true,
inntektOver1GAntallAar = 0,
flyktning = false,
epsHarInntektOver2G = true,
Expand Down
Loading