accept_spec.rb 1.9 KB

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