Add a way to use the admin api without a user.
[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 Code.ensure_compiled(Pleroma.User)
5
6 alias Pleroma.Plugs.SetUserSessionIdPlug
7 alias Pleroma.User
8
9 setup %{conn: conn} do
10 session_opts = [
11 store: :cookie,
12 key: "_test",
13 signing_salt: "cooldude"
14 ]
15
16 conn =
17 conn
18 |> Plug.Session.call(Plug.Session.init(session_opts))
19 |> fetch_session
20
21 %{conn: conn}
22 end
23
24 test "doesn't do anything if the user isn't set", %{conn: conn} do
25 ret_conn =
26 conn
27 |> SetUserSessionIdPlug.call(%{})
28
29 assert ret_conn == conn
30 end
31
32 test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
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