reject_spec.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::Activity::Reject do
  4. let(:sender) { Fabricate(:account) }
  5. let(:recipient) { Fabricate(:account) }
  6. let(:object_json) do
  7. {
  8. id: 'bar',
  9. type: 'Follow',
  10. actor: ActivityPub::TagManager.instance.uri_for(recipient),
  11. object: ActivityPub::TagManager.instance.uri_for(sender),
  12. }
  13. end
  14. let(:json) do
  15. {
  16. '@context': 'https://www.w3.org/ns/activitystreams',
  17. id: 'foo',
  18. type: 'Reject',
  19. actor: ActivityPub::TagManager.instance.uri_for(sender),
  20. object: object_json,
  21. }.with_indifferent_access
  22. end
  23. describe '#perform' do
  24. subject { described_class.new(json, sender) }
  25. context 'when rejecting a pending follow request by target' do
  26. before do
  27. Fabricate(:follow_request, account: recipient, target_account: sender)
  28. subject.perform
  29. end
  30. it 'does not create a follow relationship' do
  31. expect(recipient.following?(sender)).to be false
  32. end
  33. it 'removes the follow request' do
  34. expect(recipient.requested?(sender)).to be false
  35. end
  36. end
  37. context 'when rejecting a pending follow request by uri' do
  38. before do
  39. Fabricate(:follow_request, account: recipient, target_account: sender, uri: 'bar')
  40. subject.perform
  41. end
  42. it 'does not create a follow relationship' do
  43. expect(recipient.following?(sender)).to be false
  44. end
  45. it 'removes the follow request' do
  46. expect(recipient.requested?(sender)).to be false
  47. end
  48. end
  49. context 'when rejecting a pending follow request by uri only' do
  50. let(:object_json) { 'bar' }
  51. before do
  52. Fabricate(:follow_request, account: recipient, target_account: sender, uri: 'bar')
  53. subject.perform
  54. end
  55. it 'does not create a follow relationship' do
  56. expect(recipient.following?(sender)).to be false
  57. end
  58. it 'removes the follow request' do
  59. expect(recipient.requested?(sender)).to be false
  60. end
  61. end
  62. context 'when rejecting an existing follow relationship by target' do
  63. before do
  64. Fabricate(:follow, account: recipient, target_account: sender)
  65. subject.perform
  66. end
  67. it 'removes the follow relationship' do
  68. expect(recipient.following?(sender)).to be false
  69. end
  70. it 'does not create a follow request' do
  71. expect(recipient.requested?(sender)).to be false
  72. end
  73. end
  74. context 'when rejecting an existing follow relationship by uri' do
  75. before do
  76. Fabricate(:follow, account: recipient, target_account: sender, uri: 'bar')
  77. subject.perform
  78. end
  79. it 'removes the follow relationship' do
  80. expect(recipient.following?(sender)).to be false
  81. end
  82. it 'does not create a follow request' do
  83. expect(recipient.requested?(sender)).to be false
  84. end
  85. end
  86. context 'when rejecting an existing follow relationship by uri only' do
  87. let(:object_json) { 'bar' }
  88. before do
  89. Fabricate(:follow, account: recipient, target_account: sender, uri: 'bar')
  90. subject.perform
  91. end
  92. it 'removes the follow relationship' do
  93. expect(recipient.following?(sender)).to be false
  94. end
  95. it 'does not create a follow request' do
  96. expect(recipient.requested?(sender)).to be false
  97. end
  98. end
  99. end
  100. context 'when given a relay' do
  101. subject { described_class.new(json, sender) }
  102. let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }
  103. let(:json) do
  104. {
  105. '@context': 'https://www.w3.org/ns/activitystreams',
  106. id: 'foo',
  107. type: 'Reject',
  108. actor: ActivityPub::TagManager.instance.uri_for(sender),
  109. object: {
  110. id: 'https://abc-123/456',
  111. type: 'Follow',
  112. actor: ActivityPub::TagManager.instance.uri_for(recipient),
  113. object: ActivityPub::TagManager.instance.uri_for(sender),
  114. },
  115. }.with_indifferent_access
  116. end
  117. it 'marks the relay as rejected' do
  118. subject.perform
  119. expect(relay.reload.rejected?).to be true
  120. end
  121. end
  122. end