The code powering m.abunchtell.com https://m.abunchtell.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

150 行
4.2 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 Audio object' do
  61. let(:object) do
  62. {
  63. '@context': 'https://www.w3.org/ns/activitystreams',
  64. id: "https://#{valid_domain}/@foo/1234",
  65. type: 'Audio',
  66. name: 'Nyan Cat 10 hours remix',
  67. attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
  68. url: [
  69. {
  70. type: 'Link',
  71. mimeType: 'application/x-bittorrent',
  72. href: "https://#{valid_domain}/12345.torrent",
  73. },
  74. {
  75. type: 'Link',
  76. mimeType: 'text/html',
  77. href: "https://#{valid_domain}/watch?v=12345",
  78. },
  79. ],
  80. }
  81. end
  82. it 'creates status' do
  83. status = sender.statuses.first
  84. expect(status).to_not be_nil
  85. expect(status.url).to eq "https://#{valid_domain}/watch?v=12345"
  86. expect(strip_tags(status.text)).to eq "Nyan Cat 10 hours remix https://#{valid_domain}/watch?v=12345"
  87. end
  88. end
  89. context 'with Event object' do
  90. let(:object) do
  91. {
  92. '@context': 'https://www.w3.org/ns/activitystreams',
  93. id: "https://#{valid_domain}/@foo/1234",
  94. type: 'Event',
  95. name: "Let's change the world",
  96. attributedTo: ActivityPub::TagManager.instance.uri_for(sender)
  97. }
  98. end
  99. it 'creates status' do
  100. status = sender.statuses.first
  101. expect(status).to_not be_nil
  102. expect(status.url).to eq "https://#{valid_domain}/@foo/1234"
  103. expect(strip_tags(status.text)).to eq "Let's change the world https://#{valid_domain}/@foo/1234"
  104. end
  105. end
  106. context 'with wrong id' do
  107. let(:note) do
  108. {
  109. '@context': 'https://www.w3.org/ns/activitystreams',
  110. id: "https://real.address/@foo/1234",
  111. type: 'Note',
  112. content: 'Lorem ipsum',
  113. attributedTo: ActivityPub::TagManager.instance.uri_for(sender),
  114. }
  115. end
  116. let(:object) do
  117. temp = note.dup
  118. temp[:id] = 'https://fake.address/@foo/5678'
  119. temp
  120. end
  121. it 'does not create status' do
  122. expect(sender.statuses.first).to be_nil
  123. end
  124. end
  125. end
  126. end