1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ResilienceTest do
6 use Pleroma.Web.ConnCase, async: true
10 alias Pleroma.Activity
12 alias Pleroma.Web.CommonAPI
13 alias Pleroma.Web.MastodonAPI.StatusView
16 # user = insert(:user)
17 %{user: user, conn: conn} = oauth_access(["write", "read"])
18 other_user = insert(:user)
20 {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"})
21 {:ok, like} = CommonAPI.favorite(other_user, post_one.id)
25 other_user: other_user,
32 test "after destruction of like activities, things still work", %{
35 other_user: other_user,
39 post = Repo.get(Activity, post.id)
41 # Rendering the liked status
42 rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
43 assert rendered_for_user.favourites_count == 1
45 rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
46 assert rendered_for_other_user.favourites_count == 1
47 assert rendered_for_other_user.favourited
49 # Getting the favourited by
52 |> get("/api/v1/statuses/#{post.id}/favourited_by")
55 assert liking_user["id"] == other_user.id
57 # We have one notification
60 |> get("/api/v1/notifications")
63 assert notification["type"] == "favourite"
67 post = Repo.get(Activity, post.id)
69 # Rendering the liked status
70 rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
71 assert rendered_for_user.favourites_count == 1
73 rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user})
74 assert rendered_for_other_user.favourites_count == 1
75 assert rendered_for_other_user.favourited
77 # Getting the favourited by
80 |> get("/api/v1/statuses/#{post.id}/favourited_by")
83 assert liking_user["id"] == other_user.id
85 # Notification is removed
89 |> get("/api/v1/notifications")
92 # Favoriting again doesn't hurt
93 {:ok, _like_two} = CommonAPI.favorite(other_user, post.id)
95 post = Repo.get(Activity, post.id)
97 # Rendering the liked status
98 rendered_for_user = StatusView.render("show.json", %{activity: post, for: user})
99 assert rendered_for_user.favourites_count == 1
101 # General fallout: Can't unfavorite stuff anymore. Acceptable for remote users.