1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
6 use Pleroma.Web.ConnCase, async: true
7 alias Pleroma.UserRelationship
8 alias Pleroma.Web.CommonAPI
11 setup do: oauth_access(["read", "write"])
13 test "returns empty result", %{conn: conn} do
16 |> get("/api/v1/suggestions")
17 |> json_response_and_validate_schema(200)
22 test "returns v2 suggestions", %{conn: conn} do
23 %{id: user_id} = insert(:user, is_suggested: true)
27 |> get("/api/v2/suggestions")
28 |> json_response_and_validate_schema(200)
30 assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
33 test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
34 %{id: user_id} = insert(:user, is_suggested: true)
37 |> delete("/api/v1/suggestions/#{user_id}")
38 |> json_response_and_validate_schema(200)
42 |> get("/api/v2/suggestions")
43 |> json_response_and_validate_schema(200)
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)
54 |> get("/api/v2/suggestions")
55 |> json_response_and_validate_schema(200)
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)
66 |> get("/api/v2/suggestions")
67 |> json_response_and_validate_schema(200)
72 test "dismiss suggestion", %{conn: conn, user: source} do
73 target = insert(:user, is_suggested: true)
77 |> delete("/api/v1/suggestions/#{target.id}")
78 |> json_response_and_validate_schema(200)
81 assert UserRelationship.exists?(:suggestion_dismiss, source, target)