undo_spec.rb 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::Activity::Undo do
  4. subject { described_class.new(json, sender) }
  5. let(:sender) { Fabricate(:account, domain: 'example.com') }
  6. let(:json) do
  7. {
  8. '@context': 'https://www.w3.org/ns/activitystreams',
  9. id: 'foo',
  10. type: 'Undo',
  11. actor: ActivityPub::TagManager.instance.uri_for(sender),
  12. object: object_json,
  13. }.with_indifferent_access
  14. end
  15. describe '#perform' do
  16. context 'with Announce' do
  17. let(:status) { Fabricate(:status) }
  18. let(:object_json) do
  19. {
  20. id: 'bar',
  21. type: 'Announce',
  22. actor: ActivityPub::TagManager.instance.uri_for(sender),
  23. object: ActivityPub::TagManager.instance.uri_for(status),
  24. atomUri: 'barbar',
  25. }
  26. end
  27. context 'when not atomUri' do
  28. before do
  29. Fabricate(:status, reblog: status, account: sender, uri: 'bar')
  30. end
  31. it 'deletes the reblog' do
  32. subject.perform
  33. expect(sender.reblogged?(status)).to be false
  34. end
  35. end
  36. context 'with atomUri' do
  37. before do
  38. Fabricate(:status, reblog: status, account: sender, uri: 'barbar')
  39. end
  40. it 'deletes the reblog by atomUri' do
  41. subject.perform
  42. expect(sender.reblogged?(status)).to be false
  43. end
  44. end
  45. context 'with only object uri' do
  46. let(:object_json) { 'bar' }
  47. before do
  48. Fabricate(:status, reblog: status, account: sender, uri: 'bar')
  49. end
  50. it 'deletes the reblog by uri' do
  51. subject.perform
  52. expect(sender.reblogged?(status)).to be false
  53. end
  54. end
  55. end
  56. context 'with Accept' do
  57. let(:recipient) { Fabricate(:account) }
  58. let(:object_json) do
  59. {
  60. id: 'bar',
  61. type: 'Accept',
  62. actor: ActivityPub::TagManager.instance.uri_for(sender),
  63. object: 'follow-to-revoke',
  64. }
  65. end
  66. before do
  67. recipient.follow!(sender, uri: 'follow-to-revoke')
  68. end
  69. it 'deletes follow from recipient to sender' do
  70. subject.perform
  71. expect(recipient.following?(sender)).to be false
  72. end
  73. it 'creates a follow request from recipient to sender' do
  74. subject.perform
  75. expect(recipient.requested?(sender)).to be true
  76. end
  77. end
  78. context 'with Block' do
  79. let(:recipient) { Fabricate(:account) }
  80. let(:object_json) do
  81. {
  82. id: 'bar',
  83. type: 'Block',
  84. actor: ActivityPub::TagManager.instance.uri_for(sender),
  85. object: ActivityPub::TagManager.instance.uri_for(recipient),
  86. }
  87. end
  88. before do
  89. sender.block!(recipient, uri: 'bar')
  90. end
  91. it 'deletes block from sender to recipient' do
  92. subject.perform
  93. expect(sender.blocking?(recipient)).to be false
  94. end
  95. context 'with only object uri' do
  96. let(:object_json) { 'bar' }
  97. it 'deletes block from sender to recipient' do
  98. subject.perform
  99. expect(sender.blocking?(recipient)).to be false
  100. end
  101. end
  102. end
  103. context 'with Follow' do
  104. let(:recipient) { Fabricate(:account) }
  105. let(:object_json) do
  106. {
  107. id: 'bar',
  108. type: 'Follow',
  109. actor: ActivityPub::TagManager.instance.uri_for(sender),
  110. object: ActivityPub::TagManager.instance.uri_for(recipient),
  111. }
  112. end
  113. before do
  114. sender.follow!(recipient, uri: 'bar')
  115. end
  116. it 'deletes follow from sender to recipient' do
  117. subject.perform
  118. expect(sender.following?(recipient)).to be false
  119. end
  120. context 'with only object uri' do
  121. let(:object_json) { 'bar' }
  122. it 'deletes follow from sender to recipient' do
  123. subject.perform
  124. expect(sender.following?(recipient)).to be false
  125. end
  126. end
  127. end
  128. context 'with Like' do
  129. let(:status) { Fabricate(:status) }
  130. let(:object_json) do
  131. {
  132. id: 'bar',
  133. type: 'Like',
  134. actor: ActivityPub::TagManager.instance.uri_for(sender),
  135. object: ActivityPub::TagManager.instance.uri_for(status),
  136. }
  137. end
  138. before do
  139. Fabricate(:favourite, account: sender, status: status)
  140. end
  141. it 'deletes favourite from sender to status' do
  142. subject.perform
  143. expect(sender.favourited?(status)).to be false
  144. end
  145. end
  146. end
  147. end