delete_spec.rb 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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' do
  40. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  41. end
  42. end
  43. end
  44. context 'when the status has been reported' do
  45. describe '#perform' do
  46. subject { described_class.new(json, sender) }
  47. let!(:reporter) { Fabricate(:account) }
  48. before do
  49. reporter.reports.create!(target_account: status.account, status_ids: [status.id], forwarded: false)
  50. subject.perform
  51. end
  52. it 'marks the status as deleted' do
  53. expect(Status.find_by(id: status.id)).to be_nil
  54. end
  55. it 'actually keeps a copy for inspection' do
  56. expect(Status.with_discarded.find_by(id: status.id)).to_not be_nil
  57. end
  58. end
  59. end
  60. end