logo

pleroma

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

resilience_test.exs (2944B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.ResilienceTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. import Pleroma.Factory
  7. alias Pleroma.Activity
  8. alias Pleroma.Repo
  9. alias Pleroma.Web.CommonAPI
  10. alias Pleroma.Web.MastodonAPI.StatusView
  11. setup do
  12. # user = insert(:user)
  13. %{user: user, conn: conn} = oauth_access(["write", "read"])
  14. other_user = insert(:user)
  15. {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"})
  16. {:ok, like} = CommonAPI.favorite(other_user, post_one.id)
  17. %{
  18. user: user,
  19. other_user: other_user,
  20. post_one: post_one,
  21. like: like,
  22. conn: conn
  23. }
  24. end
  25. test "after destruction of like activities, things still work", %{
  26. user: user,
  27. post_one: post,
  28. other_user: other_user,
  29. conn: conn,
  30. like: like
  31. } do
  32. post = Repo.get(Activity, post.id)
  33. # Rendering the liked status
  34. rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
  35. assert rendered_for_user.favourites_count == 1
  36. rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
  37. assert rendered_for_other_user.favourites_count == 1
  38. assert rendered_for_other_user.favourited
  39. # Getting the favourited by
  40. [liking_user] =
  41. conn
  42. |> get("/api/v1/statuses/#{post.id}/favourited_by")
  43. |> json_response(200)
  44. assert liking_user["id"] == other_user.id
  45. # We have one notification
  46. [notification] =
  47. conn
  48. |> get("/api/v1/notifications")
  49. |> json_response(200)
  50. assert notification["type"] == "favourite"
  51. # Destroying the like
  52. Repo.delete(like)
  53. post = Repo.get(Activity, post.id)
  54. # Rendering the liked status
  55. rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
  56. assert rendered_for_user.favourites_count == 1
  57. rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
  58. assert rendered_for_other_user.favourites_count == 1
  59. assert rendered_for_other_user.favourited
  60. # Getting the favourited by
  61. [liking_user] =
  62. conn
  63. |> get("/api/v1/statuses/#{post.id}/favourited_by")
  64. |> json_response(200)
  65. assert liking_user["id"] == other_user.id
  66. # Notification is removed
  67. assert [] ==
  68. conn
  69. |> get("/api/v1/notifications")
  70. |> json_response(200)
  71. # Favoriting again doesn't hurt
  72. {:ok, _like_two} = CommonAPI.favorite(other_user, post.id)
  73. post = Repo.get(Activity, post.id)
  74. # Rendering the liked status
  75. rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
  76. assert rendered_for_user.favourites_count == 1
  77. # General fallout: Can't unfavorite stuff anymore. Acceptable for remote users.
  78. end
  79. end