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.

113 lines
4.1 KiB

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