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.

77 lines
2.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe ReblogService, type: :service do
  3. let(:alice) { Fabricate(:account, username: 'alice') }
  4. context 'creates a reblog with appropriate visibility' do
  5. let(:bob) { Fabricate(:account, username: 'bob') }
  6. let(:visibility) { :public }
  7. let(:reblog_visibility) { :public }
  8. let(:status) { Fabricate(:status, account: bob, visibility: visibility) }
  9. subject { ReblogService.new }
  10. before do
  11. subject.call(alice, status, visibility: reblog_visibility)
  12. end
  13. describe 'boosting privately' do
  14. let(:reblog_visibility) { :private }
  15. it 'reblogs privately' do
  16. expect(status.reblogs.first.visibility).to eq 'private'
  17. end
  18. end
  19. end
  20. context 'OStatus' do
  21. let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com') }
  22. let(:status) { Fabricate(:status, account: bob, uri: 'tag:example.com;something:something') }
  23. subject { ReblogService.new }
  24. before do
  25. stub_request(:post, 'http://salmon.example.com')
  26. subject.call(alice, status)
  27. end
  28. it 'creates a reblog' do
  29. expect(status.reblogs.count).to eq 1
  30. end
  31. it 'sends a Salmon slap for a remote reblog' do
  32. expect(a_request(:post, 'http://salmon.example.com')).to have_been_made
  33. end
  34. end
  35. context 'ActivityPub' do
  36. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  37. let(:status) { Fabricate(:status, account: bob) }
  38. subject { ReblogService.new }
  39. before do
  40. stub_request(:post, bob.inbox_url)
  41. allow(ActivityPub::DistributionWorker).to receive(:perform_async)
  42. subject.call(alice, status)
  43. end
  44. it 'creates a reblog' do
  45. expect(status.reblogs.count).to eq 1
  46. end
  47. describe 'after_create_commit :store_uri' do
  48. it 'keeps consistent reblog count' do
  49. expect(status.reblogs.count).to eq 1
  50. end
  51. end
  52. it 'distributes to followers' do
  53. expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
  54. end
  55. it 'sends an announce activity to the author' do
  56. expect(a_request(:post, bob.inbox_url)).to have_been_made.once
  57. end
  58. end
  59. end