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.

148 lines
4.1 KiB

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