remove_status_service_spec.rb 3.8 KB

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