Skip to content

Commit

Permalink
Create Report record when a Flag activity comes in
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Nov 27, 2024
1 parent 2f2be1c commit fb787d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/services/federails/moderation/report_creation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ def initialize(activity)
end

def call
Rails.logger.debug @activity.inspect
Report.create!(
federated_url: @activity["id"],
content: @activity["content"]
)
end
end
end
30 changes: 30 additions & 0 deletions spec/services/report_creation_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
RSpec.describe Federails::Moderation::ReportCreationService do
let(:object) { create :user }
let(:actor) { create :distant_actor }
let(:valid_activity) { {
"@context" => "https://www.w3.org/ns/activitystreams",
"id" => "https://mastodon.me.uk/d977f377-214b-4efd-8a47-70a37fb7ea20",
"type" => "Flag",
"actor" => actor.federated_url,
"content" => "I don't like spiders",
"object" => [
object.federails_actor.federated_url
]
} }

it "should create a new Report when passed a valid activity" do
expect { described_class.call(valid_activity) }.to change(Federails::Moderation::Report, :count).by(1)
end

context "when creating a new report" do
let(:report) { described_class.call(valid_activity) }

it "stores activity content in new report" do
expect(report.content).to eq "I don't like spiders"
end

it "stores activity id in new report" do
expect(report.federated_url).to eq "https://mastodon.me.uk/d977f377-214b-4efd-8a47-70a37fb7ea20"
end
end
end

0 comments on commit fb787d3

Please sign in to comment.