flag_spec.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Flag do
  3. let(:sender) { Fabricate(:account, username: 'example.com', domain: 'example.com', uri: 'http://example.com/actor') }
  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. context 'when the reported status is public' do
  23. before do
  24. subject.perform
  25. end
  26. it 'creates a report' do
  27. report = Report.find_by(account: sender, target_account: flagged)
  28. expect(report).to_not be_nil
  29. expect(report.comment).to eq 'Boo!!'
  30. expect(report.status_ids).to eq [status.id]
  31. end
  32. end
  33. context 'when the reported status is private and should not be visible to the remote server' do
  34. let(:status) { Fabricate(:status, account: flagged, uri: 'foobar', visibility: :private) }
  35. before do
  36. subject.perform
  37. end
  38. it 'creates a report with no attached status' 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 []
  43. end
  44. end
  45. context 'when the reported status is private and the author has a follower on the remote instance' do
  46. let(:status) { Fabricate(:status, account: flagged, uri: 'foobar', visibility: :private) }
  47. let(:follower) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/users/account') }
  48. before do
  49. follower.follow!(flagged)
  50. subject.perform
  51. end
  52. it 'creates a report with the attached status' do
  53. report = Report.find_by(account: sender, target_account: flagged)
  54. expect(report).to_not be_nil
  55. expect(report.comment).to eq 'Boo!!'
  56. expect(report.status_ids).to eq [status.id]
  57. end
  58. end
  59. context 'when the reported status is private and the author mentions someone else on the remote instance' do
  60. let(:status) { Fabricate(:status, account: flagged, uri: 'foobar', visibility: :private) }
  61. let(:mentioned) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/users/account') }
  62. before do
  63. status.mentions.create(account: mentioned)
  64. subject.perform
  65. end
  66. it 'creates a report with the attached status' do
  67. report = Report.find_by(account: sender, target_account: flagged)
  68. expect(report).to_not be_nil
  69. expect(report.comment).to eq 'Boo!!'
  70. expect(report.status_ids).to eq [status.id]
  71. end
  72. end
  73. context 'when the reported status is private and the author mentions someone else on the local instance' do
  74. let(:status) { Fabricate(:status, account: flagged, uri: 'foobar', visibility: :private) }
  75. let(:mentioned) { Fabricate(:account) }
  76. before do
  77. status.mentions.create(account: mentioned)
  78. subject.perform
  79. end
  80. it 'creates a report with no attached status' do
  81. report = Report.find_by(account: sender, target_account: flagged)
  82. expect(report).to_not be_nil
  83. expect(report.comment).to eq 'Boo!!'
  84. expect(report.status_ids).to eq []
  85. end
  86. end
  87. end
  88. describe '#perform with a defined uri' do
  89. subject { described_class.new(json, sender) }
  90. let (:flag_id) { 'http://example.com/reports/1' }
  91. before do
  92. subject.perform
  93. end
  94. it 'creates a report' do
  95. report = Report.find_by(account: sender, target_account: flagged)
  96. expect(report).to_not be_nil
  97. expect(report.comment).to eq 'Boo!!'
  98. expect(report.status_ids).to eq [status.id]
  99. expect(report.uri).to eq flag_id
  100. end
  101. end
  102. end