imetallica

imetallica

Configuring StreamData to work with Phoenix and Ecto

Hello folks, I’m trying to generate some payload data to test my controllers in Phoenix, but I always end up with the following problem:

{"errors":{"detail":[{"document":"has already been taken"}]}}

Which is ok, the generator is generating the same value for document over and over again. The problem it should test one property and then rollback rather than running all the tests and then, rollback. Is there a way to do this?

Marked As Solved

imetallica

imetallica

I figured out a way of doing it:

  @tag :business
  property "[POST /partners] should create a new partner.", %{conn: conn} do
    check all param <- post_partner_generator() do
      Repo.transaction(fn ->
        response = conn |> post(partner_path(conn, :create_partner, param)) |> json_response(201)
        assert response["partner"]["anticipate"] == param["anticipate"]
        assert response["partner"]["chargeback_rule"] == param["chargeback_rule"]
        assert response["partner"]["document"] == param["document"]
        assert response["partner"]["identifier"] == param["identifier"]
        assert response["partner"]["partner"] == param["partner"]

        Repo.rollback(:done)
      end)
    end
  end

That should do the trick if anyone is interested on a way of doing it.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
jononomo
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
lastday4you
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
dblack
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
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
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
gshaw
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
dblack
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

We're in Beta

About us Mission Statement