I have a pair of temporally-coupled controller actions. One, a GET that renders a form, puts a key/value pair into the session. The next action, a POST, is to combine the form values with the session value to do that thing it does. I’m trying to write the test for that second action, and I’m having trouble.
I know the trick from the Phoenix documentation of having an authorization plug that checks if a test has put a value in conn.assigns[:current_user]
:
cond do
conn.assigns[:current_user] ->
conn
But it seems wrong to add special-case test-support code for every session value.
So what’s the simplest way for a test to inject a value into the session with put_session
(or something else) such that the controller can use a get_session
to retrieve the value? If I look at the conn
after the first (GET) action, I see that the information I want is nicely stored in :private
:
:plug_session => %{
...
"token_text" => "Q2bPgpLDGHtf4BbHDgTfMpM6fN"
},
:plug_session_fetch => :done,
:plug_session_info => :write,
It seems that my test should be able to easily create an incoming session with the same token_text
, just as if a real user had previously executed the form-producing action. But I don’t see how to do it.