From a24b2bc38a18ff25cf4d5f4f87a26fa6fee718eb Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 6 Jan 2021 12:33:09 +0100 Subject: [PATCH 1/2] Resilience Test: Add tests for killing likes. --- test/pleroma/resilience_test.exs | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/pleroma/resilience_test.exs diff --git a/test/pleroma/resilience_test.exs b/test/pleroma/resilience_test.exs new file mode 100644 index 000000000..26fa462de --- /dev/null +++ b/test/pleroma/resilience_test.exs @@ -0,0 +1,87 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.ResilienceTest do + use Pleroma.Web.ConnCase, async: true + + import Pleroma.Factory + + alias Pleroma.Activity + alias Pleroma.Web.CommonAPI + alias Pleroma.Repo + alias Pleroma.Web.MastodonAPI.StatusView + + setup do + # user = insert(:user) + %{user: user, conn: conn} = oauth_access(["write:statuses"]) + other_user = insert(:user) + + {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"}) + {:ok, like} = CommonAPI.favorite(other_user, post_one.id) + + %{ + user: user, + other_user: other_user, + post_one: post_one, + like: like, + conn: conn + } + end + + test "after destruction of like activities, things still work", %{ + user: user, + post_one: post, + other_user: other_user, + conn: conn, + like: like + } do + post = Repo.get(Activity, post.id) + + # Rendering the liked status + rendered_for_user = StatusView.render("show.json", %{activity: post, for: user}) + assert rendered_for_user.favourites_count == 1 + + rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user}) + assert rendered_for_other_user.favourites_count == 1 + assert rendered_for_other_user.favourited + + # Getting the favourited by + [liking_user] = + conn + |> get("/api/v1/statuses/#{post.id}/favourited_by") + |> json_response(200) + + assert liking_user["id"] == other_user.id + + # Destroying the like + Repo.delete(like) + + # Rendering the liked status + rendered_for_user = StatusView.render("show.json", %{activity: post, for: user}) + assert rendered_for_user.favourites_count == 1 + + rendered_for_other_user = StatusView.render("show.json", %{activity: post, for: other_user}) + assert rendered_for_other_user.favourites_count == 1 + assert rendered_for_other_user.favourited + + # Getting the favourited by + [liking_user] = + conn + |> get("/api/v1/statuses/#{post.id}/favourited_by") + |> json_response(200) + + assert liking_user["id"] == other_user.id + + # Favoriting again doesn't hurt + {:ok, _like_two} = CommonAPI.favorite(other_user, post.id) + + post = Repo.get(Activity, post.id) + + # Rendering the liked status + rendered_for_user = StatusView.render("show.json", %{activity: post, for: user}) + assert rendered_for_user.favourites_count == 1 + + # General fallout: Can't unfavorite stuff anymore. Acceptable for remote users. + end +end From 07bf36142b57f0787717a6cf48a0e8619475abb3 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 6 Jan 2021 12:49:18 +0100 Subject: [PATCH 2/2] Resilience Test: Add notification check for killing likes. --- test/pleroma/resilience_test.exs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/pleroma/resilience_test.exs b/test/pleroma/resilience_test.exs index 26fa462de..9dc5d0dd6 100644 --- a/test/pleroma/resilience_test.exs +++ b/test/pleroma/resilience_test.exs @@ -8,13 +8,13 @@ defmodule Pleroma.ResilienceTest do import Pleroma.Factory alias Pleroma.Activity - alias Pleroma.Web.CommonAPI alias Pleroma.Repo + alias Pleroma.Web.CommonAPI alias Pleroma.Web.MastodonAPI.StatusView setup do # user = insert(:user) - %{user: user, conn: conn} = oauth_access(["write:statuses"]) + %{user: user, conn: conn} = oauth_access(["write", "read"]) other_user = insert(:user) {:ok, post_one} = CommonAPI.post(user, %{status: "Here is a post"}) @@ -54,8 +54,17 @@ test "after destruction of like activities, things still work", %{ assert liking_user["id"] == other_user.id + # We have one notification + [notification] = + conn + |> get("/api/v1/notifications") + |> json_response(200) + + assert notification["type"] == "favourite" + # Destroying the like Repo.delete(like) + post = Repo.get(Activity, post.id) # Rendering the liked status rendered_for_user = StatusView.render("show.json", %{activity: post, for: user}) @@ -73,6 +82,13 @@ test "after destruction of like activities, things still work", %{ assert liking_user["id"] == other_user.id + # Notification is removed + + assert [] == + conn + |> get("/api/v1/notifications") + |> json_response(200) + # Favoriting again doesn't hurt {:ok, _like_two} = CommonAPI.favorite(other_user, post.id)