|
| 1 | +package no.nav.hjelpemidler.api |
| 2 | + |
| 3 | +import io.ktor.client.request.bearerAuth |
| 4 | +import io.ktor.client.request.post |
| 5 | +import io.ktor.client.request.setBody |
| 6 | +import io.ktor.http.ContentType |
| 7 | +import io.ktor.http.HttpStatusCode |
| 8 | +import io.ktor.http.contentType |
| 9 | +import io.ktor.serialization.jackson.jackson |
| 10 | +import io.ktor.server.auth.Authentication |
| 11 | +import io.ktor.server.auth.authenticate |
| 12 | +import io.ktor.server.plugins.contentnegotiation.ContentNegotiation |
| 13 | +import io.ktor.server.testing.ApplicationTestBuilder |
| 14 | +import io.ktor.server.testing.testApplication |
| 15 | +import io.mockk.mockk |
| 16 | +import io.mockk.verify |
| 17 | +import no.nav.hjelpemidler.Context |
| 18 | +import no.nav.hjelpemidler.shouldBe |
| 19 | +import no.nav.hjelpemidler.token |
| 20 | +import kotlin.test.Test |
| 21 | + |
| 22 | +internal class RekvisisjonAPITest { |
| 23 | + |
| 24 | + private val context = Context(mockk(relaxed = true)) |
| 25 | + |
| 26 | + @Test |
| 27 | + internal fun `sender ut rekvisisjon på rapid`() = testApplication { |
| 28 | + configure() |
| 29 | + val body = context.jsonMapper.writeValueAsString( |
| 30 | + RekvisisjonKvittering( |
| 31 | + id = "1", |
| 32 | + saksnummer = "2", |
| 33 | + ordrenummer = "3", |
| 34 | + system = "HOTSAK", |
| 35 | + status = "ENTERED" |
| 36 | + ) |
| 37 | + ) |
| 38 | + client.post("/rekvisisjon-kvittering") { |
| 39 | + bearerAuth("qwer1234") |
| 40 | + contentType(ContentType.Application.Json) |
| 41 | + setBody(body) |
| 42 | + }.apply { |
| 43 | + status shouldBe HttpStatusCode.OK |
| 44 | + verify { |
| 45 | + context.publish("2", match { it.contains(body) }) |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + private fun ApplicationTestBuilder.configure() { |
| 51 | + install(ContentNegotiation) { |
| 52 | + jackson() |
| 53 | + } |
| 54 | + install(Authentication) { |
| 55 | + token("oebsToken") { |
| 56 | + validate("qwer1234") |
| 57 | + } |
| 58 | + } |
| 59 | + routing { |
| 60 | + authenticate("oebsToken") { |
| 61 | + rekvisisjonAPI(context) |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments