delete_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::Activity::Delete do
  4. let(:sender) { Fabricate(:account, domain: 'example.com') }
  5. let(:status) { Fabricate(:status, account: sender, uri: 'foobar') }
  6. let(:json) do
  7. {
  8. '@context': 'https://www.w3.org/ns/activitystreams',
  9. id: 'foo',
  10. type: 'Delete',
  11. actor: ActivityPub::TagManager.instance.uri_for(sender),
  12. object: ActivityPub::TagManager.instance.uri_for(status),
  13. signature: 'foo',
  14. }.with_indifferent_access
  15. end
  16. describe '#perform' do
  17. subject { described_class.new(json, sender) }
  18. before do
  19. subject.perform
  20. end
  21. it 'deletes sender\'s status' do
  22. expect(Status.find_by(id: status.id)).to be_nil
  23. end
  24. end
  25. context 'when the status has been reblogged' do
  26. describe '#perform' do
  27. subject { described_class.new(json, sender) }
  28. let!(:reblogger) { Fabricate(:account) }
  29. let!(:follower) { Fabricate(:account, username: 'follower', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  30. let!(:reblog) { Fabricate(:status, account: reblogger, reblog: status) }
  31. before do
  32. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  33. follower.follow!(reblogger)
  34. subject.perform
  35. end
  36. it 'deletes sender\'s status' do
  37. expect(Status.find_by(id: status.id)).to be_nil
  38. end
  39. it 'sends delete activity to followers of rebloggers', :inline_jobs do
  40. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  41. end
  42. it 'deletes the reblog' do
  43. expect { reblog.reload }.to raise_error(ActiveRecord::RecordNotFound)
  44. end
  45. end
  46. end
  47. context 'when the status has been reported' do
  48. describe '#perform' do
  49. subject { described_class.new(json, sender) }
  50. let!(:reporter) { Fabricate(:account) }
  51. before do
  52. reporter.reports.create!(target_account: status.account, status_ids: [status.id], forwarded: false)
  53. subject.perform
  54. end
  55. it 'marks the status as deleted' do
  56. expect(Status.find_by(id: status.id)).to be_nil
  57. end
  58. it 'actually keeps a copy for inspection' do
  59. expect(Status.with_discarded.find_by(id: status.id)).to_not be_nil
  60. end
  61. end
  62. end
  63. end