Skip to content

Commit

Permalink
chore(libs): add coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
hanrw committed Feb 14, 2024
1 parent 0f152cb commit 878e15b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ ktor = "2.3.7"
kotlinx-serialization = "1.6.2"
kover = "0.7.5"

kotlinx-coroutines = "1.7.3"

junit = "5.10.1"
mockito-junit-jupiter = "5.8.0"
mockito-kotlin = "5.2.1"
Expand All @@ -37,7 +39,7 @@ touchlab-kmmbridge = "0.5.1"

[libraries]

kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
Expand All @@ -49,6 +51,9 @@ ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negoti
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }

kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }

kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }

junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
Expand Down
2 changes: 2 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kotlin {
commonMain.dependencies {
// put your Multiplatform dependencies here
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.bundles.ktor.client)
}

Expand All @@ -35,6 +36,7 @@ kotlin {

jvmTest.dependencies {
implementation(project.dependencies.platform(libs.junit.bom))
implementation(libs.kotlinx.coroutines.test)
implementation(libs.bundles.jvm.test)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.tddworks.lemonsqueezy.api.internal.network.ktor
import com.tddworks.lemonsqueezy.api.mockHttpClient
import io.ktor.client.*
import io.ktor.client.request.*
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class DefaultHttpRequesterTest {
private lateinit var httpClient: HttpClient

@Test
fun `should return activation success when activated`() = runBlocking {
fun `should return activation success when activated`() = runTest {
val mockResponse = """
{
"activated": true,
Expand Down Expand Up @@ -57,7 +57,7 @@ class DefaultHttpRequesterTest {
}

@Test
fun `should return activation error when not activated`() = runBlocking {
fun `should return activation error when not activated`() = runTest {
val mockResponse = """
{
"activated": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tddworks.lemonsqueezy.api.license

import com.tddworks.lemonsqueezy.api.internal.network.ktor.HttpRequester
import com.tddworks.lemonsqueezy.api.license.data.Instance
import com.tddworks.lemonsqueezy.api.license.data.LicenseKey
import com.tddworks.lemonsqueezy.api.license.data.Meta
import com.tddworks.lemonsqueezy.api.internal.network.ktor.HttpRequester
import com.tddworks.lemonsqueezy.api.license.request.LicenseActivationRequest
import com.tddworks.lemonsqueezy.api.license.request.LicenseDeactivationRequest
import com.tddworks.lemonsqueezy.api.license.response.LicenseActivationErrorResponse
Expand All @@ -12,7 +12,7 @@ import com.tddworks.lemonsqueezy.api.license.response.LicenseDeactivationRespons
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.util.reflect.*
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.mockito.Mockito.mock
Expand All @@ -25,7 +25,7 @@ class LicenseKeysApiTest {
private var requester: HttpRequester = mock()

@Test
fun `should return deactivation success when deactivated`() = runBlocking {
fun `should return deactivation success when deactivated`() = runTest {
val expectedResponse = LicenseDeactivationResponse(
deactivated = true,
error = null,
Expand Down Expand Up @@ -80,7 +80,7 @@ class LicenseKeysApiTest {
}

@Test
fun `should return activation error when not activated`() = runBlocking {
fun `should return activation error when not activated`() = runTest {
val responseJson = """
{
"activated": false,
Expand Down Expand Up @@ -156,7 +156,7 @@ class LicenseKeysApiTest {
}

@Test
fun `should return activation success when activated`() = runBlocking {
fun `should return activation success when activated`() = runTest {
val responseJson = """
{
"activated": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import com.tddworks.lemonsqueezy.api.user.response.UserResponse
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.util.reflect.*
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.mockito.kotlin.argThat
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

class UsersApiTest {
private var requester: HttpRequester = Mockito.mock()
private var requester: HttpRequester = mock()

@Test
fun `should return me when success`() = runBlocking {
fun `should return me when success`() = runTest {
val httpRequestCaptor = argumentCaptor<HttpRequestBuilder.() -> Unit>()
val expectedResponse = UserResponse(
type = "users",
Expand Down

0 comments on commit 878e15b

Please sign in to comment.