Skip to content

Commit

Permalink
Altinn maskinporten (#618)
Browse files Browse the repository at this point in the history
* Bruk service med steg i SpinnService (#602)

* Fiks dependency submission (#603)

* Bruk service med steg i LagreSelvbestemtImService (#605)

* Revert "disabler selvbestemt innsending-endepunkt i produksjon (#584)"

This reverts commit 5503bc9.

* MaskinportenConfig (#617)

* Bruk service med steg i KvitteringService (#606)

* Refaktorering

* Refaktorering

---------

Co-authored-by: Mikael Bjerga <[email protected]>
Co-authored-by: Mikael Bjerga <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent afe3438 commit dad814d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
1 change: 0 additions & 1 deletion altinn/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ dependencies {
implementation("no.nav.helsearbeidsgiver:maskinporten-client:$maskinportenClientVersion")
testImplementation("com.nimbusds:nimbus-jose-jwt:$nimbusJoseJwtVersion")
testImplementation("com.squareup.okhttp3:mockwebserver:$mockwebserverVersion")

}
2 changes: 2 additions & 0 deletions altinn/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mockwebserverVersion=5.0.0-alpha.14
nimbusJoseJwtVersion=9.40
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@ package no.nav.helsearbeidsgiver.inntektsmelding.altinn

import com.nimbusds.jose.jwk.gen.RSAKeyGenerator
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.ints.shouldBeExactly
import io.kotest.matchers.maps.shouldContainExactly
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldStartWith
import io.mockk.clearAllMocks
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.mockkStatic
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import io.mockk.unmockkStatic
import no.nav.helse.rapids_rivers.RapidApplication
import no.nav.helse.rapids_rivers.testsupport.TestRapid
import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.altinn.AltinnOrganisasjon
import no.nav.helsearbeidsgiver.felles.fromEnv
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.json.toMap
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.firstMessage
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.sendJson
import no.nav.helsearbeidsgiver.inntektsmelding.altinn.Mock.altinnOrganisasjoner
import no.nav.helsearbeidsgiver.inntektsmelding.altinn.Mock.innkommendeMelding
Expand All @@ -38,23 +31,26 @@ class AltinnAppTest :
beforeEach {
server = MockWebServer()
server.start()
val baseUrl = server.url("/").toString()
println("baseUrl== $baseUrl")
}
afterEach { clearAllMocks() }
afterEach {
clearAllMocks()
unmockkStatic("no.nav.helsearbeidsgiver.felles.EnvUtilsKt")
testRapid.reset()
server.shutdown()
}

test("tester at Altinn client og maskinporten kaller riktig endepunkt og sender riktig data") {
mockkObject(RapidApplication)
every { RapidApplication.create(any()) } returns testRapid

val maskinportenToken = TokenResponse("test_token", "Bearer", 3600, "test:test1")
val tokenResponse = Json.encodeToString(TokenResponse.serializer(), maskinportenToken)
val tokenResponse = maskinportenToken.toJson(TokenResponse.serializer()).toString()
server.enqueue(
MockResponse()
.setBody(tokenResponse)
.addHeader("Content-Type", "application/json"),
)
val altinnResponse = Json.encodeToString(altinnOrganisasjoner)
val altinnResponse = altinnOrganisasjoner.toJson(AltinnOrganisasjon.serializer().set()).toString()
val mockResponse =
MockResponse()
.setBody(altinnResponse)
Expand All @@ -69,23 +65,6 @@ class AltinnAppTest :

testRapid.sendJson(innkommendeMelding.toMap())

testRapid.inspektør.size shouldBeExactly 1

val altinnOrgnr =
altinnOrganisasjoner
.mapNotNull { it.orgnr }
.toSet()

testRapid.firstMessage().toMap() shouldContainExactly
mapOf(
Key.EVENT_NAME to innkommendeMelding.eventName.toJson(),
Key.UUID to innkommendeMelding.transaksjonId.toJson(),
Key.DATA to
innkommendeMelding.data
.plus(
Key.ORG_RETTIGHETER to altinnOrgnr.toJson(String.serializer().set()),
).toJson(),
)
val tokenRequest = server.takeRequest()
tokenRequest.path shouldBe "/token"
tokenRequest.method shouldBe "POST"
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ mockkVersion=1.13.11
rapidsAndRiversVersion=2024061408021718344972.64ebbdb34321
tokenProviderVersion=0.4.0
utilsVersion=0.9.0
mockwebserverVersion=5.0.0-alpha.14
nimbusJoseJwtVersion=9.40

# Client dependency versions
aaregClientVersion=0.7.0
Expand Down

0 comments on commit dad814d

Please sign in to comment.