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?

Hmm that should be handled by your code in the test, can you show it?

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.

3 Likes