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

Write server / handler unit tests to ensure callbacks are being invoked #223

Open
jiyoontbd opened this issue Mar 29, 2024 · 1 comment
Open

Comments

@jiyoontbd
Copy link
Contributor

Maybe using mockk library will help

@jiyoontbd
Copy link
Contributor Author

Did most of this work in 1fa47a5

However, there's an issue testing any handler methods that invoke ApplicationCall#receiveText() like CreateExchange and SubmitMessage. Mocking this is proving difficult.

Example test written (currently not being run)

fun `verify callback is invoked upon successful rfq submission`() = runBlocking {
      // todo ApplicationCall.receiveText() is an extension function
      //  need to find another way to mock it
      coEvery { applicationCall.parameters["exchangeId"] } returns close.metadata.exchangeId
      coEvery { applicationCall.receiveText() } returns Json.stringify(close)

      coVerify(exactly = 1) { submitClose(applicationCall, exchangesApi, any<SubmitCloseCallback>(), close)}

    }

Example error stack:

SubmitMessageTest > SubmitMessageMockkTest > verify callback is invoked upon successful rfq submission() FAILED
    io.ktor.server.plugins.CannotTransformContentToTypeException: Cannot transform this request's content to io.ktor.utils.io.ByteReadChannel
        at app//io.ktor.server.request.ApplicationReceiveFunctionsKt.receiveNullable(ApplicationReceiveFunctions.kt:107)
        at app//tbdex.sdk.httpserver.handlers.SubmitMessageTest$SubmitMessageMockkTest$verify callback is invoked upon successful rfq submission$1$2.invokeSuspend(SubmitMessageTest.kt:117)
        at app//tbdex.sdk.httpserver.handlers.SubmitMessageTest$SubmitMessageMockkTest$verify callback is invoked upon successful rfq submission$1$2.invoke(SubmitMessageTest.kt)
        at app//tbdex.sdk.httpserver.handlers.SubmitMessageTest$SubmitMessageMockkTest$verify callback is invoked upon successful rfq submission$1$2.invoke(SubmitMessageTest.kt)...

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

No branches or pull requests

1 participant