Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

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

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

Comments

@jiyoonie9
Copy link
Contributor

Maybe using mockk library will help

@jiyoonie9
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant