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.

356 lines
8.8 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: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
  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. sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
  16. stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
  17. stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
  18. end
  19. describe '#perform' do
  20. before do
  21. subject.perform
  22. end
  23. context 'standalone' do
  24. let(:object_json) do
  25. {
  26. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  27. type: 'Note',
  28. content: 'Lorem ipsum',
  29. }
  30. end
  31. it 'creates status' do
  32. status = sender.statuses.first
  33. expect(status).to_not be_nil
  34. expect(status.text).to eq 'Lorem ipsum'
  35. end
  36. it 'missing to/cc defaults to direct privacy' do
  37. status = sender.statuses.first
  38. expect(status).to_not be_nil
  39. expect(status.visibility).to eq 'direct'
  40. end
  41. end
  42. context 'public' do
  43. let(:object_json) do
  44. {
  45. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  46. type: 'Note',
  47. content: 'Lorem ipsum',
  48. to: 'https://www.w3.org/ns/activitystreams#Public',
  49. }
  50. end
  51. it 'creates status' do
  52. status = sender.statuses.first
  53. expect(status).to_not be_nil
  54. expect(status.visibility).to eq 'public'
  55. end
  56. end
  57. context 'unlisted' do
  58. let(:object_json) do
  59. {
  60. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  61. type: 'Note',
  62. content: 'Lorem ipsum',
  63. cc: 'https://www.w3.org/ns/activitystreams#Public',
  64. }
  65. end
  66. it 'creates status' do
  67. status = sender.statuses.first
  68. expect(status).to_not be_nil
  69. expect(status.visibility).to eq 'unlisted'
  70. end
  71. end
  72. context 'private' do
  73. let(:object_json) do
  74. {
  75. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  76. type: 'Note',
  77. content: 'Lorem ipsum',
  78. to: 'http://example.com/followers',
  79. }
  80. end
  81. it 'creates status' do
  82. status = sender.statuses.first
  83. expect(status).to_not be_nil
  84. expect(status.visibility).to eq 'private'
  85. end
  86. end
  87. context 'direct' do
  88. let(:recipient) { Fabricate(:account) }
  89. let(:object_json) do
  90. {
  91. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  92. type: 'Note',
  93. content: 'Lorem ipsum',
  94. to: ActivityPub::TagManager.instance.uri_for(recipient),
  95. }
  96. end
  97. it 'creates status' do
  98. status = sender.statuses.first
  99. expect(status).to_not be_nil
  100. expect(status.visibility).to eq 'direct'
  101. end
  102. end
  103. context 'as a reply' do
  104. let(:original_status) { Fabricate(:status) }
  105. let(:object_json) do
  106. {
  107. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  108. type: 'Note',
  109. content: 'Lorem ipsum',
  110. inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
  111. }
  112. end
  113. it 'creates status' do
  114. status = sender.statuses.first
  115. expect(status).to_not be_nil
  116. expect(status.thread).to eq original_status
  117. expect(status.reply?).to be true
  118. expect(status.in_reply_to_account).to eq original_status.account
  119. expect(status.conversation).to eq original_status.conversation
  120. end
  121. end
  122. context 'with mentions' do
  123. let(:recipient) { Fabricate(:account) }
  124. let(:object_json) do
  125. {
  126. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  127. type: 'Note',
  128. content: 'Lorem ipsum',
  129. tag: [
  130. {
  131. type: 'Mention',
  132. href: ActivityPub::TagManager.instance.uri_for(recipient),
  133. },
  134. ],
  135. }
  136. end
  137. it 'creates status' do
  138. status = sender.statuses.first
  139. expect(status).to_not be_nil
  140. expect(status.mentions.map(&:account)).to include(recipient)
  141. end
  142. end
  143. context 'with mentions missing href' do
  144. let(:object_json) do
  145. {
  146. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  147. type: 'Note',
  148. content: 'Lorem ipsum',
  149. tag: [
  150. {
  151. type: 'Mention',
  152. },
  153. ],
  154. }
  155. end
  156. it 'creates status' do
  157. status = sender.statuses.first
  158. expect(status).to_not be_nil
  159. end
  160. end
  161. context 'with media attachments' do
  162. let(:object_json) do
  163. {
  164. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  165. type: 'Note',
  166. content: 'Lorem ipsum',
  167. attachment: [
  168. {
  169. type: 'Document',
  170. mime_type: 'image/png',
  171. url: 'http://example.com/attachment.png',
  172. },
  173. ],
  174. }
  175. end
  176. it 'creates status' do
  177. status = sender.statuses.first
  178. expect(status).to_not be_nil
  179. expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
  180. end
  181. end
  182. context 'with media attachments missing url' do
  183. let(:object_json) do
  184. {
  185. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  186. type: 'Note',
  187. content: 'Lorem ipsum',
  188. attachment: [
  189. {
  190. type: 'Document',
  191. mime_type: 'image/png',
  192. },
  193. ],
  194. }
  195. end
  196. it 'creates status' do
  197. status = sender.statuses.first
  198. expect(status).to_not be_nil
  199. end
  200. end
  201. context 'with hashtags' do
  202. let(:object_json) do
  203. {
  204. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  205. type: 'Note',
  206. content: 'Lorem ipsum',
  207. tag: [
  208. {
  209. type: 'Hashtag',
  210. href: 'http://example.com/blah',
  211. name: '#test',
  212. },
  213. ],
  214. }
  215. end
  216. it 'creates status' do
  217. status = sender.statuses.first
  218. expect(status).to_not be_nil
  219. expect(status.tags.map(&:name)).to include('test')
  220. end
  221. end
  222. context 'with hashtags missing name' do
  223. let(:object_json) do
  224. {
  225. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  226. type: 'Note',
  227. content: 'Lorem ipsum',
  228. tag: [
  229. {
  230. type: 'Hashtag',
  231. href: 'http://example.com/blah',
  232. },
  233. ],
  234. }
  235. end
  236. it 'creates status' do
  237. status = sender.statuses.first
  238. expect(status).to_not be_nil
  239. end
  240. end
  241. context 'with emojis' do
  242. let(:object_json) do
  243. {
  244. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  245. type: 'Note',
  246. content: 'Lorem ipsum :tinking:',
  247. tag: [
  248. {
  249. type: 'Emoji',
  250. icon: {
  251. url: 'http://example.com/emoji.png',
  252. },
  253. name: 'tinking',
  254. },
  255. ],
  256. }
  257. end
  258. it 'creates status' do
  259. status = sender.statuses.first
  260. expect(status).to_not be_nil
  261. expect(status.emojis.map(&:shortcode)).to include('tinking')
  262. end
  263. end
  264. context 'with emojis missing name' do
  265. let(:object_json) do
  266. {
  267. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  268. type: 'Note',
  269. content: 'Lorem ipsum :tinking:',
  270. tag: [
  271. {
  272. type: 'Emoji',
  273. icon: {
  274. url: 'http://example.com/emoji.png',
  275. },
  276. },
  277. ],
  278. }
  279. end
  280. it 'creates status' do
  281. status = sender.statuses.first
  282. expect(status).to_not be_nil
  283. end
  284. end
  285. context 'with emojis missing icon' do
  286. let(:object_json) do
  287. {
  288. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  289. type: 'Note',
  290. content: 'Lorem ipsum :tinking:',
  291. tag: [
  292. {
  293. type: 'Emoji',
  294. name: 'tinking',
  295. },
  296. ],
  297. }
  298. end
  299. it 'creates status' do
  300. status = sender.statuses.first
  301. expect(status).to_not be_nil
  302. end
  303. end
  304. end
  305. end