Merge remote-tracking branch 'origin/develop' into remote-follow-api
[akkoma] / test / pleroma / web / mastodon_api / controllers / suggestion_controller_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.MastodonAPI.SuggestionControllerTest do
6 use Pleroma.Web.ConnCase, async: true
7 alias Pleroma.UserRelationship
8 alias Pleroma.Web.CommonAPI
9 import Pleroma.Factory
10
11 setup do: oauth_access(["read", "write"])
12
13 test "returns empty result", %{conn: conn} do
14 res =
15 conn
16 |> get("/api/v1/suggestions")
17 |> json_response_and_validate_schema(200)
18
19 assert res == []
20 end
21
22 test "returns v2 suggestions", %{conn: conn} do
23 %{id: user_id} = insert(:user, is_suggested: true)
24
25 res =
26 conn
27 |> get("/api/v2/suggestions")
28 |> json_response_and_validate_schema(200)
29
30 assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
31 end
32
33 test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
34 %{id: user_id} = insert(:user, is_suggested: true)
35
36 conn
37 |> delete("/api/v1/suggestions/#{user_id}")
38 |> json_response_and_validate_schema(200)
39
40 res =
41 conn
42 |> get("/api/v2/suggestions")
43 |> json_response_and_validate_schema(200)
44
45 assert [] = res
46 end
47
48 test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do
49 blocked = insert(:user, is_suggested: true)
50 {:ok, _} = CommonAPI.block(blocker, blocked)
51
52 res =
53 conn
54 |> get("/api/v2/suggestions")
55 |> json_response_and_validate_schema(200)
56
57 assert [] = res
58 end
59
60 test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do
61 followed = insert(:user, is_suggested: true)
62 {:ok, _, _, _} = CommonAPI.follow(follower, followed)
63
64 res =
65 conn
66 |> get("/api/v2/suggestions")
67 |> json_response_and_validate_schema(200)
68
69 assert [] = res
70 end
71
72 test "dismiss suggestion", %{conn: conn, user: source} do
73 target = insert(:user, is_suggested: true)
74
75 res =
76 conn
77 |> delete("/api/v1/suggestions/#{target.id}")
78 |> json_response_and_validate_schema(200)
79
80 assert res == %{}
81 assert UserRelationship.exists?(:suggestion_dismiss, source, target)
82 end
83 end