Is there a way to persist in the same test a database change to use that change in another assert?
We’d like to implement test functions to our authentication. Since we can’t know an user password, we are also testing the recover process (changing password first).
Our current data_case.ex is:
def setup_sandbox(tags) do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(PeoplexServices.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
end
And our current test is:
defmodule LiveAdminWeb.AuthTest do
use LiveAdminWeb.ConnCase, async: true
import Phoenix.LiveViewTest
...
test "login", %{conn: conn} do
# PASSWORD
{:ok, user} = AdminUsers.get_by_email(@user_email, @subdomain)
...
attrs = %{
password_hash: password_hash
}
AdminUsers.update(user, attrs, @subdomain, nil, "service")
# ACCESS
path = "#{@base_path}/auth/"
conn = get(conn, path)
assert html_response(conn, 200) =~ "Entrar"
# LOGIN
body = %{
"item" => %{"email" => @user_email, "password" => password_text}
}
conn = post(conn, path, body)
...
end
end
This fails probably because the first database change is rollbacked.
The test works with a valid password. (no database change).