Revert "Merge branch 'remove/mastofe' into 'develop'"
[akkoma] / test / pleroma / web / plugs / user_fetcher_plug_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Plugs.UserFetcherPlugTest do
6 use Pleroma.Web.ConnCase, async: true
7
8 alias Pleroma.Web.Plugs.UserFetcherPlug
9 import Pleroma.Factory
10
11 setup do
12 user = insert(:user)
13 %{user: user}
14 end
15
16 test "if an auth_credentials assign is present, it tries to fetch the user and assigns it", %{
17 conn: conn,
18 user: user
19 } do
20 conn =
21 conn
22 |> assign(:auth_credentials, %{
23 username: user.nickname,
24 password: nil
25 })
26
27 conn =
28 conn
29 |> UserFetcherPlug.call(%{})
30
31 assert conn.assigns[:auth_user] == user
32 end
33
34 test "without a credential assign it doesn't do anything", %{conn: conn} do
35 ret_conn =
36 conn
37 |> UserFetcherPlug.call(%{})
38
39 assert conn == ret_conn
40 end
41 end