nmacuk
Elixir Mock Module called from other Worker
Hello,
I have a worker that calls another module
def perform(%Oban.Job{args: form_response}) do
sms_typeform_request_uuid = get_in(form_response, ["hidden", "sms_typeform_request_uuid"])
response =
case get_in(form_response, ["answers", Access.at(0), "choices", "labels"]) do
["Yes" <> _] -> "confirmed"
["No" <> _] -> "declined"
end
message =
MyApp.Client.publish_message(
name: "typeform_response",
correlation_key: sms_typeform_request_uuid,
variables: %{sms_typeform_response: response}
)
case message do
:ok -> :ok
{:error, error} -> {:error, error}
end
end
And in my test I have a following setup
test_with_mock "job", MyApp.Client,
[publish_message: fn(_) ->
:ok
end]do
assert :ok ==
perform_job(MyApp.Worker.TypeformResponseNotifier, %{
"answers" => [
%{
"choices" => %{"labels" => ["Yes, Date is ok"]},
],
"hidden" => %{"sms_typeform_request_uuid" => "UYl2Mw_m"}
})
assert_called(
MyApp.Client.publish_message(
task_type: "typeform_response",
correlation_key: UYl2Mw_m,
variables: %{sms_typeform_response: "confirmed"}
)
)
end```
But the test fails with this:
Expected call but did not receive it. Calls which were received:
0. Elixir.MyApp.Client.publish_message([name: "typeform_response", correlation_key: "UYl2Mw_m", variables: %{sms_typeform_response: "confirmed"}]) (returned :ok)
code: assert_called(
What Am I doing wrong? What happens?
Most Liked
Popular in Questions
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
I would like to know what is the best IDE for elixir development?
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









