samedi 16 septembre 2017

Avoiding Mocks When Generating Response Data in Elixir

I've come to understand that mocks are not generally well thought of in the Elixir community. With that in mind, I have the following predicament I'm not quite sure how to solve.

First, my current design using http://ift.tt/1I7cvx9

remote_api_generated_data = %{
  transaction_id: "09200-12-235089721-3987235",
  confirmation_number: "JB789FKS78GS82"
}

with_mock RemoteApi.Client, [order: Mocks.RemoteApi.Client.successful_transaction(&1, vaulted_data)] do
  conn = post conn, transaction_path(conn, :create), data: [@create_attrs]
  response = json_response(conn, 201)["data"]
  assert response.composite_key == "#{remote_api_generated_data.transaction_id}:#{remote_api_generated_data.confirmation_number}"
end


José Valim offers a nice mocking solution using protocols and configuration files. See the post for details: http://ift.tt/2wxO6BC

My question is this: How can you take the approach of "protocols and configuration changes" and still validate on remotely generate data? (Recognizing that it's not the data itself, but the transformation of it that I'm asserting. In this case the composite_key)

Aucun commentaire:

Enregistrer un commentaire