Improve test coverage

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-05-03 12:58:07 +02:00
parent 999a33c7c3
commit 63a23748ac
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
4 changed files with 89 additions and 5 deletions

View File

@ -13,12 +13,12 @@ defmodule Mobilizon.Web.Email.Follow do
alias Mobilizon.Web.Email
@doc """
Send follow notification to admins if the followed actor
Send follow notification to admins if the followed actor is the relay and the actor follower is an instance
"""
@spec send_notification_to_admins(Follower.t()) :: :ok
def send_notification_to_admins(
%Follower{
# approved: false,
approved: false,
actor: %Actor{type: :Application} = follower,
target_actor: %Actor{id: target_actor_id}
} = _follow

View File

@ -1243,7 +1243,7 @@ msgstr "Your participation to event %{title} has been approved"
#, elixir-autogen, elixir-format
#: lib/web/templates/email/report.html.heex:41
msgid "<b>%{reporter}</b> reported the following content."
msgstr "%{reporter_name} (%{reporter_username}) reported the following content."
msgstr "<b>%{reporter}</b> reported the following content."
#, elixir-autogen, elixir-format
#: lib/web/templates/email/report.text.eex:5

View File

@ -5,8 +5,11 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
import Mobilizon.Factory
alias Mobilizon.Actors
alias Mobilizon.Actors.Follower
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Transmogrifier}
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Relay, Transmogrifier}
alias Mobilizon.Service.HTTP.ActivityPub.Mock
alias Mobilizon.Users.User
import Swoosh.TestAssertions
describe "handle incoming follow requests" do
test "it works only for groups" do
@ -99,6 +102,83 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
# assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
# assert User.check_follow(User.get_by_ap_id(data["actor"]), user)
# end
test "it works for accepting instance follow from user" do
%User{} = insert(:user, email: "loulou@example.com", role: :administrator)
relay = Relay.get_actor()
actor_data =
File.read!("test/fixtures/mastodon-actor.json")
|> Jason.decode!()
Mock
|> expect(:call, fn
%{method: :get, url: "https://social.tcit.fr/users/tcit"}, _opts ->
{:ok,
%Tesla.Env{
status: 200,
body: Map.put(actor_data, "id", "https://social.tcit.fr/users/tcit")
}}
end)
data =
File.read!("test/fixtures/mastodon-follow-activity.json")
|> Jason.decode!()
|> Map.put("object", relay.url)
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
assert data["actor"] == "https://social.tcit.fr/users/tcit"
assert data["type"] == "Follow"
assert data["id"] == "https://social.tcit.fr/users/tcit#follows/2"
follow = Actors.check_follow(Actors.get_actor_by_url!(data["actor"], true), relay)
assert follow
refute follow.approved
refute_email_sent()
end
test "it works for accepting instance follow from other instance" do
%User{email: admin_email} = insert(:user, email: "loulou@example.com", role: :administrator)
relay = Relay.get_actor()
actor_data =
File.read!("test/fixtures/mastodon-actor.json")
|> Jason.decode!()
Mock
|> expect(:call, fn
%{method: :get, url: "https://mobilizon.fr/relay"}, _opts ->
{:ok,
%Tesla.Env{
status: 200,
body:
actor_data
|> Map.put("id", "https://mobilizon.fr/relay")
|> Map.put("type", "Application")
}}
end)
data =
File.read!("test/fixtures/mastodon-follow-activity.json")
|> Jason.decode!()
|> Map.put("actor", "https://mobilizon.fr/relay")
|> Map.put("id", "https://mobilizon.fr/relay#follows/2")
|> Map.put("object", relay.url)
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
assert data["actor"] == "https://mobilizon.fr/relay"
assert data["type"] == "Follow"
assert data["id"] == "https://mobilizon.fr/relay#follows/2"
follow = Actors.check_follow(Actors.get_actor_by_url!(data["actor"], true), relay)
assert follow
refute follow.approved
assert_email_sent(to: admin_email)
end
end
describe "handle incoming follow accept activities" do

View File

@ -7,10 +7,11 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
alias Mobilizon.Actors.Actor
alias Mobilizon.Config
alias Mobilizon.Events.Event
alias Mobilizon.GraphQL.AbsintheHelpers
alias Mobilizon.Reports.{Note, Report}
alias Mobilizon.Users.User
alias Mobilizon.GraphQL.AbsintheHelpers
import Swoosh.TestAssertions
describe "Resolver: Report a content" do
@create_report_mutation """
@ -41,6 +42,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
end
test "create_report/3 creates a report", %{conn: conn} do
%User{email: admin_email} = insert(:user, email: "loulou@example.com", role: :administrator)
%User{} = user_reporter = insert(:user)
%Actor{} = reporter = insert(:actor, user: user_reporter)
%Actor{} = reported = insert(:actor)
@ -65,6 +67,8 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
assert res["data"]["createReport"]["reporter"]["id"] ==
to_string(reporter.id)
assert_email_sent(to: admin_email)
end
test "create_report/3 without being connected doesn't create any report", %{conn: conn} do