remove `unread_conversation_count` from User
[akkoma] / test / plugs / set_user_session_id_plug_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Plugs.SetUserSessionIdPlug
9 alias Pleroma.User
10
11 setup %{conn: conn} do
12 session_opts = [
13 store: :cookie,
14 key: "_test",
15 signing_salt: "cooldude"
16 ]
17
18 conn =
19 conn
20 |> Plug.Session.call(Plug.Session.init(session_opts))
21 |> fetch_session
22
23 %{conn: conn}
24 end
25
26 test "doesn't do anything if the user isn't set", %{conn: conn} do
27 ret_conn =
28 conn
29 |> SetUserSessionIdPlug.call(%{})
30
31 assert ret_conn == conn
32 end
33
34 test "sets the user_id in the session to the user id of the user assign", %{conn: conn} do
35 Code.ensure_compiled(Pleroma.User)
36
37 conn =
38 conn
39 |> assign(:user, %User{id: 1})
40 |> SetUserSessionIdPlug.call(%{})
41
42 id = get_session(conn, :user_id)
43 assert id == 1
44 end
45 end