accept_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Accept do
  3. let(:sender) { Fabricate(:account) }
  4. let(:recipient) { Fabricate(:account) }
  5. let(:json) do
  6. {
  7. '@context': 'https://www.w3.org/ns/activitystreams',
  8. id: 'foo',
  9. type: 'Accept',
  10. actor: ActivityPub::TagManager.instance.uri_for(sender),
  11. object: {
  12. id: 'bar',
  13. type: 'Follow',
  14. actor: ActivityPub::TagManager.instance.uri_for(recipient),
  15. object: ActivityPub::TagManager.instance.uri_for(sender),
  16. },
  17. }.with_indifferent_access
  18. end
  19. describe '#perform' do
  20. subject { described_class.new(json, sender) }
  21. before do
  22. allow(RemoteAccountRefreshWorker).to receive(:perform_async)
  23. Fabricate(:follow_request, account: recipient, target_account: sender)
  24. subject.perform
  25. end
  26. it 'creates a follow relationship' do
  27. expect(recipient.following?(sender)).to be true
  28. end
  29. it 'removes the follow request' do
  30. expect(recipient.requested?(sender)).to be false
  31. end
  32. it 'queues a refresh' do
  33. expect(RemoteAccountRefreshWorker).to have_received(:perform_async).with(sender.id)
  34. end
  35. end
  36. context 'given a relay' do
  37. let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }
  38. let(:json) do
  39. {
  40. '@context': 'https://www.w3.org/ns/activitystreams',
  41. id: 'foo',
  42. type: 'Accept',
  43. actor: ActivityPub::TagManager.instance.uri_for(sender),
  44. object: {
  45. id: 'https://abc-123/456',
  46. type: 'Follow',
  47. actor: ActivityPub::TagManager.instance.uri_for(recipient),
  48. object: ActivityPub::TagManager.instance.uri_for(sender),
  49. },
  50. }.with_indifferent_access
  51. end
  52. subject { described_class.new(json, sender) }
  53. it 'marks the relay as accepted' do
  54. subject.perform
  55. expect(relay.reload.accepted?).to be true
  56. end
  57. end
  58. end