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.

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