add_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Add do
  3. let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured', domain: 'example.com') }
  4. let(:status) { Fabricate(:status, account: sender, visibility: :private) }
  5. let(:json) do
  6. {
  7. '@context': 'https://www.w3.org/ns/activitystreams',
  8. id: 'foo',
  9. type: 'Add',
  10. actor: ActivityPub::TagManager.instance.uri_for(sender),
  11. object: ActivityPub::TagManager.instance.uri_for(status),
  12. target: sender.featured_collection_url,
  13. }.with_indifferent_access
  14. end
  15. describe '#perform' do
  16. subject { described_class.new(json, sender) }
  17. it 'creates a pin' do
  18. subject.perform
  19. expect(sender.pinned?(status)).to be true
  20. end
  21. context 'when status was not known before' do
  22. let(:service_stub) { double }
  23. let(:json) do
  24. {
  25. '@context': 'https://www.w3.org/ns/activitystreams',
  26. id: 'foo',
  27. type: 'Add',
  28. actor: ActivityPub::TagManager.instance.uri_for(sender),
  29. object: 'https://example.com/unknown',
  30. target: sender.featured_collection_url,
  31. }.with_indifferent_access
  32. end
  33. before do
  34. allow(ActivityPub::FetchRemoteStatusService).to receive(:new).and_return(service_stub)
  35. end
  36. context 'when there is a local follower' do
  37. before do
  38. account = Fabricate(:account)
  39. account.follow!(sender)
  40. end
  41. it 'fetches the status and pins it' do
  42. allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, request_id: nil|
  43. expect(uri).to eq 'https://example.com/unknown'
  44. expect(id).to eq true
  45. expect(on_behalf_of&.following?(sender)).to eq true
  46. status
  47. end
  48. subject.perform
  49. expect(service_stub).to have_received(:call)
  50. expect(sender.pinned?(status)).to be true
  51. end
  52. end
  53. context 'when there is no local follower' do
  54. it 'tries to fetch the status' do
  55. allow(service_stub).to receive(:call) do |uri, id: true, on_behalf_of: nil, request_id: nil|
  56. expect(uri).to eq 'https://example.com/unknown'
  57. expect(id).to eq true
  58. expect(on_behalf_of).to eq nil
  59. nil
  60. end
  61. subject.perform
  62. expect(service_stub).to have_received(:call)
  63. expect(sender.pinned?(status)).to be false
  64. end
  65. end
  66. end
  67. end
  68. end