LauraBeatris

LauraBeatris

Fixtures for HTTP response assertions

Is there a recommended way for creating/organizing fixtures for HTTP response in order to be referenced when mocking?

Atm, on our SDK, we’re setting a fake body that doesn’t match the response payload from the API:

  describe "#delete_organization/1 with an invalid id" do
    setup do
      mock(fn
        %{method: :delete, url: "https://api.workos.com/organizations/invalid"} ->
          %Tesla.Env{status: 404, body: "Not Found"}
      end)

      :ok
    end

Ideally, we would like to pass a fixture to it for the entire response body, like this example from our Node SDK: workos-node/organizations.spec.ts at main · workos/workos-node · GitHub

Most Liked

dimitarvp

dimitarvp

Let’s just list some libraries first:

  • exvcr
  • mock
  • patch
  • mox (only if you mock your own code, not that of a library dependency)
  • bypass

I used mock just yesterday but was made aware of patch in the meantime and will use it next time because it does seem to have more functionality.

Related thread from just yesterday: Approach for numerous edge cases, HTTP GET, exvcr - #4 by dimitarvp


Responding to your actual question, it seems that exvcr has what you need. You record “cassettes” and then specify their location in the test case file.

w0rd-driven

w0rd-driven

exvcr seems to follow snapshot testing, which is a more framework agnostic term. This article is a little dated Stephen Bussey - Introducing Elixir Response Snapshot Testing but the repo at GitHub - sb8244/elixir_response_snapshot: Implement snapshot testing in Elixir. has more recent changes and could be another option.

It looks like patch has a companion repo testing various mock libraries at GitHub - ihumanable/mockompare: Companion Mock Comparison Suite for Patch.

Where Next?

Popular in Questions Top

9mm
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
senggen
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio_101
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
nsuchy
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
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
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
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement