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.

63 lines
2.3 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. subject { ProcessMentionsService.new }
  7. context 'ActivityPub' do
  8. context do
  9. let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  10. before do
  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. end
  17. context 'with an IDN domain' do
  18. let!(:remote_user) { Fabricate(:account, username: 'sneak', protocol: :activitypub, domain: 'xn--hresiar-mxa.ch', inbox_url: 'http://example.com/inbox') }
  19. let!(:status) { Fabricate(:status, account: account, text: "Hello @sneak@hæresiar.ch") }
  20. before do
  21. subject.call(status)
  22. end
  23. it 'creates a mention' do
  24. expect(remote_user.mentions.where(status: status).count).to eq 1
  25. end
  26. end
  27. context 'with an IDN TLD' do
  28. let!(:remote_user) { Fabricate(:account, username: 'foo', protocol: :activitypub, domain: 'xn--y9a3aq.xn--y9a3aq', inbox_url: 'http://example.com/inbox') }
  29. let!(:status) { Fabricate(:status, account: account, text: "Hello @foo@հայ.հայ") }
  30. before do
  31. subject.call(status)
  32. end
  33. it 'creates a mention' do
  34. expect(remote_user.mentions.where(status: status).count).to eq 1
  35. end
  36. end
  37. end
  38. context 'Temporarily-unreachable ActivityPub user' do
  39. let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) }
  40. before do
  41. stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404)
  42. stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500)
  43. subject.call(status)
  44. end
  45. it 'creates a mention' do
  46. expect(remote_user.mentions.where(status: status).count).to eq 1
  47. end
  48. end
  49. end