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.

221 lines
5.0 KiB

  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Create do
  3. let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers') }
  4. let(:json) do
  5. {
  6. '@context': 'https://www.w3.org/ns/activitystreams',
  7. id: 'foo',
  8. type: 'Create',
  9. actor: ActivityPub::TagManager.instance.uri_for(sender),
  10. object: object_json,
  11. }.with_indifferent_access
  12. end
  13. subject { described_class.new(json, sender) }
  14. before do
  15. stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
  16. end
  17. describe '#perform' do
  18. before do
  19. subject.perform
  20. end
  21. context 'standalone' do
  22. let(:object_json) do
  23. {
  24. id: 'bar',
  25. type: 'Note',
  26. content: 'Lorem ipsum',
  27. }
  28. end
  29. it 'creates status' do
  30. status = sender.statuses.first
  31. expect(status).to_not be_nil
  32. expect(status.text).to eq 'Lorem ipsum'
  33. end
  34. it 'missing to/cc defaults to direct privacy' do
  35. status = sender.statuses.first
  36. expect(status).to_not be_nil
  37. expect(status.visibility).to eq 'direct'
  38. end
  39. end
  40. context 'public' do
  41. let(:object_json) do
  42. {
  43. id: 'bar',
  44. type: 'Note',
  45. content: 'Lorem ipsum',
  46. to: 'https://www.w3.org/ns/activitystreams#Public',
  47. }
  48. end
  49. it 'creates status' do
  50. status = sender.statuses.first
  51. expect(status).to_not be_nil
  52. expect(status.visibility).to eq 'public'
  53. end
  54. end
  55. context 'unlisted' do
  56. let(:object_json) do
  57. {
  58. id: 'bar',
  59. type: 'Note',
  60. content: 'Lorem ipsum',
  61. cc: 'https://www.w3.org/ns/activitystreams#Public',
  62. }
  63. end
  64. it 'creates status' do
  65. status = sender.statuses.first
  66. expect(status).to_not be_nil
  67. expect(status.visibility).to eq 'unlisted'
  68. end
  69. end
  70. context 'private' do
  71. let(:object_json) do
  72. {
  73. id: 'bar',
  74. type: 'Note',
  75. content: 'Lorem ipsum',
  76. to: 'http://example.com/followers',
  77. }
  78. end
  79. it 'creates status' do
  80. status = sender.statuses.first
  81. expect(status).to_not be_nil
  82. expect(status.visibility).to eq 'private'
  83. end
  84. end
  85. context 'direct' do
  86. let(:recipient) { Fabricate(:account) }
  87. let(:object_json) do
  88. {
  89. id: 'bar',
  90. type: 'Note',
  91. content: 'Lorem ipsum',
  92. to: ActivityPub::TagManager.instance.uri_for(recipient),
  93. }
  94. end
  95. it 'creates status' do
  96. status = sender.statuses.first
  97. expect(status).to_not be_nil
  98. expect(status.visibility).to eq 'direct'
  99. end
  100. end
  101. context 'as a reply' do
  102. let(:original_status) { Fabricate(:status) }
  103. let(:object_json) do
  104. {
  105. id: 'bar',
  106. type: 'Note',
  107. content: 'Lorem ipsum',
  108. inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
  109. }
  110. end
  111. it 'creates status' do
  112. status = sender.statuses.first
  113. expect(status).to_not be_nil
  114. expect(status.thread).to eq original_status
  115. expect(status.reply?).to be true
  116. expect(status.in_reply_to_account).to eq original_status.account
  117. expect(status.conversation).to eq original_status.conversation
  118. end
  119. end
  120. context 'with mentions' do
  121. let(:recipient) { Fabricate(:account) }
  122. let(:object_json) do
  123. {
  124. id: 'bar',
  125. type: 'Note',
  126. content: 'Lorem ipsum',
  127. tag: [
  128. {
  129. type: 'Mention',
  130. href: ActivityPub::TagManager.instance.uri_for(recipient),
  131. },
  132. ],
  133. }
  134. end
  135. it 'creates status' do
  136. status = sender.statuses.first
  137. expect(status).to_not be_nil
  138. expect(status.mentions.map(&:account)).to include(recipient)
  139. end
  140. end
  141. context 'with media attachments' do
  142. let(:object_json) do
  143. {
  144. id: 'bar',
  145. type: 'Note',
  146. content: 'Lorem ipsum',
  147. attachment: [
  148. {
  149. type: 'Document',
  150. mime_type: 'image/png',
  151. url: 'http://example.com/attachment.png',
  152. },
  153. ],
  154. }
  155. end
  156. it 'creates status' do
  157. status = sender.statuses.first
  158. expect(status).to_not be_nil
  159. expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
  160. end
  161. end
  162. context 'with hashtags' do
  163. let(:object_json) do
  164. {
  165. id: 'bar',
  166. type: 'Note',
  167. content: 'Lorem ipsum',
  168. tag: [
  169. {
  170. type: 'Hashtag',
  171. href: 'http://example.com/blah',
  172. name: '#test',
  173. },
  174. ],
  175. }
  176. end
  177. it 'creates status' do
  178. status = sender.statuses.first
  179. expect(status).to_not be_nil
  180. expect(status.tags.map(&:name)).to include('test')
  181. end
  182. end
  183. end
  184. end