logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

process_mentions_service_spec.rb (2219B)


  1. require 'rails_helper'
  2. RSpec.describe ProcessMentionsService do
  3. let(:account) { Fabricate(:account, username: 'alice') }
  4. let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}") }
  5. context 'OStatus' do
  6. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com') }
  7. subject { ProcessMentionsService.new }
  8. before do
  9. stub_request(:post, remote_user.salmon_url)
  10. subject.call(status)
  11. end
  12. it 'creates a mention' do
  13. expect(remote_user.mentions.where(status: status).count).to eq 1
  14. end
  15. it 'posts to remote user\'s Salmon end point' do
  16. expect(a_request(:post, remote_user.salmon_url)).to have_been_made.once
  17. end
  18. end
  19. context 'ActivityPub' do
  20. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  21. subject { ProcessMentionsService.new }
  22. before do
  23. stub_request(:post, remote_user.inbox_url)
  24. subject.call(status)
  25. end
  26. it 'creates a mention' do
  27. expect(remote_user.mentions.where(status: status).count).to eq 1
  28. end
  29. it 'sends activity to the inbox' do
  30. expect(a_request(:post, remote_user.inbox_url)).to have_been_made.once
  31. end
  32. end
  33. context 'Temporarily-unreachable ActivityPub user' do
  34. let(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) }
  35. subject { ProcessMentionsService.new }
  36. before do
  37. stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404)
  38. stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500)
  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. end