The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

355 lines
7.9 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 mentions missing href' do
  143. let(:object_json) do
  144. {
  145. id: 'bar',
  146. type: 'Note',
  147. content: 'Lorem ipsum',
  148. tag: [
  149. {
  150. type: 'Mention',
  151. },
  152. ],
  153. }
  154. end
  155. it 'creates status' do
  156. status = sender.statuses.first
  157. expect(status).to_not be_nil
  158. end
  159. end
  160. context 'with media attachments' do
  161. let(:object_json) do
  162. {
  163. id: 'bar',
  164. type: 'Note',
  165. content: 'Lorem ipsum',
  166. attachment: [
  167. {
  168. type: 'Document',
  169. mime_type: 'image/png',
  170. url: 'http://example.com/attachment.png',
  171. },
  172. ],
  173. }
  174. end
  175. it 'creates status' do
  176. status = sender.statuses.first
  177. expect(status).to_not be_nil
  178. expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
  179. end
  180. end
  181. context 'with media attachments missing url' do
  182. let(:object_json) do
  183. {
  184. id: 'bar',
  185. type: 'Note',
  186. content: 'Lorem ipsum',
  187. attachment: [
  188. {
  189. type: 'Document',
  190. mime_type: 'image/png',
  191. },
  192. ],
  193. }
  194. end
  195. it 'creates status' do
  196. status = sender.statuses.first
  197. expect(status).to_not be_nil
  198. end
  199. end
  200. context 'with hashtags' do
  201. let(:object_json) do
  202. {
  203. id: 'bar',
  204. type: 'Note',
  205. content: 'Lorem ipsum',
  206. tag: [
  207. {
  208. type: 'Hashtag',
  209. href: 'http://example.com/blah',
  210. name: '#test',
  211. },
  212. ],
  213. }
  214. end
  215. it 'creates status' do
  216. status = sender.statuses.first
  217. expect(status).to_not be_nil
  218. expect(status.tags.map(&:name)).to include('test')
  219. end
  220. end
  221. context 'with hashtags missing name' do
  222. let(:object_json) do
  223. {
  224. id: 'bar',
  225. type: 'Note',
  226. content: 'Lorem ipsum',
  227. tag: [
  228. {
  229. type: 'Hashtag',
  230. href: 'http://example.com/blah',
  231. },
  232. ],
  233. }
  234. end
  235. it 'creates status' do
  236. status = sender.statuses.first
  237. expect(status).to_not be_nil
  238. end
  239. end
  240. context 'with emojis' do
  241. let(:object_json) do
  242. {
  243. id: 'bar',
  244. type: 'Note',
  245. content: 'Lorem ipsum :tinking:',
  246. tag: [
  247. {
  248. type: 'Emoji',
  249. icon: {
  250. url: 'http://example.com/emoji.png',
  251. },
  252. name: 'tinking',
  253. },
  254. ],
  255. }
  256. end
  257. it 'creates status' do
  258. status = sender.statuses.first
  259. expect(status).to_not be_nil
  260. expect(status.emojis.map(&:shortcode)).to include('tinking')
  261. end
  262. end
  263. context 'with emojis missing name' do
  264. let(:object_json) do
  265. {
  266. id: 'bar',
  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. },
  276. ],
  277. }
  278. end
  279. it 'creates status' do
  280. status = sender.statuses.first
  281. expect(status).to_not be_nil
  282. end
  283. end
  284. context 'with emojis missing icon' do
  285. let(:object_json) do
  286. {
  287. id: 'bar',
  288. type: 'Note',
  289. content: 'Lorem ipsum :tinking:',
  290. tag: [
  291. {
  292. type: 'Emoji',
  293. name: 'tinking',
  294. },
  295. ],
  296. }
  297. end
  298. it 'creates status' do
  299. status = sender.statuses.first
  300. expect(status).to_not be_nil
  301. end
  302. end
  303. end
  304. end