undo_spec.rb 4.4 KB

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