2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-09 05:52:15 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ActivityPub::Activity::Update do
|
2023-02-20 15:24:14 +11:00
|
|
|
subject { described_class.new(json, sender) }
|
|
|
|
|
2023-07-21 02:23:48 +10:00
|
|
|
let!(:sender) { Fabricate(:account, domain: 'example.com', inbox_url: 'https://example.com/foo/inbox', outbox_url: 'https://example.com/foo/outbox') }
|
2017-08-09 05:52:15 +10:00
|
|
|
|
2022-01-27 04:05:39 +11:00
|
|
|
describe '#perform' do
|
|
|
|
context 'with an Actor object' do
|
|
|
|
let(:actor_json) do
|
2023-07-21 02:23:48 +10:00
|
|
|
{
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
{
|
|
|
|
manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
|
|
|
|
toot: 'http://joinmastodon.org/ns#',
|
|
|
|
featured: { '@id': 'toot:featured', '@type': '@id' },
|
|
|
|
featuredTags: { '@id': 'toot:featuredTags', '@type': '@id' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
id: sender.uri,
|
|
|
|
type: 'Person',
|
|
|
|
following: 'https://example.com/users/dfsdf/following',
|
|
|
|
followers: 'https://example.com/users/dfsdf/followers',
|
|
|
|
inbox: sender.inbox_url,
|
|
|
|
outbox: sender.outbox_url,
|
|
|
|
featured: 'https://example.com/users/dfsdf/featured',
|
|
|
|
featuredTags: 'https://example.com/users/dfsdf/tags',
|
|
|
|
preferredUsername: sender.username,
|
|
|
|
name: 'Totally modified now',
|
|
|
|
publicKey: {
|
|
|
|
id: "#{sender.uri}#main-key",
|
|
|
|
owner: sender.uri,
|
|
|
|
publicKeyPem: sender.public_key,
|
|
|
|
},
|
|
|
|
}
|
2022-01-27 04:05:39 +11:00
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
|
2022-01-27 04:05:39 +11:00
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Update',
|
2023-07-21 02:23:48 +10:00
|
|
|
actor: sender.uri,
|
2022-01-27 04:05:39 +11:00
|
|
|
object: actor_json,
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
|
2022-01-27 04:05:39 +11:00
|
|
|
before do
|
|
|
|
stub_request(:get, actor_json[:outbox]).to_return(status: 404)
|
|
|
|
stub_request(:get, actor_json[:followers]).to_return(status: 404)
|
|
|
|
stub_request(:get, actor_json[:following]).to_return(status: 404)
|
|
|
|
stub_request(:get, actor_json[:featured]).to_return(status: 404)
|
2023-07-21 02:23:48 +10:00
|
|
|
stub_request(:get, actor_json[:featuredTags]).to_return(status: 404)
|
2022-01-27 04:05:39 +11:00
|
|
|
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates profile' do
|
|
|
|
expect(sender.reload.display_name).to eq 'Totally modified now'
|
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
end
|
|
|
|
|
2022-01-27 04:05:39 +11:00
|
|
|
context 'with a Question object' do
|
|
|
|
let!(:at_time) { Time.now.utc }
|
2023-07-21 02:23:48 +10:00
|
|
|
let!(:status) { Fabricate(:status, uri: 'https://example.com/statuses/poll', account: sender, poll: Poll.new(account: sender, options: %w(Bar Baz), cached_tallies: [0, 0], expires_at: at_time + 5.days)) }
|
2022-01-27 04:05:39 +11:00
|
|
|
|
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Update',
|
2023-07-21 02:23:48 +10:00
|
|
|
actor: sender.uri,
|
2022-01-27 04:05:39 +11:00
|
|
|
object: {
|
|
|
|
type: 'Question',
|
2023-07-21 02:23:48 +10:00
|
|
|
id: status.uri,
|
2022-01-27 04:05:39 +11:00
|
|
|
content: 'Foo',
|
|
|
|
endTime: (at_time + 5.days).iso8601,
|
|
|
|
oneOf: [
|
|
|
|
{
|
|
|
|
type: 'Note',
|
|
|
|
name: 'Bar',
|
|
|
|
replies: {
|
|
|
|
type: 'Collection',
|
|
|
|
totalItems: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
type: 'Note',
|
|
|
|
name: 'Baz',
|
|
|
|
replies: {
|
|
|
|
type: 'Collection',
|
|
|
|
totalItems: 12,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
status.update!(uri: ActivityPub::TagManager.instance.uri_for(status))
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates poll numbers' do
|
|
|
|
expect(status.preloadable_poll.cached_tallies).to eq [0, 12]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not set status as edited' do
|
|
|
|
expect(status.edited_at).to be_nil
|
|
|
|
end
|
2017-08-09 05:52:15 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|