Testing Read Operation

Learn how to test Read operation in Elixir

We'll cover the following...

The Read function

First, let’s look at the code in our Users module at testing_ecto/lib/users/users.ex.

Note: We used “Read” in the section header to keep it in line with CRUD, but you’ll notice that we prefer to call our function get/1. This is entirely user preference.

Press + to interact
#file path -> testing_ecto/lib/users/users.ex
#add this code at the indicated place mentioned in comments of testing_ecto/lib/users/users.ex
#in the playground widget
def get(user_id) do
if user = Repo.get(User, user_id) do
{:ok, user}
else
{:error, :not_found}
end
end

Our ...