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.

206 lines
6.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe AtomSerializer do
  3. let(:author) { Fabricate(:account, username: 'Sombra', display_name: '1337 haxxor') }
  4. let(:receiver) { Fabricate(:account, username: 'Symmetra') }
  5. before do
  6. stub_request(:get, "https://cb6e6126.ngrok.io/avatars/original/missing.png").to_return(status: 404)
  7. stub_request(:get, "https://cb6e6126.ngrok.io/headers/original/missing.png").to_return(status: 404)
  8. end
  9. describe '#author' do
  10. it 'returns dumpable XML with emojis' do
  11. account = Fabricate(:account, display_name: '💩')
  12. xml = AtomSerializer.render(AtomSerializer.new.author(account))
  13. expect(xml).to be_a String
  14. expect(xml).to match(/<poco:displayName>💩<\/poco:displayName>/)
  15. end
  16. it 'returns dumpable XML with invalid characters like \b and \v' do
  17. account = Fabricate(:account, display_name: "im l33t\b haxo\b\vr")
  18. xml = AtomSerializer.render(AtomSerializer.new.author(account))
  19. expect(xml).to be_a String
  20. expect(xml).to match(/<poco:displayName>im l33t haxor<\/poco:displayName>/)
  21. end
  22. end
  23. describe '#entry' do
  24. describe 'with deleted status' do
  25. let(:entry) do
  26. status = Fabricate(:status, account: author, text: 'boop')
  27. entry = status.stream_entry
  28. status.destroy
  29. entry
  30. end
  31. it 'returns dumpable XML' do
  32. xml = AtomSerializer.render(AtomSerializer.new.entry(entry, true))
  33. expect(xml).to be_a String
  34. expect(xml).to match(/<id>#{TagManager.instance.unique_tag(entry.created_at, entry.activity_id, 'Status')}<\/id>/)
  35. end
  36. it 'triggers delete when processed' do
  37. status = double(id: entry.activity_id)
  38. service = double
  39. allow(Status).to receive(:find_by).and_return(status)
  40. allow(RemoveStatusService).to receive(:new).and_return(service)
  41. allow(service).to receive(:call)
  42. xml = AtomSerializer.render(AtomSerializer.new.entry(entry, true))
  43. ProcessFeedService.new.call(xml, author)
  44. expect(service).to have_received(:call).with(status)
  45. end
  46. end
  47. describe 'with reblog of local user' do
  48. it 'returns dumpable XML'
  49. it 'creates a reblog'
  50. end
  51. describe 'with reblog of 3rd party user' do
  52. it 'returns dumpable XML'
  53. it 'creates a reblog with correct author'
  54. end
  55. end
  56. describe '#follow_salmon' do
  57. let(:xml) do
  58. follow = Fabricate(:follow, account: author, target_account: receiver)
  59. xml = AtomSerializer.render(AtomSerializer.new.follow_salmon(follow))
  60. follow.destroy
  61. xml
  62. end
  63. it 'returns dumpable XML' do
  64. expect(xml).to be_a String
  65. end
  66. it 'triggers follow when processed' do
  67. envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
  68. ProcessInteractionService.new.call(envelope, receiver)
  69. expect(author.following?(receiver)).to be true
  70. end
  71. end
  72. describe '#unfollow_salmon' do
  73. let(:xml) do
  74. follow = Fabricate(:follow, account: author, target_account: receiver)
  75. follow.destroy
  76. xml = AtomSerializer.render(AtomSerializer.new.unfollow_salmon(follow))
  77. author.follow!(receiver)
  78. xml
  79. end
  80. it 'returns dumpable XML' do
  81. expect(xml).to be_a String
  82. end
  83. it 'triggers unfollow when processed' do
  84. envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
  85. ProcessInteractionService.new.call(envelope, receiver)
  86. expect(author.following?(receiver)).to be false
  87. end
  88. end
  89. describe '#favourite_salmon' do
  90. let(:status) { Fabricate(:status, account: receiver, text: 'Everything by design.') }
  91. let(:xml) do
  92. favourite = Fabricate(:favourite, account: author, status: status)
  93. xml = AtomSerializer.render(AtomSerializer.new.favourite_salmon(favourite))
  94. favourite.destroy
  95. xml
  96. end
  97. it 'returns dumpable XML' do
  98. expect(xml).to be_a String
  99. end
  100. it 'triggers favourite when processed' do
  101. envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
  102. ProcessInteractionService.new.call(envelope, receiver)
  103. expect(author.favourited?(status)).to be true
  104. end
  105. end
  106. describe '#unfavourite_salmon' do
  107. let(:status) { Fabricate(:status, account: receiver, text: 'Perfect harmony.') }
  108. let(:xml) do
  109. favourite = Fabricate(:favourite, account: author, status: status)
  110. favourite.destroy
  111. xml = AtomSerializer.render(AtomSerializer.new.unfavourite_salmon(favourite))
  112. Fabricate(:favourite, account: author, status: status)
  113. xml
  114. end
  115. it 'returns dumpable XML' do
  116. expect(xml).to be_a String
  117. end
  118. it 'triggers unfavourite when processed' do
  119. envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
  120. ProcessInteractionService.new.call(envelope, receiver)
  121. expect(author.favourited?(status)).to be false
  122. end
  123. end
  124. describe '#block_salmon' do
  125. let(:xml) do
  126. block = Fabricate(:block, account: author, target_account: receiver, block: true)
  127. xml = AtomSerializer.render(AtomSerializer.new.block_salmon(block))
  128. block.destroy
  129. xml
  130. end
  131. it 'returns dumpable XML' do
  132. expect(xml).to be_a String
  133. end
  134. it 'triggers block when processed' do
  135. envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
  136. ProcessInteractionService.new.call(envelope, receiver)
  137. expect(author.blocking?(receiver)).to be true
  138. end
  139. end
  140. describe '#unblock_salmon' do
  141. let(:xml) do
  142. block = Fabricate(:block, account: author, target_account: receiver, block: true)
  143. block.destroy
  144. xml = AtomSerializer.render(AtomSerializer.new.unblock_salmon(block))
  145. author.block!(receiver)
  146. xml
  147. end
  148. it 'returns dumpable XML' do
  149. expect(xml).to be_a String
  150. end
  151. it 'triggers unblock when processed' do
  152. envelope = OStatus2::Salmon.new.pack(xml, author.keypair)
  153. ProcessInteractionService.new.call(envelope, receiver)
  154. expect(author.blocking?(receiver)).to be false
  155. end
  156. end
  157. describe '#follow_request_salmon' do
  158. it 'returns dumpable XML'
  159. it 'triggers follow request when processed'
  160. end
  161. describe '#authorize_follow_request_salmon' do
  162. it 'returns dumpable XML'
  163. it 'creates follow from follow request when processed'
  164. end
  165. describe '#reject_follow_request_salmon' do
  166. it 'returns dumpable XML'
  167. it 'deletes follow request when processed'
  168. end
  169. end