7cf8e42cc865534dbfefb0e18f9e9e8c7c523f03
[akkoma] / test / plugs / set_user_session_id_plug_test.exs
1 defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
2 use Pleroma.Web.ConnCase, async: true
3
4 alias Pleroma.Plugs.SetUserSessionIdPlug
5 alias Pleroma.User
6
7 setup %{conn: conn} do
8 session_opts = [
9 store: :cookie,
10 key: "_test",
11 signing_salt: "cooldude"
12 ]
13
14 conn =
15 conn
16 |> Plug.Session.call(Plug.Session.init(session_opts))
17 |> fetch_session
18
19 %{conn: conn}
20 end
21
22 test "doesn't do anything if the user isn't set", %{conn: conn} do
23 ret_conn =
24 conn
25 |> SetUserSessionIdPlug.call(%{})
26
27 assert ret_conn == conn
28 end
29
30 test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
31 Code.ensure_compiled(Pleroma.User)
32
33 conn =
34 conn
35 |> assign(:user, %User{id: 1})
36 |> SetUserSessionIdPlug.call(%{})
37
38 id = get_session(conn, :user_id)
39 assert id == 1
40 end
41 end