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.

86 lines
2.9 KiB

  1. require 'rails_helper'
  2. RSpec.describe ProcessMentionsService, type: :service do
  3. let(:account) { Fabricate(:account, username: 'alice') }
  4. let(:visibility) { :public }
  5. let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: visibility) }
  6. context 'OStatus with public toot' do
  7. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
  8. subject { ProcessMentionsService.new }
  9. before do
  10. stub_request(:post, remote_user.salmon_url)
  11. subject.call(status)
  12. end
  13. it 'creates a mention' do
  14. expect(remote_user.mentions.where(status: status).count).to eq 1
  15. end
  16. it 'posts to remote user\'s Salmon end point' do
  17. expect(a_request(:post, remote_user.salmon_url)).to have_been_made.once
  18. end
  19. end
  20. context 'OStatus with private toot' do
  21. let(:visibility) { :private }
  22. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
  23. subject { ProcessMentionsService.new }
  24. before do
  25. stub_request(:post, remote_user.salmon_url)
  26. subject.call(status)
  27. end
  28. it 'does not create a mention' do
  29. expect(remote_user.mentions.where(status: status).count).to eq 0
  30. end
  31. it 'does not post to remote user\'s Salmon end point' do
  32. expect(a_request(:post, remote_user.salmon_url)).to_not have_been_made
  33. end
  34. end
  35. context 'ActivityPub' do
  36. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  37. subject { ProcessMentionsService.new }
  38. before do
  39. stub_request(:post, remote_user.inbox_url)
  40. subject.call(status)
  41. end
  42. it 'creates a mention' do
  43. expect(remote_user.mentions.where(status: status).count).to eq 1
  44. end
  45. it 'sends activity to the inbox' do
  46. expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
  47. end
  48. end
  49. context 'Temporarily-unreachable ActivityPub user' do
  50. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) }
  51. subject { ProcessMentionsService.new }
  52. before do
  53. stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404)
  54. stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500)
  55. stub_request(:post, remote_user.inbox_url)
  56. subject.call(status)
  57. end
  58. it 'creates a mention' do
  59. expect(remote_user.mentions.where(status: status).count).to eq 1
  60. end
  61. it 'sends activity to the inbox' do
  62. expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
  63. end
  64. end
  65. end