You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Flag do
  3. let(:sender) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
  4. let(:flagged) { Fabricate(:account) }
  5. let(:status) { Fabricate(:status, account: flagged, uri: 'foobar') }
  6. let(:flag_id) { nil }
  7. let(:json) do
  8. {
  9. '@context': 'https://www.w3.org/ns/activitystreams',
  10. id: flag_id,
  11. type: 'Flag',
  12. content: 'Boo!!',
  13. actor: ActivityPub::TagManager.instance.uri_for(sender),
  14. object: [
  15. ActivityPub::TagManager.instance.uri_for(flagged),
  16. ActivityPub::TagManager.instance.uri_for(status),
  17. ],
  18. }.with_indifferent_access
  19. end
  20. describe '#perform' do
  21. subject { described_class.new(json, sender) }
  22. before do
  23. subject.perform
  24. end
  25. it 'creates a report' do
  26. report = Report.find_by(account: sender, target_account: flagged)
  27. expect(report).to_not be_nil
  28. expect(report.comment).to eq 'Boo!!'
  29. expect(report.status_ids).to eq [status.id]
  30. end
  31. end
  32. describe '#perform with a defined uri' do
  33. subject { described_class.new(json, sender) }
  34. let (:flag_id) { 'http://example.com/reports/1' }
  35. before do
  36. subject.perform
  37. end
  38. it 'creates a report' do
  39. report = Report.find_by(account: sender, target_account: flagged)
  40. expect(report).to_not be_nil
  41. expect(report.comment).to eq 'Boo!!'
  42. expect(report.status_ids).to eq [status.id]
  43. expect(report.uri).to eq flag_id
  44. end
  45. end
  46. end