闭社主体 forked from https://github.com/tootsuite/mastodon
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.

246 lines
5.7 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. stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
  17. end
  18. describe '#perform' do
  19. before do
  20. subject.perform
  21. end
  22. context 'standalone' do
  23. let(:object_json) do
  24. {
  25. id: 'bar',
  26. type: 'Note',
  27. content: 'Lorem ipsum',
  28. }
  29. end
  30. it 'creates status' do
  31. status = sender.statuses.first
  32. expect(status).to_not be_nil
  33. expect(status.text).to eq 'Lorem ipsum'
  34. end
  35. it 'missing to/cc defaults to direct privacy' do
  36. status = sender.statuses.first
  37. expect(status).to_not be_nil
  38. expect(status.visibility).to eq 'direct'
  39. end
  40. end
  41. context 'public' do
  42. let(:object_json) do
  43. {
  44. id: 'bar',
  45. type: 'Note',
  46. content: 'Lorem ipsum',
  47. to: 'https://www.w3.org/ns/activitystreams#Public',
  48. }
  49. end
  50. it 'creates status' do
  51. status = sender.statuses.first
  52. expect(status).to_not be_nil
  53. expect(status.visibility).to eq 'public'
  54. end
  55. end
  56. context 'unlisted' do
  57. let(:object_json) do
  58. {
  59. id: 'bar',
  60. type: 'Note',
  61. content: 'Lorem ipsum',
  62. cc: 'https://www.w3.org/ns/activitystreams#Public',
  63. }
  64. end
  65. it 'creates status' do
  66. status = sender.statuses.first
  67. expect(status).to_not be_nil
  68. expect(status.visibility).to eq 'unlisted'
  69. end
  70. end
  71. context 'private' do
  72. let(:object_json) do
  73. {
  74. id: 'bar',
  75. type: 'Note',
  76. content: 'Lorem ipsum',
  77. to: 'http://example.com/followers',
  78. }
  79. end
  80. it 'creates status' do
  81. status = sender.statuses.first
  82. expect(status).to_not be_nil
  83. expect(status.visibility).to eq 'private'
  84. end
  85. end
  86. context 'direct' do
  87. let(:recipient) { Fabricate(:account) }
  88. let(:object_json) do
  89. {
  90. id: 'bar',
  91. type: 'Note',
  92. content: 'Lorem ipsum',
  93. to: ActivityPub::TagManager.instance.uri_for(recipient),
  94. }
  95. end
  96. it 'creates status' do
  97. status = sender.statuses.first
  98. expect(status).to_not be_nil
  99. expect(status.visibility).to eq 'direct'
  100. end
  101. end
  102. context 'as a reply' do
  103. let(:original_status) { Fabricate(:status) }
  104. let(:object_json) do
  105. {
  106. id: 'bar',
  107. type: 'Note',
  108. content: 'Lorem ipsum',
  109. inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
  110. }
  111. end
  112. it 'creates status' do
  113. status = sender.statuses.first
  114. expect(status).to_not be_nil
  115. expect(status.thread).to eq original_status
  116. expect(status.reply?).to be true
  117. expect(status.in_reply_to_account).to eq original_status.account
  118. expect(status.conversation).to eq original_status.conversation
  119. end
  120. end
  121. context 'with mentions' do
  122. let(:recipient) { Fabricate(:account) }
  123. let(:object_json) do
  124. {
  125. id: 'bar',
  126. type: 'Note',
  127. content: 'Lorem ipsum',
  128. tag: [
  129. {
  130. type: 'Mention',
  131. href: ActivityPub::TagManager.instance.uri_for(recipient),
  132. },
  133. ],
  134. }
  135. end
  136. it 'creates status' do
  137. status = sender.statuses.first
  138. expect(status).to_not be_nil
  139. expect(status.mentions.map(&:account)).to include(recipient)
  140. end
  141. end
  142. context 'with media attachments' do
  143. let(:object_json) do
  144. {
  145. id: 'bar',
  146. type: 'Note',
  147. content: 'Lorem ipsum',
  148. attachment: [
  149. {
  150. type: 'Document',
  151. mime_type: 'image/png',
  152. url: 'http://example.com/attachment.png',
  153. },
  154. ],
  155. }
  156. end
  157. it 'creates status' do
  158. status = sender.statuses.first
  159. expect(status).to_not be_nil
  160. expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
  161. end
  162. end
  163. context 'with hashtags' do
  164. let(:object_json) do
  165. {
  166. id: 'bar',
  167. type: 'Note',
  168. content: 'Lorem ipsum',
  169. tag: [
  170. {
  171. type: 'Hashtag',
  172. href: 'http://example.com/blah',
  173. name: '#test',
  174. },
  175. ],
  176. }
  177. end
  178. it 'creates status' do
  179. status = sender.statuses.first
  180. expect(status).to_not be_nil
  181. expect(status.tags.map(&:name)).to include('test')
  182. end
  183. end
  184. context 'with emojis' do
  185. let(:object_json) do
  186. {
  187. id: 'bar',
  188. type: 'Note',
  189. content: 'Lorem ipsum :tinking:',
  190. tag: [
  191. {
  192. type: 'Emoji',
  193. href: 'http://example.com/emoji.png',
  194. name: 'tinking',
  195. },
  196. ],
  197. }
  198. end
  199. it 'creates status' do
  200. status = sender.statuses.first
  201. expect(status).to_not be_nil
  202. expect(status.emojis.map(&:shortcode)).to include('tinking')
  203. end
  204. end
  205. end
  206. end