Skip to content

Commit

Permalink
Cleanup utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin-marginean committed May 2, 2024
1 parent a1a2e64 commit c11812c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
invirtVersion = 0.8.26
invirtVersion = 0.8.27
kotlinVersion = 1.9.23
http4kVersion = 5.17.0.0
mockkVersion = 1.13.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package invirt.http4k.handlers

import invirt.http4k.GET
import invirt.http4k.jsonLens
import invirt.http4k.ok
import invirt.http4k.views.ok
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.core.with
import org.http4k.routing.RoutingHttpHandler
import org.http4k.routing.routes

Expand All @@ -13,7 +14,7 @@ object HealthCheck {

val json: RoutingHttpHandler = routes(
"/health" GET {
HealthStatus().ok(jsonLens)
Response(Status.OK).with(jsonLens of HealthStatus())
}
)
}
Expand Down
1 change: 0 additions & 1 deletion invirt-http4k/src/main/kotlin/invirt/http4k/response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.http4k.lens.BiDiBodyLens
import org.http4k.lens.Header
import java.time.Instant

fun <T : Any> T.ok(lens: BiDiBodyLens<T>): Response = Response(Status.OK).with(lens of this)
fun <T : Any> BiDiBodyLens<T>.ok(message: T): Response = Response(Status.OK).with(this of message)

fun Response.withCookies(cookies: Collection<Cookie>): Response {
Expand Down
21 changes: 1 addition & 20 deletions invirt-http4k/src/test/kotlin/invirt/http4k/ResponseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package invirt.http4k

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.core.*
import org.http4k.core.cookie.Cookie
import org.http4k.kotest.shouldHaveSetCookie
import org.http4k.routing.bind
Expand Down Expand Up @@ -35,22 +32,6 @@ class ResponseTest : StringSpec({
).bodyString() shouldBe """{"name":"Apache Productions","enabled":true}"""
}

"pojo.ok(bidilens)" {
data class JsonTestPojo(
val name: String,
val enabled: Boolean
)

val httpHandler = routes(
"/test" bind Method.GET to {
val lens = jsonLens<JsonTestPojo>()
JsonTestPojo("Something else in Geordie", true).ok(lens)
}
)

httpHandler(Request(Method.GET, "/test")).bodyString() shouldBe """{"name":"Something else in Geordie","enabled":true}"""
}

"withCookies" {
val expiry = Instant.now().plusSeconds(30).truncatedTo(ChronoUnit.SECONDS)
val response = Response(Status.OK)
Expand Down

0 comments on commit c11812c

Please sign in to comment.