remove_status_service_spec.rb 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe RemoveStatusService, :sidekiq_inline, type: :service do
  4. subject { described_class.new }
  5. let!(:alice) { Fabricate(:account) }
  6. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  7. let!(:jeff) { Fabricate(:account) }
  8. let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  9. let!(:bill) { Fabricate(:account, username: 'bill', protocol: :activitypub, domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
  10. before do
  11. stub_request(:post, hank.inbox_url).to_return(status: 200)
  12. stub_request(:post, bill.inbox_url).to_return(status: 200)
  13. jeff.follow!(alice)
  14. hank.follow!(alice)
  15. end
  16. context 'when removed status is not a reblog' do
  17. let!(:media_attachment) { Fabricate(:media_attachment, account: alice) }
  18. let!(:status) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct} ThisIsASecret", media_ids: [media_attachment.id]) }
  19. before do
  20. FavouriteService.new.call(jeff, status)
  21. Fabricate(:status, account: bill, reblog: status, uri: 'hoge')
  22. end
  23. it 'removes status from author\'s home feed' do
  24. subject.call(status)
  25. expect(HomeFeed.new(alice).get(10).pluck(:id)).to_not include(status.id)
  26. end
  27. it 'removes status from local follower\'s home feed' do
  28. subject.call(status)
  29. expect(HomeFeed.new(jeff).get(10).pluck(:id)).to_not include(status.id)
  30. end
  31. it 'publishes to public media timeline' do
  32. allow(redis).to receive(:publish).with(any_args)
  33. subject.call(status)
  34. expect(redis).to have_received(:publish).with('timeline:public:media', Oj.dump(event: :delete, payload: status.id.to_s))
  35. end
  36. it 'sends Delete activity to followers' do
  37. subject.call(status)
  38. expect(a_request(:post, hank.inbox_url).with(
  39. body: hash_including({
  40. 'type' => 'Delete',
  41. 'object' => {
  42. 'type' => 'Tombstone',
  43. 'id' => ActivityPub::TagManager.instance.uri_for(status),
  44. 'atomUri' => OStatus::TagManager.instance.uri_for(status),
  45. },
  46. })
  47. )).to have_been_made.once
  48. end
  49. it 'sends Delete activity to rebloggers' do
  50. subject.call(status)
  51. expect(a_request(:post, bill.inbox_url).with(
  52. body: hash_including({
  53. 'type' => 'Delete',
  54. 'object' => {
  55. 'type' => 'Tombstone',
  56. 'id' => ActivityPub::TagManager.instance.uri_for(status),
  57. 'atomUri' => OStatus::TagManager.instance.uri_for(status),
  58. },
  59. })
  60. )).to have_been_made.once
  61. end
  62. it 'remove status from notifications' do
  63. expect { subject.call(status) }.to change {
  64. Notification.where(activity_type: 'Favourite', from_account: jeff, account: alice).count
  65. }.from(1).to(0)
  66. end
  67. end
  68. context 'when removed status is a private self-reblog' do
  69. let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :private) }
  70. let!(:status) { ReblogService.new.call(alice, original_status) }
  71. it 'sends Undo activity to followers' do
  72. subject.call(status)
  73. expect(a_request(:post, hank.inbox_url).with(
  74. body: hash_including({
  75. 'type' => 'Undo',
  76. 'object' => hash_including({
  77. 'type' => 'Announce',
  78. 'object' => ActivityPub::TagManager.instance.uri_for(original_status),
  79. }),
  80. })
  81. )).to have_been_made.once
  82. end
  83. end
  84. context 'when removed status is public self-reblog' do
  85. let!(:original_status) { Fabricate(:status, account: alice, text: 'Hello ThisIsASecret', visibility: :public) }
  86. let!(:status) { ReblogService.new.call(alice, original_status) }
  87. it 'sends Undo activity to followers' do
  88. subject.call(status)
  89. expect(a_request(:post, hank.inbox_url).with(
  90. body: hash_including({
  91. 'type' => 'Undo',
  92. 'object' => hash_including({
  93. 'type' => 'Announce',
  94. 'object' => ActivityPub::TagManager.instance.uri_for(original_status),
  95. }),
  96. })
  97. )).to have_been_made.once
  98. end
  99. end
  100. context 'when removed status is a reblog of a non-follower' do
  101. let!(:original_status) { Fabricate(:status, account: bill, text: 'Hello ThisIsASecret', visibility: :public) }
  102. let!(:status) { ReblogService.new.call(alice, original_status) }
  103. it 'sends Undo activity to followers' do
  104. subject.call(status)
  105. expect(a_request(:post, bill.inbox_url).with(
  106. body: hash_including({
  107. 'type' => 'Undo',
  108. 'object' => hash_including({
  109. 'type' => 'Announce',
  110. 'object' => ActivityPub::TagManager.instance.uri_for(original_status),
  111. }),
  112. })
  113. )).to have_been_made.once
  114. end
  115. end
  116. end