Skip to content

Commit

Permalink
Slett midlertidlig orgnrunderenhet key (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper-Hustad authored Nov 21, 2024
1 parent 3c847d9 commit d877299
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import no.nav.helsearbeidsgiver.felles.json.toMap
import no.nav.helsearbeidsgiver.felles.rapidsrivers.model.Fail
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.firstMessage
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.sendJson
import no.nav.helsearbeidsgiver.felles.test.shouldContainAllExcludingTempKey
import no.nav.helsearbeidsgiver.inntektsmelding.altinn.MockTilgang.toMap
import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.test.wrapper.genererGyldig
Expand Down Expand Up @@ -58,7 +57,7 @@ class TilgangRiverTest :

testRapid.inspektør.size shouldBeExactly 1

testRapid.firstMessage().toMap() shouldContainAllExcludingTempKey
testRapid.firstMessage().toMap() shouldContainExactly
mapOf(
Key.EVENT_NAME to innkommendeMelding.eventName.toJson(),
Key.KONTEKST_ID to innkommendeMelding.transaksjonId.toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class InntektSelvbestemtProducerTest :
mapOf(
Key.FNR to sykmeldtFnr.toJson(),
Key.ORGNRUNDERENHET to orgnr.toJson(),
Key.ORGNRUNDERENHET_V2 to orgnr.toJson(),
Key.INNTEKTSDATO to inntektsdato.toJson(),
).toJson(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ enum class Key(
VEDTAKSPERIODE_ID_LISTE("vedtaksperiode_id_liste"),
VIRKSOMHET("virksomhet"),
VIRKSOMHETER("virksomheter"),
ORGNRUNDERENHET("orgnr_underenhet"),

// ulik formattering
ORGNRUNDERENHET("orgnrUnderenhet"),
ORGNRUNDERENHET_V2("orgnr_underenhet"),
SPINN_INNTEKTSMELDING_ID("spinnInntektsmeldingId"),

;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,14 @@ import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonNull
import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.json.toMap
import no.nav.helsearbeidsgiver.utils.collection.mapValuesNotNull
import no.nav.helsearbeidsgiver.utils.json.parseJson
import no.nav.helsearbeidsgiver.utils.json.toJson

fun MessageContext.publish(vararg messageFields: Pair<Key, JsonElement>): JsonElement = publish(messageFields.toMap())

fun MessageContext.publish(messageFields: Map<Key, JsonElement>): JsonElement =
messageFields
.let { root ->
val data = root[Key.DATA]?.toMap().orEmpty()
val newData =
data
.plus(Key.ORGNRUNDERENHET_V2 to data[Key.ORGNRUNDERENHET])
.mapValuesNotNull { it }
.ifEmpty { null }
root
.plus(Key.ORGNRUNDERENHET_V2 to root[Key.ORGNRUNDERENHET])
.plus(Key.DATA to newData?.toJson())
.mapValuesNotNull { it }
}.mapKeys { (key, _) -> key.toString() }
.mapKeys { (key, _) -> key.toString() }
.filterValues { it !is JsonNull }
.toJson()
.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,99 +84,5 @@ class RiverUtilsKtTest :
)
}
}

test("duplikert verdi i ORGNRUNDERENHET_V2 nøkkel") {

val verdi = ("unik ORGNRUNDERENHET verdi " + UUID.randomUUID().toString()).toJson()

val melding =
mapOf(
Key.FORESPOERSEL_ID to UUID.randomUUID().toJson(),
Key.ORGNRUNDERENHET to verdi,
)

testRapid.publish(melding)

verifySequence {
testRapid.publish(
withArg<String> {
it.parseJson().toMap() shouldContainExactly melding.plus(Key.ORGNRUNDERENHET_V2 to verdi)
},
)
}
}

test("duplikert verdi i Data MapOf i ORGNRUNDERENHET_V2 nøkkel") {

val verdi = ("unik ORGNRUNDERENHET verdi " + UUID.randomUUID().toString()).toJson()

val melding =
mapOf(
Key.FORESPOERSEL_ID to UUID.randomUUID().toJson(),
Key.DATA to
mapOf(
Key.ORGNRUNDERENHET to verdi,
).toJson(),
)

testRapid.publish(melding)

val meldingMedDuplikert =
melding.plus(
Key.DATA to
mapOf(
Key.ORGNRUNDERENHET to verdi,
Key.ORGNRUNDERENHET_V2 to verdi,
).toJson(),
)

verifySequence {
testRapid.publish(
withArg<String> {
it.parseJson().toMap() shouldContainExactly meldingMedDuplikert
},
)
}
}

test("duplikert verdi i nøkkel og Data MapOf nøkkel") {

val verdi = ("unik ORGNRUNDERENHET verdi " + UUID.randomUUID().toString()).toJson()
val id = Key.FORESPOERSEL_ID to UUID.randomUUID().toJson()

val melding =
mapOf(
id,
Key.ORGNRUNDERENHET to verdi,
Key.DATA to
mapOf(
Key.ORGNRUNDERENHET to verdi,
).toJson(),
)

testRapid.publish(melding)

val meldingMedDuplikert =
mapOf(
id,
Key.ORGNRUNDERENHET to verdi,
Key.ORGNRUNDERENHET to verdi,
Key.ORGNRUNDERENHET_V2 to verdi,
Key.DATA to
mapOf(
Key.ORGNRUNDERENHET to verdi,
Key.ORGNRUNDERENHET_V2 to verdi,
).toJson(),
)

verifySequence {
testRapid.publish(
withArg<String> {

it.parseJson().toMap() shouldContainExactly meldingMedDuplikert
},
)
}
}
}
})
10 changes: 0 additions & 10 deletions felles/src/testFixtures/kotlin/Temp.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.sendJson
import no.nav.helsearbeidsgiver.inntekt.InntektKlient
import no.nav.helsearbeidsgiver.inntektsmelding.inntekt.Mock.toMap
import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.pipe.orDefault
import no.nav.helsearbeidsgiver.utils.test.date.april
import no.nav.helsearbeidsgiver.utils.test.date.august
import no.nav.helsearbeidsgiver.utils.test.date.januar
Expand Down Expand Up @@ -108,15 +107,7 @@ class HentInntektRiverTest :
Key.DATA to
innkommendeMelding.data
.plus(Key.INNTEKT to forventetInntekt.toJson(Inntekt.serializer()))
.let {
val verdi = innkommendeMelding.data[Key.ORGNRUNDERENHET].orDefault(JsonNull)

if (innkommendeMelding.data.containsKey(Key.ORGNRUNDERENHET)) {
it.plus(Key.ORGNRUNDERENHET_V2 to verdi)
} else {
it
}
}.toJson(),
.toJson(),
)

