8948a52de149c60d1ecb10ed5eb2c9133911ff55
[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 import Pleroma.Factory
9
10 setup do: oauth_access(["read", "write"])
11
12 test "returns empty result", %{conn: conn} do
13 res =
14 conn
15 |> get("/api/v1/suggestions")
16 |> json_response_and_validate_schema(200)
17
18 assert res == []
19 end
20
21 test "returns v2 suggestions", %{conn: conn} do
22 %{id: user_id} = insert(:user, is_suggested: true)
23
24 res =
25 conn
26 |> get("/api/v2/suggestions")
27 |> json_response_and_validate_schema(200)
28
29 assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
30 end
31
32 test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
33 %{id: user_id} = insert(:user, is_suggested: true)
34
35 conn
36 |> delete("/api/v1/suggestions/#{user_id}")
37 |> json_response_and_validate_schema(200)
38
39 res =
40 conn
41 |> get("/api/v2/suggestions")
42 |> json_response_and_validate_schema(200)
43
44 assert [] = res
45 end
46
47 test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do
48 blocked = insert(:user, is_suggested: true)
49 {:ok, _} = Pleroma.Web.CommonAPI.block(blocker, blocked)
50
51 res =
52 conn
53 |> get("/api/v2/suggestions")
54 |> json_response_and_validate_schema(200)
55
56 assert [] = res
57 end
58
59 test "dismiss suggestion", %{conn: conn, user: source} do
60 target = insert(:user, is_suggested: true)
61
62 res =
63 conn
64 |> delete("/api/v1/suggestions/#{target.id}")
65 |> json_response_and_validate_schema(200)
66
67 assert res == %{}
68 assert UserRelationship.exists?(:suggestion_dismiss, source, target)
69 end
70 end