diff --git a/common/src/commonMain/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfig.kt b/common/src/commonMain/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfig.kt index f094332..cdba069 100644 --- a/common/src/commonMain/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfig.kt +++ b/common/src/commonMain/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfig.kt @@ -2,6 +2,6 @@ package com.tddworks.common.network.api.ktor.internal data class HostPortConnectionConfig( val protocol: () -> String? = { null }, - val host: () -> String = { "" }, val port: () -> Int? = { null }, + val host: () -> String, ) : ConnectionConfig \ No newline at end of file diff --git a/common/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HttpClientTest.kt b/common/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HttpClientTest.kt index 7dd8b20..3754ecc 100644 --- a/common/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HttpClientTest.kt +++ b/common/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HttpClientTest.kt @@ -31,8 +31,8 @@ class HttpClientTest { val apiClient = createHttpClient( connectionConfig = HostPortConnectionConfig( protocol = { "https" }, - host = { "some-host" }, - port = { 443 } + port = { 443 }, + host = { "some-host" } ), httpClientEngine = mockEngine, authConfig = AuthConfig(authToken = { "token" }), @@ -50,8 +50,8 @@ class HttpClientTest { val apiClient = createHttpClient( connectionConfig = HostPortConnectionConfig( protocol = { "https" }, - host = { "some-host" }, - port = { 443 } + port = { 443 }, + host = { "some-host" } ), httpClientEngine = mockEngine ) diff --git a/openai-client/openai-client-core/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfigTest.kt b/openai-client/openai-client-core/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfigTest.kt new file mode 100644 index 0000000..be5f578 --- /dev/null +++ b/openai-client/openai-client-core/src/jvmTest/kotlin/com/tddworks/common/network/api/ktor/internal/HostPortConnectionConfigTest.kt @@ -0,0 +1,30 @@ +package com.tddworks.common.network.api.ktor.internal + +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test + +class HostPortConnectionConfigTest { + + @Test + fun `should return default protocol and port`() { + val config = HostPortConnectionConfig { "example.com" } + + assertNull(config.protocol(), "Protocol should default to null") + + assertNull(config.port(), "Port should default to null") + } + + @Test + fun `should able to specified protocol and port`() { + val protocol: () -> String? = { "http" } + val port: () -> Int? = { 8080 } + val config = HostPortConnectionConfig( + protocol = protocol, + port = port, + host = { "example.com" } + ) + + assertEquals("http", config.protocol(), "Protocol should be 'http'") + assertEquals(8080, config.port(), "Port should be 8080") + } +} \ No newline at end of file