2018-09-05 13:42:42 -06:00
|
|
|
defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
|
|
|
|
use Pleroma.Web.ConnCase, async: true
|
|
|
|
|
2018-12-18 05:40:25 -07:00
|
|
|
Code.ensure_compiled(Pleroma.User)
|
|
|
|
|
2018-09-05 13:42:42 -06:00
|
|
|
alias Pleroma.Plugs.SetUserSessionIdPlug
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
setup %{conn: conn} do
|
|
|
|
session_opts = [
|
|
|
|
store: :cookie,
|
|
|
|
key: "_test",
|
|
|
|
signing_salt: "cooldude"
|
|
|
|
]
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> Plug.Session.call(Plug.Session.init(session_opts))
|
|
|
|
|> fetch_session
|
|
|
|
|
|
|
|
%{conn: conn}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "doesn't do anything if the user isn't set", %{conn: conn} do
|
|
|
|
ret_conn =
|
|
|
|
conn
|
|
|
|
|> SetUserSessionIdPlug.call(%{})
|
|
|
|
|
|
|
|
assert ret_conn == conn
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, %User{id: 1})
|
|
|
|
|> SetUserSessionIdPlug.call(%{})
|
|
|
|
|
|
|
|
id = get_session(conn, :user_id)
|
|
|
|
assert id == 1
|
|
|
|
end
|
|
|
|
end
|