wearblc

wearblc

Testing with Bypass that makes a call to a dynamic 3rd party url that can't be easily stubbed

I am working on testing a complex function that makes multiple third party API calls. We use [Bypass](https://hexdocs.pm/bypass/Bypass.html) to mock our API calls and has served us well for testing functions where it’s easy to mock the url being called.

However, the function I’m testing has a few API calls that are nested. I am easily able to anticipate the url being called except for one where we pass a newly created UUID that is used in the API call.

def complex_function(args) do
   # logic and api calls

   ThirdPartyApi.create(arg1, UUID.uuid4(), arg3)

   # additional logic and api calls
end

Makes a call similar to api/v2/{arg1}/{uuid}
Testing the function ThirdPartyApi.create/3 is easy to do on its own but in the above function it is not since the uuid is not known.

I’ve read about accessing the env in the function and creating a stub function for ThirdPartyApi.create/3 if the env is test. It’s something I know about and have seen but haven’t read too much into just yet.

I wanted to see if there’s a way to handle the above scenario with Bypass with how I’m using it now or if I’ll need to do something like passing the env to test.

Most Liked

Hermanverschooten

Hermanverschooten

I am using Mimic to handle just such a situation.
I mimic the uuid generation and have it return a static one.

dimitarvp

dimitarvp

You can also use patch.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
ashish173
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
pmjoe
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fayddelight
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
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement