From 77b48cb4ce81165a3a4f28e91b8f22dd510d3d00 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 2 Aug 2020 16:36:55 -0500 Subject: [PATCH 1/2] Factory: Add report_activity_factory --- test/support/factory.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/support/factory.ex b/test/support/factory.ex index 635d83650..4c09d65b6 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -297,6 +297,30 @@ def follow_activity_factory do } end + def report_activity_factory(attrs \\ %{}) do + user = attrs[:user] || insert(:user) + activity = attrs[:activity] || insert(:note_activity) + state = attrs[:state] || "open" + + data = %{ + "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(), + "actor" => user.ap_id, + "type" => "Flag", + "object" => [activity.actor, activity.data["id"]], + "published" => DateTime.utc_now() |> DateTime.to_iso8601(), + "to" => [], + "cc" => [activity.actor], + "context" => activity.data["context"], + "state" => state, + } + + %Pleroma.Activity{ + data: data, + actor: data["actor"], + recipients: data["to"] ++ data["cc"] + } + end + def oauth_app_factory do %Pleroma.Web.OAuth.App{ client_name: sequence(:client_name, &"Some client #{&1}"), From f9301044ed9c80314d1c313035359956cf5dbc1a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 2 Aug 2020 16:37:33 -0500 Subject: [PATCH 2/2] Add ReportNote test --- test/report_note_test.exs | 16 ++++++++++++++++ test/support/factory.ex | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/report_note_test.exs diff --git a/test/report_note_test.exs b/test/report_note_test.exs new file mode 100644 index 000000000..25c1d6a61 --- /dev/null +++ b/test/report_note_test.exs @@ -0,0 +1,16 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.ReportNoteTest do + alias Pleroma.ReportNote + use Pleroma.DataCase + import Pleroma.Factory + + test "create/3" do + user = insert(:user) + report = insert(:report_activity) + assert {:ok, note} = ReportNote.create(user.id, report.id, "naughty boy") + assert note.content == "naughty boy" + end +end diff --git a/test/support/factory.ex b/test/support/factory.ex index 4c09d65b6..486eda8da 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -311,7 +311,7 @@ def report_activity_factory(attrs \\ %{}) do "to" => [], "cc" => [activity.actor], "context" => activity.data["context"], - "state" => state, + "state" => state } %Pleroma.Activity{