logo

mastofe

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

fetch_remote_status_service_spec.rb (2097B)


  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::FetchRemoteStatusService do
  3. include ActionView::Helpers::TextHelper
  4. let(:sender) { Fabricate(:account) }
  5. let(:recipient) { Fabricate(:account) }
  6. let(:valid_domain) { Rails.configuration.x.local_domain }
  7. let(:note) do
  8. {
  9. '@context': 'https://www.w3.org/ns/activitystreams',
  10. id: "https://#{valid_domain}/@foo/1234",
  11. type: 'Note',
  12. content: 'Lorem ipsum',
  13. attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
  14. }
  15. end
  16. subject { described_class.new }
  17. describe '#call' do
  18. before do
  19. sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
  20. stub_request(:head, 'https://example.com/watch?v=12345').to_return(status: 404, body: '')
  21. subject.call(object[:id], prefetched_body: Oj.dump(object))
  22. end
  23. context 'with Note object' do
  24. let(:object) { note }
  25. it 'creates status' do
  26. status = sender.statuses.first
  27. expect(status).to_not be_nil
  28. expect(status.text).to eq 'Lorem ipsum'
  29. end
  30. end
  31. context 'with Video object' do
  32. let(:object) do
  33. {
  34. '@context': 'https://www.w3.org/ns/activitystreams',
  35. id: "https://#{valid_domain}/@foo/1234",
  36. type: 'Video',
  37. name: 'Nyan Cat 10 hours remix',
  38. attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
  39. url: [
  40. {
  41. type: 'Link',
  42. mimeType: 'application/x-bittorrent',
  43. href: "https://#{valid_domain}/12345.torrent",
  44. },
  45. {
  46. type: 'Link',
  47. mimeType: 'text/html',
  48. href: "https://#{valid_domain}/watch?v=12345",
  49. },
  50. ],
  51. }
  52. end
  53. it 'creates status' do
  54. status = sender.statuses.first
  55. expect(status).to_not be_nil
  56. expect(status.url).to eq "https://#{valid_domain}/watch?v=12345"
  57. expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remix https://#{valid_domain}/watch?v=12345"
  58. end
  59. end
  60. end
  61. end