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.

72 lines
2.1 KiB

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