undo_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. end
  45. context 'with Accept' do
  46. let(:recipient) { Fabricate(:account) }
  47. let(:object_json) do
  48. {
  49. id: 'bar',
  50. type: 'Accept',
  51. actor: ActivityPub::TagManager.instance.uri_for(sender),
  52. object: 'follow-to-revoke',
  53. }
  54. end
  55. before do
  56. recipient.follow!(sender, uri: 'follow-to-revoke')
  57. end
  58. it 'deletes follow from recipient to sender' do
  59. subject.perform
  60. expect(recipient.following?(sender)).to be false
  61. end
  62. it 'creates a follow request from recipient to sender' do
  63. subject.perform
  64. expect(recipient.requested?(sender)).to be true
  65. end
  66. end
  67. context 'with Block' do
  68. let(:recipient) { Fabricate(:account) }
  69. let(:object_json) do
  70. {
  71. id: 'bar',
  72. type: 'Block',
  73. actor: ActivityPub::TagManager.instance.uri_for(sender),
  74. object: ActivityPub::TagManager.instance.uri_for(recipient),
  75. }
  76. end
  77. before do
  78. sender.block!(recipient)
  79. end
  80. it 'deletes block from sender to recipient' do
  81. subject.perform
  82. expect(sender.blocking?(recipient)).to be false
  83. end
  84. end
  85. context 'with Follow' do
  86. let(:recipient) { Fabricate(:account) }
  87. let(:object_json) do
  88. {
  89. id: 'bar',
  90. type: 'Follow',
  91. actor: ActivityPub::TagManager.instance.uri_for(sender),
  92. object: ActivityPub::TagManager.instance.uri_for(recipient),
  93. }
  94. end
  95. before do
  96. sender.follow!(recipient)
  97. end
  98. it 'deletes follow from sender to recipient' do
  99. subject.perform
  100. expect(sender.following?(recipient)).to be false
  101. end
  102. end
  103. context 'with Like' do
  104. let(:status) { Fabricate(:status) }
  105. let(:object_json) do
  106. {
  107. id: 'bar',
  108. type: 'Like',
  109. actor: ActivityPub::TagManager.instance.uri_for(sender),
  110. object: ActivityPub::TagManager.instance.uri_for(status),
  111. }
  112. end
  113. before do
  114. Fabricate(:favourite, account: sender, status: status)
  115. end
  116. it 'deletes favourite from sender to status' do
  117. subject.perform
  118. expect(sender.favourited?(status)).to be false
  119. end
  120. end
  121. end
  122. end