create_spec.rb 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Create do
  3. let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor') }
  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. before do
  14. sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
  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. stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
  18. end
  19. describe '#perform' do
  20. context 'when fetching' do
  21. subject { described_class.new(json, sender) }
  22. before do
  23. subject.perform
  24. end
  25. context 'object has been edited' do
  26. let(:object_json) do
  27. {
  28. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  29. type: 'Note',
  30. content: 'Lorem ipsum',
  31. published: '2022-01-22T15:00:00Z',
  32. updated: '2022-01-22T16:00:00Z',
  33. }
  34. end
  35. it 'creates status' do
  36. status = sender.statuses.first
  37. expect(status).to_not be_nil
  38. expect(status.text).to eq 'Lorem ipsum'
  39. end
  40. it 'marks status as edited' do
  41. status = sender.statuses.first
  42. expect(status).to_not be_nil
  43. expect(status.edited?).to eq true
  44. end
  45. end
  46. context 'object has update date equal to creation date' do
  47. let(:object_json) do
  48. {
  49. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  50. type: 'Note',
  51. content: 'Lorem ipsum',
  52. published: '2022-01-22T15:00:00Z',
  53. updated: '2022-01-22T15:00:00Z',
  54. }
  55. end
  56. it 'creates status' do
  57. status = sender.statuses.first
  58. expect(status).to_not be_nil
  59. expect(status.text).to eq 'Lorem ipsum'
  60. end
  61. it 'does not mark status as edited' do
  62. status = sender.statuses.first
  63. expect(status).to_not be_nil
  64. expect(status.edited?).to eq false
  65. end
  66. end
  67. context 'unknown object type' do
  68. let(:object_json) do
  69. {
  70. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  71. type: 'Banana',
  72. content: 'Lorem ipsum',
  73. }
  74. end
  75. it 'does not create a status' do
  76. expect(sender.statuses.count).to be_zero
  77. end
  78. end
  79. context 'standalone' do
  80. let(:object_json) do
  81. {
  82. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  83. type: 'Note',
  84. content: 'Lorem ipsum',
  85. }
  86. end
  87. it 'creates status' do
  88. status = sender.statuses.first
  89. expect(status).to_not be_nil
  90. expect(status.text).to eq 'Lorem ipsum'
  91. end
  92. it 'missing to/cc defaults to direct privacy' do
  93. status = sender.statuses.first
  94. expect(status).to_not be_nil
  95. expect(status.visibility).to eq 'direct'
  96. end
  97. end
  98. context 'public with explicit public address' do
  99. let(:object_json) do
  100. {
  101. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  102. type: 'Note',
  103. content: 'Lorem ipsum',
  104. to: 'https://www.w3.org/ns/activitystreams#Public',
  105. }
  106. end
  107. it 'creates status' do
  108. status = sender.statuses.first
  109. expect(status).to_not be_nil
  110. expect(status.visibility).to eq 'public'
  111. end
  112. end
  113. context 'public with as:Public' do
  114. let(:object_json) do
  115. {
  116. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  117. type: 'Note',
  118. content: 'Lorem ipsum',
  119. to: 'as:Public',
  120. }
  121. end
  122. it 'creates status' do
  123. status = sender.statuses.first
  124. expect(status).to_not be_nil
  125. expect(status.visibility).to eq 'public'
  126. end
  127. end
  128. context 'public with Public' do
  129. let(:object_json) do
  130. {
  131. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  132. type: 'Note',
  133. content: 'Lorem ipsum',
  134. to: 'Public',
  135. }
  136. end
  137. it 'creates status' do
  138. status = sender.statuses.first
  139. expect(status).to_not be_nil
  140. expect(status.visibility).to eq 'public'
  141. end
  142. end
  143. context 'unlisted with explicit public address' 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. cc: 'https://www.w3.org/ns/activitystreams#Public',
  150. }
  151. end
  152. it 'creates status' do
  153. status = sender.statuses.first
  154. expect(status).to_not be_nil
  155. expect(status.visibility).to eq 'unlisted'
  156. end
  157. end
  158. context 'unlisted with as:Public' do
  159. let(:object_json) do
  160. {
  161. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  162. type: 'Note',
  163. content: 'Lorem ipsum',
  164. cc: 'as:Public',
  165. }
  166. end
  167. it 'creates status' do
  168. status = sender.statuses.first
  169. expect(status).to_not be_nil
  170. expect(status.visibility).to eq 'unlisted'
  171. end
  172. end
  173. context 'unlisted with Public' do
  174. let(:object_json) do
  175. {
  176. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  177. type: 'Note',
  178. content: 'Lorem ipsum',
  179. cc: 'Public',
  180. }
  181. end
  182. it 'creates status' do
  183. status = sender.statuses.first
  184. expect(status).to_not be_nil
  185. expect(status.visibility).to eq 'unlisted'
  186. end
  187. end
  188. context 'private' do
  189. let(:object_json) do
  190. {
  191. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  192. type: 'Note',
  193. content: 'Lorem ipsum',
  194. to: 'http://example.com/followers',
  195. }
  196. end
  197. it 'creates status' do
  198. status = sender.statuses.first
  199. expect(status).to_not be_nil
  200. expect(status.visibility).to eq 'private'
  201. end
  202. end
  203. context 'private with inlined Collection in audience' do
  204. let(:object_json) do
  205. {
  206. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  207. type: 'Note',
  208. content: 'Lorem ipsum',
  209. to: {
  210. 'type': 'OrderedCollection',
  211. 'id': 'http://example.com/followers',
  212. 'first': 'http://example.com/followers?page=true',
  213. }
  214. }
  215. end
  216. it 'creates status' do
  217. status = sender.statuses.first
  218. expect(status).to_not be_nil
  219. expect(status.visibility).to eq 'private'
  220. end
  221. end
  222. context 'limited' do
  223. let(:recipient) { Fabricate(:account) }
  224. let(:object_json) do
  225. {
  226. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  227. type: 'Note',
  228. content: 'Lorem ipsum',
  229. to: ActivityPub::TagManager.instance.uri_for(recipient),
  230. }
  231. end
  232. it 'creates status' do
  233. status = sender.statuses.first
  234. expect(status).to_not be_nil
  235. expect(status.visibility).to eq 'limited'
  236. end
  237. it 'creates silent mention' do
  238. status = sender.statuses.first
  239. expect(status.mentions.first).to be_silent
  240. end
  241. end
  242. context 'direct' do
  243. let(:recipient) { Fabricate(:account) }
  244. let(:object_json) do
  245. {
  246. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  247. type: 'Note',
  248. content: 'Lorem ipsum',
  249. to: ActivityPub::TagManager.instance.uri_for(recipient),
  250. tag: {
  251. type: 'Mention',
  252. href: ActivityPub::TagManager.instance.uri_for(recipient),
  253. },
  254. }
  255. end
  256. it 'creates status' do
  257. status = sender.statuses.first
  258. expect(status).to_not be_nil
  259. expect(status.visibility).to eq 'direct'
  260. end
  261. end
  262. context 'as a reply' do
  263. let(:original_status) { Fabricate(:status) }
  264. let(:object_json) do
  265. {
  266. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  267. type: 'Note',
  268. content: 'Lorem ipsum',
  269. inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
  270. }
  271. end
  272. it 'creates status' do
  273. status = sender.statuses.first
  274. expect(status).to_not be_nil
  275. expect(status.thread).to eq original_status
  276. expect(status.reply?).to be true
  277. expect(status.in_reply_to_account).to eq original_status.account
  278. expect(status.conversation).to eq original_status.conversation
  279. end
  280. end
  281. context 'with mentions' do
  282. let(:recipient) { Fabricate(:account) }
  283. let(:object_json) do
  284. {
  285. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  286. type: 'Note',
  287. content: 'Lorem ipsum',
  288. tag: [
  289. {
  290. type: 'Mention',
  291. href: ActivityPub::TagManager.instance.uri_for(recipient),
  292. },
  293. ],
  294. }
  295. end
  296. it 'creates status' do
  297. status = sender.statuses.first
  298. expect(status).to_not be_nil
  299. expect(status.mentions.map(&:account)).to include(recipient)
  300. end
  301. end
  302. context 'with mentions missing href' do
  303. let(:object_json) do
  304. {
  305. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  306. type: 'Note',
  307. content: 'Lorem ipsum',
  308. tag: [
  309. {
  310. type: 'Mention',
  311. },
  312. ],
  313. }
  314. end
  315. it 'creates status' do
  316. status = sender.statuses.first
  317. expect(status).to_not be_nil
  318. end
  319. end
  320. context 'with media attachments' do
  321. let(:object_json) do
  322. {
  323. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  324. type: 'Note',
  325. content: 'Lorem ipsum',
  326. attachment: [
  327. {
  328. type: 'Document',
  329. mediaType: 'image/png',
  330. url: 'http://example.com/attachment.png',
  331. },
  332. ],
  333. }
  334. end
  335. it 'creates status' do
  336. status = sender.statuses.first
  337. expect(status).to_not be_nil
  338. expect(status.media_attachments.map(&:remote_url)).to include('http://example.com/attachment.png')
  339. end
  340. end
  341. context 'with media attachments with long description' do
  342. let(:object_json) do
  343. {
  344. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  345. type: 'Note',
  346. content: 'Lorem ipsum',
  347. attachment: [
  348. {
  349. type: 'Document',
  350. mediaType: 'image/png',
  351. url: 'http://example.com/attachment.png',
  352. name: '*' * 1500,
  353. },
  354. ],
  355. }
  356. end
  357. it 'creates status' do
  358. status = sender.statuses.first
  359. expect(status).to_not be_nil
  360. expect(status.media_attachments.map(&:description)).to include('*' * 1500)
  361. end
  362. end
  363. context 'with media attachments with long description as summary' do
  364. let(:object_json) do
  365. {
  366. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  367. type: 'Note',
  368. content: 'Lorem ipsum',
  369. attachment: [
  370. {
  371. type: 'Document',
  372. mediaType: 'image/png',
  373. url: 'http://example.com/attachment.png',
  374. summary: '*' * 1500,
  375. },
  376. ],
  377. }
  378. end
  379. it 'creates status' do
  380. status = sender.statuses.first
  381. expect(status).to_not be_nil
  382. expect(status.media_attachments.map(&:description)).to include('*' * 1500)
  383. end
  384. end
  385. context 'with media attachments with focal points' do
  386. let(:object_json) do
  387. {
  388. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  389. type: 'Note',
  390. content: 'Lorem ipsum',
  391. attachment: [
  392. {
  393. type: 'Document',
  394. mediaType: 'image/png',
  395. url: 'http://example.com/attachment.png',
  396. focalPoint: [0.5, -0.7],
  397. },
  398. ],
  399. }
  400. end
  401. it 'creates status' do
  402. status = sender.statuses.first
  403. expect(status).to_not be_nil
  404. expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
  405. end
  406. end
  407. context 'with media attachments missing url' do
  408. let(:object_json) do
  409. {
  410. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  411. type: 'Note',
  412. content: 'Lorem ipsum',
  413. attachment: [
  414. {
  415. type: 'Document',
  416. mediaType: 'image/png',
  417. },
  418. ],
  419. }
  420. end
  421. it 'creates status' do
  422. status = sender.statuses.first
  423. expect(status).to_not be_nil
  424. end
  425. end
  426. context 'with hashtags' do
  427. let(:object_json) do
  428. {
  429. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  430. type: 'Note',
  431. content: 'Lorem ipsum',
  432. tag: [
  433. {
  434. type: 'Hashtag',
  435. href: 'http://example.com/blah',
  436. name: '#test',
  437. },
  438. ],
  439. }
  440. end
  441. it 'creates status' do
  442. status = sender.statuses.first
  443. expect(status).to_not be_nil
  444. expect(status.tags.map(&:name)).to include('test')
  445. end
  446. end
  447. context 'with hashtags missing name' do
  448. let(:object_json) do
  449. {
  450. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  451. type: 'Note',
  452. content: 'Lorem ipsum',
  453. tag: [
  454. {
  455. type: 'Hashtag',
  456. href: 'http://example.com/blah',
  457. },
  458. ],
  459. }
  460. end
  461. it 'creates status' do
  462. status = sender.statuses.first
  463. expect(status).to_not be_nil
  464. end
  465. end
  466. context 'with hashtags invalid name' do
  467. let(:object_json) do
  468. {
  469. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  470. type: 'Note',
  471. content: 'Lorem ipsum',
  472. tag: [
  473. {
  474. type: 'Hashtag',
  475. href: 'http://example.com/blah',
  476. name: 'foo, #eh !',
  477. },
  478. ],
  479. }
  480. end
  481. it 'creates status' do
  482. status = sender.statuses.first
  483. expect(status).to_not be_nil
  484. end
  485. end
  486. context 'with emojis' do
  487. let(:object_json) do
  488. {
  489. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  490. type: 'Note',
  491. content: 'Lorem ipsum :tinking:',
  492. tag: [
  493. {
  494. type: 'Emoji',
  495. icon: {
  496. url: 'http://example.com/emoji.png',
  497. },
  498. name: 'tinking',
  499. },
  500. ],
  501. }
  502. end
  503. it 'creates status' do
  504. status = sender.statuses.first
  505. expect(status).to_not be_nil
  506. expect(status.emojis.map(&:shortcode)).to include('tinking')
  507. end
  508. end
  509. context 'with emojis served with invalid content-type' do
  510. let(:object_json) do
  511. {
  512. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  513. type: 'Note',
  514. content: 'Lorem ipsum :tinkong:',
  515. tag: [
  516. {
  517. type: 'Emoji',
  518. icon: {
  519. url: 'http://example.com/emojib.png',
  520. },
  521. name: 'tinkong',
  522. },
  523. ],
  524. }
  525. end
  526. it 'creates status' do
  527. status = sender.statuses.first
  528. expect(status).to_not be_nil
  529. expect(status.emojis.map(&:shortcode)).to include('tinkong')
  530. end
  531. end
  532. context 'with emojis missing name' do
  533. let(:object_json) do
  534. {
  535. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  536. type: 'Note',
  537. content: 'Lorem ipsum :tinking:',
  538. tag: [
  539. {
  540. type: 'Emoji',
  541. icon: {
  542. url: 'http://example.com/emoji.png',
  543. },
  544. },
  545. ],
  546. }
  547. end
  548. it 'creates status' do
  549. status = sender.statuses.first
  550. expect(status).to_not be_nil
  551. end
  552. end
  553. context 'with emojis missing icon' do
  554. let(:object_json) do
  555. {
  556. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  557. type: 'Note',
  558. content: 'Lorem ipsum :tinking:',
  559. tag: [
  560. {
  561. type: 'Emoji',
  562. name: 'tinking',
  563. },
  564. ],
  565. }
  566. end
  567. it 'creates status' do
  568. status = sender.statuses.first
  569. expect(status).to_not be_nil
  570. end
  571. end
  572. context 'with poll' do
  573. let(:object_json) do
  574. {
  575. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  576. type: 'Question',
  577. content: 'Which color was the submarine?',
  578. oneOf: [
  579. {
  580. name: 'Yellow',
  581. replies: {
  582. type: 'Collection',
  583. totalItems: 10,
  584. },
  585. },
  586. {
  587. name: 'Blue',
  588. replies: {
  589. type: 'Collection',
  590. totalItems: 3,
  591. }
  592. },
  593. ],
  594. }
  595. end
  596. it 'creates status' do
  597. status = sender.statuses.first
  598. expect(status).to_not be_nil
  599. expect(status.poll).to_not be_nil
  600. end
  601. it 'creates a poll' do
  602. poll = sender.polls.first
  603. expect(poll).to_not be_nil
  604. expect(poll.status).to_not be_nil
  605. expect(poll.options).to eq %w(Yellow Blue)
  606. expect(poll.cached_tallies).to eq [10, 3]
  607. end
  608. end
  609. context 'when a vote to a local poll' do
  610. let(:poll) { Fabricate(:poll, options: %w(Yellow Blue)) }
  611. let!(:local_status) { Fabricate(:status, poll: poll) }
  612. let(:object_json) do
  613. {
  614. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  615. type: 'Note',
  616. name: 'Yellow',
  617. inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status)
  618. }
  619. end
  620. it 'adds a vote to the poll with correct uri' do
  621. vote = poll.votes.first
  622. expect(vote).to_not be_nil
  623. expect(vote.uri).to eq object_json[:id]
  624. expect(poll.reload.cached_tallies).to eq [1, 0]
  625. end
  626. end
  627. context 'when a vote to an expired local poll' do
  628. let(:poll) do
  629. poll = Fabricate.build(:poll, options: %w(Yellow Blue), expires_at: 1.day.ago)
  630. poll.save(validate: false)
  631. poll
  632. end
  633. let!(:local_status) { Fabricate(:status, poll: poll) }
  634. let(:object_json) do
  635. {
  636. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  637. type: 'Note',
  638. name: 'Yellow',
  639. inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status)
  640. }
  641. end
  642. it 'does not add a vote to the poll' do
  643. expect(poll.votes.first).to be_nil
  644. end
  645. end
  646. end
  647. context 'with an encrypted message' do
  648. let(:recipient) { Fabricate(:account) }
  649. let(:target_device) { Fabricate(:device, account: recipient) }
  650. subject { described_class.new(json, sender, delivery: true, delivered_to_account_id: recipient.id) }
  651. let(:object_json) do
  652. {
  653. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  654. type: 'EncryptedMessage',
  655. attributedTo: {
  656. type: 'Device',
  657. deviceId: '1234',
  658. },
  659. to: {
  660. type: 'Device',
  661. deviceId: target_device.device_id,
  662. },
  663. messageType: 1,
  664. cipherText: 'Foo',
  665. messageFranking: 'Baz678',
  666. digest: {
  667. digestAlgorithm: 'Bar456',
  668. digestValue: 'Foo123',
  669. },
  670. }
  671. end
  672. before do
  673. subject.perform
  674. end
  675. it 'creates an encrypted message' do
  676. encrypted_message = target_device.encrypted_messages.reload.first
  677. expect(encrypted_message).to_not be_nil
  678. expect(encrypted_message.from_device_id).to eq '1234'
  679. expect(encrypted_message.from_account).to eq sender
  680. expect(encrypted_message.type).to eq 1
  681. expect(encrypted_message.body).to eq 'Foo'
  682. expect(encrypted_message.digest).to eq 'Foo123'
  683. end
  684. it 'creates a message franking' do
  685. encrypted_message = target_device.encrypted_messages.reload.first
  686. message_franking = encrypted_message.message_franking
  687. crypt = ActiveSupport::MessageEncryptor.new(SystemKey.current_key, serializer: Oj)
  688. json = crypt.decrypt_and_verify(message_franking)
  689. expect(json['source_account_id']).to eq sender.id
  690. expect(json['target_account_id']).to eq recipient.id
  691. expect(json['original_franking']).to eq 'Baz678'
  692. end
  693. end
  694. context 'when sender is followed by local users' do
  695. subject { described_class.new(json, sender, delivery: true) }
  696. before do
  697. Fabricate(:account).follow!(sender)
  698. subject.perform
  699. end
  700. let(:object_json) do
  701. {
  702. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  703. type: 'Note',
  704. content: 'Lorem ipsum',
  705. }
  706. end
  707. it 'creates status' do
  708. status = sender.statuses.first
  709. expect(status).to_not be_nil
  710. expect(status.text).to eq 'Lorem ipsum'
  711. end
  712. end
  713. context 'when sender replies to local status' do
  714. let!(:local_status) { Fabricate(:status) }
  715. subject { described_class.new(json, sender, delivery: true) }
  716. before do
  717. subject.perform
  718. end
  719. let(:object_json) do
  720. {
  721. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  722. type: 'Note',
  723. content: 'Lorem ipsum',
  724. inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
  725. }
  726. end
  727. it 'creates status' do
  728. status = sender.statuses.first
  729. expect(status).to_not be_nil
  730. expect(status.text).to eq 'Lorem ipsum'
  731. end
  732. end
  733. context 'when sender targets a local user' do
  734. let!(:local_account) { Fabricate(:account) }
  735. subject { described_class.new(json, sender, delivery: true) }
  736. before do
  737. subject.perform
  738. end
  739. let(:object_json) do
  740. {
  741. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  742. type: 'Note',
  743. content: 'Lorem ipsum',
  744. to: ActivityPub::TagManager.instance.uri_for(local_account),
  745. }
  746. end
  747. it 'creates status' do
  748. status = sender.statuses.first
  749. expect(status).to_not be_nil
  750. expect(status.text).to eq 'Lorem ipsum'
  751. end
  752. end
  753. context 'when sender cc\'s a local user' do
  754. let!(:local_account) { Fabricate(:account) }
  755. subject { described_class.new(json, sender, delivery: true) }
  756. before do
  757. subject.perform
  758. end
  759. let(:object_json) do
  760. {
  761. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  762. type: 'Note',
  763. content: 'Lorem ipsum',
  764. cc: ActivityPub::TagManager.instance.uri_for(local_account),
  765. }
  766. end
  767. it 'creates status' do
  768. status = sender.statuses.first
  769. expect(status).to_not be_nil
  770. expect(status.text).to eq 'Lorem ipsum'
  771. end
  772. end
  773. context 'when the sender has no relevance to local activity' do
  774. subject { described_class.new(json, sender, delivery: true) }
  775. before do
  776. subject.perform
  777. end
  778. let(:object_json) do
  779. {
  780. id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
  781. type: 'Note',
  782. content: 'Lorem ipsum',
  783. }
  784. end
  785. it 'does not create anything' do
  786. expect(sender.statuses.count).to eq 0
  787. end
  788. end
  789. end
  790. end