Skip to content

Commit

Permalink
Bruke inntekt kontrakt fra https://github.com/navikt/dp-inntekt
Browse files Browse the repository at this point in the history
  • Loading branch information
geiralund committed Dec 20, 2023
1 parent bc6f18f commit 137aa91
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
20 changes: 11 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ dependencies {
}
}
implementation(kotlin("stdlib-jdk8"))
implementation(Dagpenger.Streams)
implementation("com.github.navikt:dagpenger-events:20231204.ee1cc3")
implementation("com.github.navikt:dagpenger-streams:20231220.ec218b")
implementation("com.github.navikt:dp-inntekt-kontrakter:1_20231220.55a8a9")
implementation("com.github.navikt:dagpenger-events:20231220.3050bf")

implementation(Jackson.core)
implementation(Jackson.kotlin)
Expand Down Expand Up @@ -137,13 +138,14 @@ tasks.withType<Test> {
showStackTraces = true
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
events = setOf(
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.FAILED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR
)
events =
setOf(
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.FAILED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR,
)
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/main/kotlin/no/nav/dagpenger/regel/api/models/Inntekt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package no.nav.dagpenger.regel.api.models

import com.fasterxml.jackson.core.type.TypeReference
import no.nav.dagpenger.events.Packet
import no.nav.dagpenger.events.inntekt.v1.Inntekt
import no.nav.dagpenger.inntekt.v1.Inntekt
import no.nav.dagpenger.regel.api.serder.jacksonObjectMapper
import java.time.YearMonth

internal enum class PeriodeNumber(val number: Int) {
ONE(1), TWO(2), THREE(3)
ONE(1),
TWO(2),
THREE(3),
}

data class InntektsPeriode(
val førsteMåned: YearMonth, // todo: rename and create test that verifies the name
val sisteMåned: YearMonth // todo: rename and create test that verifies the name
val sisteMåned: YearMonth, // todo: rename and create test that verifies the name
) {
companion object Mapper {

fun fromPacket(packet: Packet): InntektsPeriode? =
packet.getNullableObjectValue(PacketKeys.BRUKT_INNTEKTSPERIODE) { json: Any ->
jacksonObjectMapper.convertValue(json, InntektsPeriode::class.java)
Expand All @@ -24,16 +25,17 @@ data class InntektsPeriode(
fun toJson(inntektsPeriode: InntektsPeriode): Any {
return jacksonObjectMapper.convertValue(
inntektsPeriode,
object : TypeReference<Map<String, String>>() {}
object : TypeReference<Map<String, String>>() {},
)
}
}

fun toJson(): Any = toJson(this)
}

internal fun inntektFrom(packet: Packet): Inntekt? = packet.getNullableObjectValue(PacketKeys.INNTEKT) { json ->
jacksonObjectMapper.convertValue(json, Inntekt::class.java)
}
internal fun inntektFrom(packet: Packet): Inntekt? =
packet.getNullableObjectValue(PacketKeys.INNTEKT) { json ->
jacksonObjectMapper.convertValue(json, Inntekt::class.java)
}

internal fun Inntekt.harAvvik(): Boolean = this.inntektsListe.any { it.harAvvik ?: false }
48 changes: 24 additions & 24 deletions src/test/kotlin/no/nav/dagpenger/regel/api/models/InntektTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package no.nav.dagpenger.regel.api.models
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import no.nav.dagpenger.events.Packet
import no.nav.dagpenger.events.inntekt.v1.Inntekt
import no.nav.dagpenger.events.inntekt.v1.KlassifisertInntektMåned
import no.nav.dagpenger.inntekt.v1.Inntekt
import no.nav.dagpenger.inntekt.v1.KlassifisertInntektMåned
import org.junit.jupiter.api.Test
import java.time.YearMonth

internal class InntektsPeriodeTest {

@Test
fun `Mapping to JSON`() {
InntektsPeriode(YearMonth.of(2019, 1), YearMonth.of(2019, 2)).toJson().let {
Expand All @@ -23,15 +22,16 @@ internal class InntektsPeriodeTest {

@Test
fun `Mapping from Packet`() {
val inntektsPeriode = Packet().apply {
putValue(
PacketKeys.BRUKT_INNTEKTSPERIODE,
mapOf(
Pair("førsteMåned", "2019-01"),
Pair("sisteMåned", "2019-02")
val inntektsPeriode =
Packet().apply {
putValue(
PacketKeys.BRUKT_INNTEKTSPERIODE,
mapOf(
Pair("førsteMåned", "2019-01"),
Pair("sisteMåned", "2019-02"),
),
)
)
}.let { InntektsPeriode.fromPacket(it) }
}.let { InntektsPeriode.fromPacket(it) }

inntektsPeriode shouldNotBe null
inntektsPeriode?.førsteMåned shouldBe YearMonth.of(2019, 1)
Expand All @@ -40,7 +40,6 @@ internal class InntektsPeriodeTest {
}

internal class InntektTest {

@Test
fun `Extension function harAvvik`() {
val avvik = KlassifisertInntektMåned(YearMonth.now(), listOf(), true)
Expand All @@ -53,19 +52,20 @@ internal class InntektTest {

@Test
fun `Mapping from Packet`() {
val inntekt = inntektFrom(
Packet().apply {
putValue(
PacketKeys.INNTEKT,
mapOf(
Pair("inntektsId", "id"),
Pair("inntektsListe", listOf<String>()),
Pair("manueltRedigert", true),
Pair("sisteAvsluttendeKalenderMåned", YearMonth.now().toString())
val inntekt =
inntektFrom(
Packet().apply {
putValue(
PacketKeys.INNTEKT,
mapOf(
Pair("inntektsId", "id"),
Pair("inntektsListe", listOf<String>()),
Pair("manueltRedigert", true),
Pair("sisteAvsluttendeKalenderMåned", YearMonth.now().toString()),
),
)
)
}
)
},
)

inntekt shouldNotBe null
inntekt?.let {
Expand Down

0 comments on commit 137aa91

Please sign in to comment.