remove `unread_conversation_count` from User
[akkoma] / test / plugs / session_authentication_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.SessionAuthenticationPlugTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Plugs.SessionAuthenticationPlug
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 |> assign(:auth_user, %User{id: 1})
23
24 %{conn: conn}
25 end
26
27 test "it does nothing if a user is assigned", %{conn: conn} do
28 conn =
29 conn
30 |> assign(:user, %User{})
31
32 ret_conn =
33 conn
34 |> SessionAuthenticationPlug.call(%{})
35
36 assert ret_conn == conn
37 end
38
39 test "if the auth_user has the same id as the user_id in the session, it assigns the user", %{
40 conn: conn
41 } do
42 conn =
43 conn
44 |> put_session(:user_id, conn.assigns.auth_user.id)
45 |> SessionAuthenticationPlug.call(%{})
46
47 assert conn.assigns.user == conn.assigns.auth_user
48 end
49
50 test "if the auth_user has a different id as the user_id in the session, it does nothing", %{
51 conn: conn
52 } do
53 conn =
54 conn
55 |> put_session(:user_id, -1)
56
57 ret_conn =
58 conn
59 |> SessionAuthenticationPlug.call(%{})
60
61 assert ret_conn == conn
62 end
63 end