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.

381 lines
9.5 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. mediaType: '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 with focal points' 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. mediaType: 'image/png',
  192. url: 'http://example.com/attachment.png',
  193. focalPoint: [0.5, -0.7],
  194. },
  195. ],
  196. }
  197. end
  198. it 'creates status' do
  199. status = sender.statuses.first
  200. expect(status).to_not be_nil
  201. expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
  202. end
  203. end
  204. context 'with media attachments missing url' do
  205. let(:object_json) do
  206. {
  207. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  208. type: 'Note',
  209. content: 'Lorem ipsum',
  210. attachment: [
  211. {
  212. type: 'Document',
  213. mediaType: 'image/png',
  214. },
  215. ],
  216. }
  217. end
  218. it 'creates status' do
  219. status = sender.statuses.first
  220. expect(status).to_not be_nil
  221. end
  222. end
  223. context 'with hashtags' do
  224. let(:object_json) do
  225. {
  226. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  227. type: 'Note',
  228. content: 'Lorem ipsum',
  229. tag: [
  230. {
  231. type: 'Hashtag',
  232. href: 'http://example.com/blah',
  233. name: '#test',
  234. },
  235. ],
  236. }
  237. end
  238. it 'creates status' do
  239. status = sender.statuses.first
  240. expect(status).to_not be_nil
  241. expect(status.tags.map(&:name)).to include('test')
  242. end
  243. end
  244. context 'with hashtags missing name' do
  245. let(:object_json) do
  246. {
  247. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  248. type: 'Note',
  249. content: 'Lorem ipsum',
  250. tag: [
  251. {
  252. type: 'Hashtag',
  253. href: 'http://example.com/blah',
  254. },
  255. ],
  256. }
  257. end
  258. it 'creates status' do
  259. status = sender.statuses.first
  260. expect(status).to_not be_nil
  261. end
  262. end
  263. context 'with emojis' do
  264. let(:object_json) do
  265. {
  266. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  267. type: 'Note',
  268. content: 'Lorem ipsum :tinking:',
  269. tag: [
  270. {
  271. type: 'Emoji',
  272. icon: {
  273. url: 'http://example.com/emoji.png',
  274. },
  275. name: 'tinking',
  276. },
  277. ],
  278. }
  279. end
  280. it 'creates status' do
  281. status = sender.statuses.first
  282. expect(status).to_not be_nil
  283. expect(status.emojis.map(&:shortcode)).to include('tinking')
  284. end
  285. end
  286. context 'with emojis missing name' do
  287. let(:object_json) do
  288. {
  289. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  290. type: 'Note',
  291. content: 'Lorem ipsum :tinking:',
  292. tag: [
  293. {
  294. type: 'Emoji',
  295. icon: {
  296. url: 'http://example.com/emoji.png',
  297. },
  298. },
  299. ],
  300. }
  301. end
  302. it 'creates status' do
  303. status = sender.statuses.first
  304. expect(status).to_not be_nil
  305. end
  306. end
  307. context 'with emojis missing icon' do
  308. let(:object_json) do
  309. {
  310. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  311. type: 'Note',
  312. content: 'Lorem ipsum :tinking:',
  313. tag: [
  314. {
  315. type: 'Emoji',
  316. name: 'tinking',
  317. },
  318. ],
  319. }
  320. end
  321. it 'creates status' do
  322. status = sender.statuses.first
  323. expect(status).to_not be_nil
  324. end
  325. end
  326. end
  327. end