algolia / algoliasearch-client-kotlin

⚡️ A fully-featured and blazing-fast Kotlin/Android API client to interact with Algolia.
https://www.algolia.com/doc/api-client/getting-started/install/kotlin/
MIT License
59 stars 23 forks source link

Support mocking #403

Open mleonhard-flexport opened 1 year ago

mleonhard-flexport commented 1 year ago

Is your feature request related to a problem? Please describe 🙏
Since Algolia provides nothing like LocalStack for testing, I must write poor tests that mock the Algolia client object. The test must mock partialUpdateObjects. Unfortunately, Kotlin client library uses an extension function which makes mocking very hard. I haven't figured it out yet.

val responseBatch = mockk<ResponseBatch>() {
    every {
        // Unresolved reference: wait
        wait()
    }
}
val updates = slot<List<Pair<ObjectID, Partial>>>()
val index = mockk<Index>() {
    coEvery {
        partialUpdateObjects(
            createIfNotExists = true,
            partials = capture(updates)
        )
    }
}

Describe the solution you'd like 🤔 Remove the need to call wait() and instead make partialUpdateObjects a suspend function.

Describe alternatives you've considered ✨

Additional context
implementation("com.algolia:algoliasearch-client-kotlin:2.1.5") Kotlin version 1.9.0-release-358 (JRE 20.0.1) IntelliJ IDEA 2023.2 (Community Edition) Build #IC-232.8660.185, built on July 25, 2023 Runtime version: 17.0.7+7-b1000.6 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 13.5 Non-Bundled Plugins: Kotlin: 232-1.9.0-IJ8660.185

alexkops commented 4 weeks ago

I second this. And version 3.x made it worse, since even more functions became extension functions for whatever reason.