My app has a helper function (say ensure_authenicated) that is run by the live session in the router “on_mount” that fetches the current user and sets both the user and their account on the socket assigns before on_mount is called in the live view.
scope "/", AppWeb do
pipe_through [:browser, :require_authenticated_user]
live_session :require_authenticated_user,
on_mount: [{AppWeb.UserAuth, :ensure_authenticated}] do
live "/users/settings", UserSettingsLive, :edit
...
end
end
I need to test this live view, so the precondition is thus that the user and account are on the socket assigns somehow before I call the code under test. The code under test reads only from the socket, not the session.
@impl true
def mount(_params, _session, socket) do
{:ok,
stream(
socket,
:thing,
Thing.function(socket.assigns.current_account)
)}
end
Is is possible to do this? The test helpers seem to only let you pass in session data






















