From 293bf713d8009c966d5c3b5311b5b5df3120792f Mon Sep 17 00:00:00 2001 From: jaguililla Date: Sat, 3 Aug 2024 19:14:52 +0200 Subject: [PATCH] Improve :tests --- .../kotlin/com/hexagonkt/core/media/MediaTypesTest.kt | 2 +- .../src/test/kotlin/com/hexagonkt/http/HttpTest.kt | 10 ++++++++++ .../test/kotlin/com/hexagonkt/http/model/CookieTest.kt | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/test/kotlin/com/hexagonkt/core/media/MediaTypesTest.kt b/core/src/test/kotlin/com/hexagonkt/core/media/MediaTypesTest.kt index 83dd48f9e7..f3d0fce84c 100644 --- a/core/src/test/kotlin/com/hexagonkt/core/media/MediaTypesTest.kt +++ b/core/src/test/kotlin/com/hexagonkt/core/media/MediaTypesTest.kt @@ -23,9 +23,9 @@ internal class MediaTypesTest { @Test fun `Parse correct media types`() { MediaType("*/*").apply { assertEquals(ANY, group) + assertEquals("any", group.text) assertEquals("*", type) assertEquals("*/*", fullType) - } MediaType("text/plain").apply { diff --git a/http/http/src/test/kotlin/com/hexagonkt/http/HttpTest.kt b/http/http/src/test/kotlin/com/hexagonkt/http/HttpTest.kt index 0fa0e3afa3..15e6f61669 100644 --- a/http/http/src/test/kotlin/com/hexagonkt/http/HttpTest.kt +++ b/http/http/src/test/kotlin/com/hexagonkt/http/HttpTest.kt @@ -14,6 +14,16 @@ import kotlin.test.assertTrue internal class HttpTest { + @Test fun `Format query string with empty keys`() { + assertEquals("", formatQueryString(QueryParameters(QueryParameter("", 1)))) + assertEquals("", formatQueryString(QueryParameters(QueryParameter(" ", 1)))) + } + + @Test fun `Basic auth is encoded correctly`() { + assertEquals("YTo", basicAuth("a")) + assertEquals("YTpi", basicAuth("a", "b")) + } + @Test fun `Format query string`() { fun testParseFormat(expected: String, queryString: String) { assertEquals(expected, formatQueryString(parseQueryString(queryString))) diff --git a/http/http/src/test/kotlin/com/hexagonkt/http/model/CookieTest.kt b/http/http/src/test/kotlin/com/hexagonkt/http/model/CookieTest.kt index c810b70268..213285dc0f 100644 --- a/http/http/src/test/kotlin/com/hexagonkt/http/model/CookieTest.kt +++ b/http/http/src/test/kotlin/com/hexagonkt/http/model/CookieTest.kt @@ -1,5 +1,6 @@ package com.hexagonkt.http.model +import com.hexagonkt.http.model.CookieSameSite.* import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Test import kotlin.IllegalArgumentException @@ -20,6 +21,10 @@ internal class CookieTest { assertEquals(5, cookie.maxAge) assertTrue(cookie.secure) assertFalse(cookie.deleted) + + assertEquals(LAX, cookie.copy(sameSite = LAX).sameSite) + assertEquals(NONE, cookie.copy(sameSite = NONE).sameSite) + assertEquals(STRICT, cookie.copy(sameSite = STRICT).sameSite) } @Test fun `Cookie can be deleted`() {