Add tests for ActivityPub poll processing (#10143)
This commit is contained in:
parent
3cf98aac66
commit
0e6998da3c
@ -231,8 +231,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
|||||||
items = @object['oneOf']
|
items = @object['oneOf']
|
||||||
end
|
end
|
||||||
|
|
||||||
Poll.new(
|
@account.polls.new(
|
||||||
account: @account,
|
|
||||||
multiple: multiple,
|
multiple: multiple,
|
||||||
expires_at: expires_at,
|
expires_at: expires_at,
|
||||||
options: items.map { |item| item['name'].presence || item['content'] },
|
options: items.map { |item| item['name'].presence || item['content'] },
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ActivityPub::Activity::Create do
|
RSpec.describe ActivityPub::Activity::Create do
|
||||||
let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers') }
|
let(:sender) { Fabricate(:account, followers_url: 'http://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor') }
|
||||||
|
|
||||||
let(:json) do
|
let(:json) do
|
||||||
{
|
{
|
||||||
@ -407,6 +407,46 @@ RSpec.describe ActivityPub::Activity::Create do
|
|||||||
expect(status).to_not be_nil
|
expect(status).to_not be_nil
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when sender is followed by local users' do
|
context 'when sender is followed by local users' do
|
||||||
|
Loading…
Reference in New Issue
Block a user