process_mentions_service_spec.rb 2.8 KB

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