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
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
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
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
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
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









