Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mocking #403

Open
mleonhard-flexport opened this issue Aug 10, 2023 · 0 comments
Open

Support mocking #403

mleonhard-flexport opened this issue Aug 10, 2023 · 0 comments

Comments

@mleonhard-flexport
Copy link

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 ✨

  • Writing a test harness to create an index per test run and delete it afterward. This would be a real integration test.
  • Wrapping the Algolia client in a class that can be mocked, with suspend functions.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant