12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121 |
- # frozen_string_literal: true
- require 'rails_helper'
- RSpec.describe ActivityPub::Activity::Create do
- let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor') }
- let(:json) do
- {
- '@context': 'https://www.w3.org/ns/activitystreams',
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
- type: 'Create',
- actor: ActivityPub::TagManager.instance.uri_for(sender),
- object: object_json,
- }.with_indifferent_access
- end
- before do
- sender.update(uri: ActivityPub::TagManager.instance.uri_for(sender))
- stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
- stub_request(:get, 'http://example.com/emoji.png').to_return(body: attachment_fixture('emojo.png'))
- stub_request(:get, 'http://example.com/emojib.png').to_return(body: attachment_fixture('emojo.png'), headers: { 'Content-Type' => 'application/octet-stream' })
- end
- describe 'processing posts received out of order' do
- let(:follower) { Fabricate(:account, username: 'bob') }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), 'post1'].join('/'),
- type: 'Note',
- to: [
- 'https://www.w3.org/ns/activitystreams#Public',
- ActivityPub::TagManager.instance.uri_for(follower),
- ],
- content: '@bob lorem ipsum',
- published: 1.hour.ago.utc.iso8601,
- updated: 1.hour.ago.utc.iso8601,
- tag: {
- type: 'Mention',
- href: ActivityPub::TagManager.instance.uri_for(follower),
- },
- }
- end
- let(:reply_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), 'reply'].join('/'),
- type: 'Note',
- inReplyTo: object_json[:id],
- to: [
- 'https://www.w3.org/ns/activitystreams#Public',
- ActivityPub::TagManager.instance.uri_for(follower),
- ],
- content: '@bob lorem ipsum',
- published: Time.now.utc.iso8601,
- updated: Time.now.utc.iso8601,
- tag: {
- type: 'Mention',
- href: ActivityPub::TagManager.instance.uri_for(follower),
- },
- }
- end
- let(:invalid_mention_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), 'post2'].join('/'),
- type: 'Note',
- to: [
- 'https://www.w3.org/ns/activitystreams#Public',
- ActivityPub::TagManager.instance.uri_for(follower),
- ],
- content: '@bob lorem ipsum',
- published: 1.hour.ago.utc.iso8601,
- updated: 1.hour.ago.utc.iso8601,
- tag: {
- type: 'Mention',
- href: 'http://notexisting.dontexistingtld/actor',
- },
- }
- end
- def activity_for_object(json)
- {
- '@context': 'https://www.w3.org/ns/activitystreams',
- id: [json[:id], 'activity'].join('/'),
- type: 'Create',
- actor: ActivityPub::TagManager.instance.uri_for(sender),
- object: json,
- }.with_indifferent_access
- end
- before do
- follower.follow!(sender)
- end
- it 'correctly processes posts and inserts them in timelines', :aggregate_failures do
- # Simulate a temporary failure preventing from fetching the parent post
- stub_request(:get, object_json[:id]).to_return(status: 500)
- # When receiving the reply…
- described_class.new(activity_for_object(reply_json), sender, delivery: true).perform
- # NOTE: Refering explicitly to the workers is a bit awkward
- DistributionWorker.drain
- FeedInsertWorker.drain
- # …it creates a status with an unknown parent
- reply = Status.find_by(uri: reply_json[:id])
- expect(reply.reply?).to be true
- expect(reply.in_reply_to_id).to be_nil
- # …and creates a notification
- expect(LocalNotificationWorker.jobs.size).to eq 1
- # …but does not insert it into timelines
- expect(redis.zscore(FeedManager.instance.key(:home, follower.id), reply.id)).to be_nil
- # When receiving the parent…
- described_class.new(activity_for_object(object_json), sender, delivery: true).perform
- Sidekiq::Worker.drain_all
- # …it creates a status and insert it into timelines
- parent = Status.find_by(uri: object_json[:id])
- expect(parent.reply?).to be false
- expect(parent.in_reply_to_id).to be_nil
- expect(reply.reload.in_reply_to_id).to eq parent.id
- # Check that the both statuses have been inserted into the home feed
- expect(redis.zscore(FeedManager.instance.key(:home, follower.id), parent.id)).to be_within(0.1).of(parent.id.to_f)
- expect(redis.zscore(FeedManager.instance.key(:home, follower.id), reply.id)).to be_within(0.1).of(reply.id.to_f)
- # Creates two notifications
- expect(Notification.count).to eq 2
- end
- it 'ignores unprocessable mention', :aggregate_failures do
- stub_request(:get, invalid_mention_json[:tag][:href]).to_raise(HTTP::ConnectionError)
- # When receiving the post that contains an invalid mention…
- described_class.new(activity_for_object(invalid_mention_json), sender, delivery: true).perform
- # NOTE: Refering explicitly to the workers is a bit awkward
- DistributionWorker.drain
- FeedInsertWorker.drain
- # …it creates a status
- status = Status.find_by(uri: invalid_mention_json[:id])
- # Check the process did not crash
- expect(status.nil?).to be false
- # It has queued a mention resolve job
- expect(MentionResolveWorker).to have_enqueued_sidekiq_job(status.id, invalid_mention_json[:tag][:href], anything)
- end
- end
- describe '#perform' do
- context 'when fetching' do
- subject { described_class.new(json, sender) }
- before do
- subject.perform
- end
- context 'when object publication date is below ISO8601 range' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- published: '-0977-11-03T08:31:22Z',
- }
- end
- it 'creates status with a valid creation date', :aggregate_failures do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- expect(status.created_at).to be_within(30).of(Time.now.utc)
- end
- end
- context 'when object publication date is above ISO8601 range' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- published: '10000-11-03T08:31:22Z',
- }
- end
- it 'creates status with a valid creation date', :aggregate_failures do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- expect(status.created_at).to be_within(30).of(Time.now.utc)
- end
- end
- context 'when object has been edited' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- published: '2022-01-22T15:00:00Z',
- updated: '2022-01-22T16:00:00Z',
- }
- end
- it 'creates status with appropriate creation and edition dates', :aggregate_failures do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- expect(status.created_at).to eq '2022-01-22T15:00:00Z'.to_datetime
- expect(status.edited?).to be true
- expect(status.edited_at).to eq '2022-01-22T16:00:00Z'.to_datetime
- end
- end
- context 'when object has update date equal to creation date' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- published: '2022-01-22T15:00:00Z',
- updated: '2022-01-22T15:00:00Z',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- end
- it 'does not mark status as edited' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.edited?).to be false
- end
- end
- context 'with an unknown object type' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Banana',
- content: 'Lorem ipsum',
- }
- end
- it 'does not create a status' do
- expect(sender.statuses.count).to be_zero
- end
- end
- context 'with a standalone' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- end
- it 'missing to/cc defaults to direct privacy' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'direct'
- end
- end
- context 'when public with explicit public address' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: 'https://www.w3.org/ns/activitystreams#Public',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'public'
- end
- end
- context 'when public with as:Public' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: 'as:Public',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'public'
- end
- end
- context 'when public with Public' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: 'Public',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'public'
- end
- end
- context 'when unlisted with explicit public address' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- cc: 'https://www.w3.org/ns/activitystreams#Public',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'unlisted'
- end
- end
- context 'when unlisted with as:Public' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- cc: 'as:Public',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'unlisted'
- end
- end
- context 'when unlisted with Public' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- cc: 'Public',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'unlisted'
- end
- end
- context 'when private' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: 'http://example.com/followers',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'private'
- end
- end
- context 'when private with inlined Collection in audience' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: {
- type: 'OrderedCollection',
- id: 'http://example.com/followers',
- first: 'http://example.com/followers?page=true',
- },
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'private'
- end
- end
- context 'when limited' do
- let(:recipient) { Fabricate(:account) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: ActivityPub::TagManager.instance.uri_for(recipient),
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'limited'
- end
- it 'creates silent mention' do
- status = sender.statuses.first
- expect(status.mentions.first).to be_silent
- end
- end
- context 'when direct' do
- let(:recipient) { Fabricate(:account) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: ActivityPub::TagManager.instance.uri_for(recipient),
- tag: {
- type: 'Mention',
- href: ActivityPub::TagManager.instance.uri_for(recipient),
- },
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.visibility).to eq 'direct'
- end
- end
- context 'with a reply' do
- let(:original_status) { Fabricate(:status) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- inReplyTo: ActivityPub::TagManager.instance.uri_for(original_status),
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.thread).to eq original_status
- expect(status.reply?).to be true
- expect(status.in_reply_to_account).to eq original_status.account
- expect(status.conversation).to eq original_status.conversation
- end
- end
- context 'with mentions' do
- let(:recipient) { Fabricate(:account) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- tag: [
- {
- type: 'Mention',
- href: ActivityPub::TagManager.instance.uri_for(recipient),
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.mentions.map(&:account)).to include(recipient)
- end
- end
- context 'with mentions missing href' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- tag: [
- {
- type: 'Mention',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- end
- end
- context 'with media attachments' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- attachment: [
- {
- type: 'Document',
- mediaType: 'image/png',
- url: 'http://example.com/attachment.png',
- },
- {
- type: 'Document',
- mediaType: 'image/png',
- url: 'http://example.com/emoji.png',
- },
- ],
- }
- end
- it 'creates status with correctly-ordered media attachments' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.ordered_media_attachments.map(&:remote_url)).to eq ['http://example.com/attachment.png', 'http://example.com/emoji.png']
- expect(status.ordered_media_attachment_ids).to be_present
- end
- end
- context 'with media attachments with long description' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- attachment: [
- {
- type: 'Document',
- mediaType: 'image/png',
- url: 'http://example.com/attachment.png',
- name: '*' * 1500,
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.media_attachments.map(&:description)).to include('*' * 1500)
- end
- end
- context 'with media attachments with long description as summary' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- attachment: [
- {
- type: 'Document',
- mediaType: 'image/png',
- url: 'http://example.com/attachment.png',
- summary: '*' * 1500,
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.media_attachments.map(&:description)).to include('*' * 1500)
- end
- end
- context 'with media attachments with focal points' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- attachment: [
- {
- type: 'Document',
- mediaType: 'image/png',
- url: 'http://example.com/attachment.png',
- focalPoint: [0.5, -0.7],
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
- end
- end
- context 'with media attachments missing url' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- attachment: [
- {
- type: 'Document',
- mediaType: 'image/png',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- end
- end
- context 'with hashtags' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- tag: [
- {
- type: 'Hashtag',
- href: 'http://example.com/blah',
- name: '#test',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.tags.map(&:name)).to include('test')
- end
- end
- context 'with hashtags missing name' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- tag: [
- {
- type: 'Hashtag',
- href: 'http://example.com/blah',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- end
- end
- context 'with hashtags invalid name' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- tag: [
- {
- type: 'Hashtag',
- href: 'http://example.com/blah',
- name: 'foo, #eh !',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- end
- end
- context 'with emojis' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum :tinking:',
- tag: [
- {
- type: 'Emoji',
- icon: {
- url: 'http://example.com/emoji.png',
- },
- name: 'tinking',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.emojis.map(&:shortcode)).to include('tinking')
- end
- end
- context 'with emojis served with invalid content-type' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum :tinkong:',
- tag: [
- {
- type: 'Emoji',
- icon: {
- url: 'http://example.com/emojib.png',
- },
- name: 'tinkong',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.emojis.map(&:shortcode)).to include('tinkong')
- end
- end
- context 'with emojis missing name' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum :tinking:',
- tag: [
- {
- type: 'Emoji',
- icon: {
- url: 'http://example.com/emoji.png',
- },
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- end
- end
- context 'with emojis missing icon' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum :tinking:',
- tag: [
- {
- type: 'Emoji',
- name: 'tinking',
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- end
- end
- context 'with poll' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Question',
- content: 'Which color was the submarine?',
- oneOf: [
- {
- name: 'Yellow',
- replies: {
- type: 'Collection',
- totalItems: 10,
- },
- },
- {
- name: 'Blue',
- replies: {
- type: 'Collection',
- totalItems: 3,
- },
- },
- ],
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.poll).to_not be_nil
- end
- it 'creates a poll' do
- poll = sender.polls.first
- expect(poll).to_not be_nil
- expect(poll.status).to_not be_nil
- expect(poll.options).to eq %w(Yellow Blue)
- expect(poll.cached_tallies).to eq [10, 3]
- end
- end
- context 'when a vote to a local poll' do
- let(:poll) { Fabricate(:poll, options: %w(Yellow Blue)) }
- let!(:local_status) { Fabricate(:status, poll: poll) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- name: 'Yellow',
- inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
- }
- end
- it 'adds a vote to the poll with correct uri' do
- vote = poll.votes.first
- expect(vote).to_not be_nil
- expect(vote.uri).to eq object_json[:id]
- expect(poll.reload.cached_tallies).to eq [1, 0]
- end
- end
- context 'when a vote to an expired local poll' do
- let(:poll) do
- poll = Fabricate.build(:poll, options: %w(Yellow Blue), expires_at: 1.day.ago)
- poll.save(validate: false)
- poll
- end
- let!(:local_status) { Fabricate(:status, poll: poll) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- name: 'Yellow',
- inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
- }
- end
- it 'does not add a vote to the poll' do
- expect(poll.votes.first).to be_nil
- end
- end
- context 'with counts' do
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- likes: {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar', '/likes'].join,
- type: 'Collection',
- totalItems: 50,
- },
- shares: {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar', '/shares'].join,
- type: 'Collection',
- totalItems: 100,
- },
- }
- end
- it 'uses the counts from the created object' do
- status = sender.statuses.first
- expect(status.untrusted_favourites_count).to eq 50
- expect(status.untrusted_reblogs_count).to eq 100
- end
- end
- end
- context 'when object URI uses bearcaps' do
- subject { described_class.new(json, sender) }
- let(:token) { 'foo' }
- let(:json) do
- {
- '@context': 'https://www.w3.org/ns/activitystreams',
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#foo'].join,
- type: 'Create',
- actor: ActivityPub::TagManager.instance.uri_for(sender),
- object: Addressable::URI.new(scheme: 'bear', query_values: { t: token, u: object_json[:id] }).to_s,
- }.with_indifferent_access
- end
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: 'https://www.w3.org/ns/activitystreams#Public',
- }
- end
- before do
- stub_request(:get, object_json[:id])
- .with(headers: { Authorization: "Bearer #{token}" })
- .to_return(body: Oj.dump(object_json), headers: { 'Content-Type': 'application/activity+json' })
- subject.perform
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status).to have_attributes(
- visibility: 'public',
- text: 'Lorem ipsum'
- )
- end
- end
- context 'when sender is followed by local users' do
- subject { described_class.new(json, sender, delivery: true) }
- before do
- Fabricate(:account).follow!(sender)
- subject.perform
- end
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- }
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- end
- end
- context 'when sender replies to local status' do
- subject { described_class.new(json, sender, delivery: true) }
- let!(:local_status) { Fabricate(:status) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- inReplyTo: ActivityPub::TagManager.instance.uri_for(local_status),
- }
- end
- before do
- subject.perform
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- end
- end
- context 'when sender targets a local user' do
- subject { described_class.new(json, sender, delivery: true) }
- let!(:local_account) { Fabricate(:account) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- to: ActivityPub::TagManager.instance.uri_for(local_account),
- }
- end
- before do
- subject.perform
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- end
- end
- context 'when sender cc\'s a local user' do
- subject { described_class.new(json, sender, delivery: true) }
- let!(:local_account) { Fabricate(:account) }
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- cc: ActivityPub::TagManager.instance.uri_for(local_account),
- }
- end
- before do
- subject.perform
- end
- it 'creates status' do
- status = sender.statuses.first
- expect(status).to_not be_nil
- expect(status.text).to eq 'Lorem ipsum'
- end
- end
- context 'when the sender has no relevance to local activity' do
- subject { described_class.new(json, sender, delivery: true) }
- before do
- subject.perform
- end
- let(:object_json) do
- {
- id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
- type: 'Note',
- content: 'Lorem ipsum',
- }
- end
- it 'does not create anything' do
- expect(sender.statuses.count).to eq 0
- end
- end
- end
- end
|