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
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
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
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
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
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
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
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’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
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









