process_mentions_service_spec.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. subject { ProcessMentionsService.new }
  7. context 'OStatus with public toot' do
  8. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
  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. before do
  21. stub_request(:post, remote_user.salmon_url)
  22. subject.call(status)
  23. end
  24. it 'does not create a mention' do
  25. expect(remote_user.mentions.where(status: status).count).to eq 0
  26. end
  27. it 'does not post to remote user\'s Salmon end point' do
  28. expect(a_request(:post, remote_user.salmon_url)).to_not have_been_made
  29. end
  30. end
  31. context 'ActivityPub' do
  32. context do
  33. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  34. before do
  35. stub_request(:post, remote_user.inbox_url)
  36. subject.call(status)
  37. end
  38. it 'creates a mention' do
  39. expect(remote_user.mentions.where(status: status).count).to eq 1
  40. end
  41. it 'sends activity to the inbox' do
  42. expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
  43. end
  44. end
  45. context 'with an IDN domain' do
  46. let(:remote_user) { Fabricate(:account, username: 'sneak', protocol: :activitypub, domain: 'xn--hresiar-mxa.ch', inbox_url: 'http://example.com/inbox') }
  47. let(:status) { Fabricate(:status, account: account, text: "Hello @sneak@hæresiar.ch") }
  48. before do
  49. stub_request(:post, remote_user.inbox_url)
  50. subject.call(status)
  51. end
  52. it 'creates a mention' do
  53. expect(remote_user.mentions.where(status: status).count).to eq 1
  54. end
  55. it 'sends activity to the inbox' do
  56. expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
  57. end
  58. end
  59. end
  60. context 'Temporarily-unreachable ActivityPub user' do
  61. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) }
  62. before do
  63. stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404)
  64. stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500)
  65. stub_request(:post, remote_user.inbox_url)
  66. subject.call(status)
  67. end
  68. it 'creates a mention' do
  69. expect(remote_user.mentions.where(status: status).count).to eq 1
  70. end
  71. it 'sends activity to the inbox' do
  72. expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
  73. end
  74. end
  75. end