coVerifySequence {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.helsearbeidsgiver.inntektsmelding.integrasjonstest

import io.kotest.matchers.maps.shouldContainExactly
import io.kotest.matchers.nulls.shouldNotBeNull
import io.mockk.coEvery
import no.nav.helsearbeidsgiver.felles.BehovType
Expand All @@ -8,7 +9,6 @@ import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.domene.Inntekt
import no.nav.helsearbeidsgiver.felles.domene.InntektPerMaaned
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.test.shouldContainAllExcludingTempKey
import no.nav.helsearbeidsgiver.inntektsmelding.integrasjonstest.utils.EndToEndTest
import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.test.date.april
Expand Down Expand Up @@ -42,7 +42,7 @@ class InntektSelvbestemtIT : EndToEndTest() {
messages
.filter(BehovType.HENT_INNTEKT)
.firstAsMap()
.shouldContainAllExcludingTempKey(
.shouldContainExactly(
mapOf(
Key.EVENT_NAME to EventName.INNTEKT_SELVBESTEMT_REQUESTED.toJson(),
Key.BEHOV to BehovType.HENT_INNTEKT.toJson(),
Expand All @@ -59,7 +59,7 @@ class InntektSelvbestemtIT : EndToEndTest() {
messages
.filter(Key.INNTEKT)
.firstAsMap()
.shouldContainAllExcludingTempKey(
.shouldContainExactly(
mapOf(
Key.EVENT_NAME to EventName.INNTEKT_SELVBESTEMT_REQUESTED.toJson(),
Key.KONTEKST_ID to Mock.transaksjonId.toJson(),
Expand Down

0 comments on commit d877299

Please sign in to comment.