Hello I have some GenServer that subscribe to Phoenix.PubSub channel to reduce code coupling
I feel like something is missing Patch (that is really nice btw).
My workflow is everytime a character is created, I broadcast a message that will be catch by some GenServers to do their shit (e.g. send welcome email, push discord msg, or log the event in a db or w.e)
I want to test this but because it's a PhoenixPubSub event, it's not easily testable. I end with the following test (that works great).
defmoduleForHonor.Feed.AdventureEventSubscriberTestdousePatch#...test"on character created",%{character: character}dopatch_handle_info(AdventureEventSubscriber)msg={:character_created,character}Phoenix.PubSub.broadcast(ForHonor.PubSub,"game:events",msg)assert_handle_info(AdventureEventSubscriber)# test if side effect was apply or w.eenddefppatch_handle_info(module)dopid=self()patch(module,:handle_info,fnmsg,state->real(module).handle_info(msg,state)|>tap(fn_->send(pid,module)end)end)enddefpassert_handle_info(module,timeout\\:timer.seconds(5))doreceivedo^module->asserttrueaftertimeout->assertfalseendendendI don't have a global overview of patch, maybe I miss something. I would like to have your opinion on the previous code. If their is no other way to accomplish that, are you interested by a pull request ?
Thanks a lot ;)
Hello I have some GenServer that subscribe to Phoenix.PubSub channel to reduce code coupling
I feel like something is missing Patch (that is really nice btw).
My workflow is everytime a
characteris created, I broadcast a message that will be catch by some GenServers to do their shit (e.g. send welcome email, push discord msg, or log the event in a db or w.e)I want to test this but because it's a PhoenixPubSub event, it's not easily testable. I end with the following test (that works great).
I don't have a global overview of patch, maybe I miss something. I would like to have your opinion on the previous code. If their is no other way to accomplish that, are you interested by a pull request ?
Thanks a lot ;)