logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

suggestion_controller_test.exs (2237B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. alias Pleroma.UserRelationship
  7. alias Pleroma.Web.CommonAPI
  8. import Pleroma.Factory
  9. setup do: oauth_access(["read", "write"])
  10. test "returns empty result", %{conn: conn} do
  11. res =
  12. conn
  13. |> get("/api/v1/suggestions")
  14. |> json_response_and_validate_schema(200)
  15. assert res == []
  16. end
  17. test "returns v2 suggestions", %{conn: conn} do
  18. %{id: user_id} = insert(:user, is_suggested: true)
  19. res =
  20. conn
  21. |> get("/api/v2/suggestions")
  22. |> json_response_and_validate_schema(200)
  23. assert [%{"source" => "staff", "account" => %{"id" => ^user_id}}] = res
  24. end
  25. test "returns v2 suggestions excluding dismissed accounts", %{conn: conn} do
  26. %{id: user_id} = insert(:user, is_suggested: true)
  27. conn
  28. |> delete("/api/v1/suggestions/#{user_id}")
  29. |> json_response_and_validate_schema(200)
  30. res =
  31. conn
  32. |> get("/api/v2/suggestions")
  33. |> json_response_and_validate_schema(200)
  34. assert [] = res
  35. end
  36. test "returns v2 suggestions excluding blocked accounts", %{conn: conn, user: blocker} do
  37. blocked = insert(:user, is_suggested: true)
  38. {:ok, _} = CommonAPI.block(blocker, blocked)
  39. res =
  40. conn
  41. |> get("/api/v2/suggestions")
  42. |> json_response_and_validate_schema(200)
  43. assert [] = res
  44. end
  45. test "returns v2 suggestions excluding followed accounts", %{conn: conn, user: follower} do
  46. followed = insert(:user, is_suggested: true)
  47. {:ok, _, _, _} = CommonAPI.follow(follower, followed)
  48. res =
  49. conn
  50. |> get("/api/v2/suggestions")
  51. |> json_response_and_validate_schema(200)
  52. assert [] = res
  53. end
  54. test "dismiss suggestion", %{conn: conn, user: source} do
  55. target = insert(:user, is_suggested: true)
  56. res =
  57. conn
  58. |> delete("/api/v1/suggestions/#{target.id}")
  59. |> json_response_and_validate_schema(200)
  60. assert res == %{}
  61. assert UserRelationship.exists?(:suggestion_dismiss, source, target)
  62. end
  63. end