Skip to content

Commit

Permalink
🤡 LocalApp er mer lik RapidApp i rekkefølgen av initialisering
Browse files Browse the repository at this point in the history
  • Loading branch information
chsko committed Oct 30, 2024
1 parent 033b9c0 commit 1a15e2f
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions spesialist-selve/src/test/kotlin/no/nav/helse/LocalApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,45 @@ import org.testcontainers.containers.PostgreSQLContainer
import java.util.UUID

fun main() {
val mockOAuth2Server = MockOAuth2Server()
mockOAuth2Server.start()
val clientId = "en-client-id"
val issuerId = "LocalTestIssuer"
val token =
LocalApp.start()
}

object LocalApp {

// Simulerer RapidApp, der SpesialistApp (som trenger RapidsConnection) først gis
// til RapidApplicationBuildern, og deretter får ut en RapidsConnection, dvs. at RapidsConnection er en
// lateinit var
@Suppress("JoinDeclarationAndAssignment")
private lateinit var testRapid: TestRapid

private val mockOAuth2Server = MockOAuth2Server()
private val clientId = "en-client-id"
private val issuerId = "LocalTestIssuer"
private val token =
mockOAuth2Server.issueToken(
issuerId = issuerId,
audience = clientId,
claims =
mapOf(
"preferred_username" to "[email protected]",
"oid" to "${UUID.randomUUID()}",
"name" to "En Saksbehandler",
"NAVident" to "X123456",
),
).serialize()
println("OAuth2-token: $token")
val azureConfig =
mapOf(
"preferred_username" to "[email protected]",
"oid" to "${UUID.randomUUID()}",
"name" to "En Saksbehandler",
"NAVident" to "X123456",
),
).serialize().also {
println("OAuth2-token:")
println(it)
}

private val azureConfig =
AzureConfig(
clientId = clientId,
issuerUrl = mockOAuth2Server.issuerUrl(issuerId).toString(),
jwkProviderUri = mockOAuth2Server.jwksUrl(issuerId).toString(),
tokenEndpoint = mockOAuth2Server.tokenEndpointUrl(issuerId).toString(),
)

val spesialistApp =
private val spesialistApp =
SpesialistApp(
env = Environment(database.envvars + mapOf("LOKAL_UTVIKLING" to "true")),
gruppekontroll = gruppekontroll,
Expand All @@ -62,10 +75,10 @@ fun main() {
reservasjonClient = reservasjonClient,
versjonAvKode = "versjon_1",
) {
TestRapid()
testRapid
}

val server =
private val server =
embeddedServer(CIO, port = 4321) {
spesialistApp.ktorApp(this)
routing {
Expand All @@ -74,8 +87,15 @@ fun main() {
}
}
}
spesialistApp.start()
server.start(wait = true)

init {
testRapid = TestRapid()
}

fun start() {
spesialistApp.start()
server.start(wait = true)
}
}

private val snapshotClient =
Expand Down

0 comments on commit 1a15e2f

Please sign in to comment.