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
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
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









