The code powering m.abunchtell.com https://m.abunchtell.com
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

97 linhas
2.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service 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. context 'with wrong id' do
  61. let(:note) do
  62. {
  63. '@context': 'https://www.w3.org/ns/activitystreams',
  64. id: "https://real.address/@foo/1234",
  65. type: 'Note',
  66. content: 'Lorem ipsum',
  67. attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
  68. }
  69. end
  70. let(:object) do
  71. temp = note.dup
  72. temp[:id] = 'https://fake.address/@foo/5678'
  73. temp
  74. end
  75. it 'does not create status' do
  76. expect(sender.statuses.first).to be_nil
  77. end
  78. end
  79. end
  80. end