Implement FEP 7888: Part 1 - publish conversation context (#35959)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:conversation)
|
||||
Fabricator(:conversation) do
|
||||
parent_account { Fabricate(:account) }
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ RSpec.describe AccountConversation do
|
||||
|
||||
it 'appends to old record when there is a match' do
|
||||
last_status = Fabricate(:status, account: alice, visibility: :direct)
|
||||
conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id])
|
||||
conversation = described_class.create!(account: alice, conversation_id: last_status.conversation_id, participant_account_ids: [bob.id], status_ids: [last_status.id])
|
||||
|
||||
status = Fabricate(:status, account: bob, visibility: :direct, thread: last_status)
|
||||
status.mentions.create(account: alice)
|
||||
@@ -36,7 +36,7 @@ RSpec.describe AccountConversation do
|
||||
|
||||
it 'creates new record when new participants are added' do
|
||||
last_status = Fabricate(:status, account: alice, visibility: :direct)
|
||||
conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id])
|
||||
conversation = described_class.create!(account: alice, conversation_id: last_status.conversation_id, participant_account_ids: [bob.id], status_ids: [last_status.id])
|
||||
|
||||
status = Fabricate(:status, account: bob, visibility: :direct, thread: last_status)
|
||||
status.mentions.create(account: alice)
|
||||
@@ -55,7 +55,7 @@ RSpec.describe AccountConversation do
|
||||
it 'updates last status to a previous value' do
|
||||
last_status = Fabricate(:status, account: alice, visibility: :direct)
|
||||
status = Fabricate(:status, account: alice, visibility: :direct)
|
||||
conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [status.id, last_status.id])
|
||||
conversation = described_class.create!(account: alice, conversation_id: last_status.conversation_id, participant_account_ids: [bob.id], status_ids: [status.id, last_status.id])
|
||||
last_status.mentions.create(account: bob)
|
||||
last_status.destroy!
|
||||
conversation.reload
|
||||
@@ -65,7 +65,7 @@ RSpec.describe AccountConversation do
|
||||
|
||||
it 'removes the record if no other statuses are referenced' do
|
||||
last_status = Fabricate(:status, account: alice, visibility: :direct)
|
||||
conversation = described_class.create!(account: alice, conversation: last_status.conversation, participant_account_ids: [bob.id], status_ids: [last_status.id])
|
||||
conversation = described_class.create!(account: alice, conversation_id: last_status.conversation_id, participant_account_ids: [bob.id], status_ids: [last_status.id])
|
||||
last_status.mentions.create(account: bob)
|
||||
last_status.destroy!
|
||||
expect(described_class.where(id: conversation.id).count).to eq 0
|
||||
|
||||
127
spec/requests/activitypub/contexts_spec.rb
Normal file
127
spec/requests/activitypub/contexts_spec.rb
Normal file
@@ -0,0 +1,127 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'ActivityPub Contexts' do
|
||||
let(:conversation) { Fabricate(:conversation) }
|
||||
|
||||
describe 'GET #show' do
|
||||
subject { get context_path(id: conversation.id), headers: nil }
|
||||
|
||||
let!(:status) { Fabricate(:status, conversation: conversation) }
|
||||
let!(:unrelated_status) { Fabricate(:status) }
|
||||
|
||||
it 'returns http success and correct media type and correct items' do
|
||||
subject
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_cacheable_headers
|
||||
|
||||
expect(response.media_type)
|
||||
.to eq 'application/activity+json'
|
||||
|
||||
expect(response.parsed_body[:type])
|
||||
.to eq 'Collection'
|
||||
|
||||
expect(response.parsed_body[:first][:items])
|
||||
.to be_an(Array)
|
||||
.and have_attributes(size: 1)
|
||||
.and include(ActivityPub::TagManager.instance.uri_for(status))
|
||||
.and not_include(ActivityPub::TagManager.instance.uri_for(unrelated_status))
|
||||
end
|
||||
|
||||
context 'with pagination' do
|
||||
context 'with few statuses' do
|
||||
before do
|
||||
3.times do
|
||||
Fabricate(:status, conversation: conversation)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not include a next page link' do
|
||||
subject
|
||||
|
||||
expect(response.parsed_body[:first][:next]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with many statuses' do
|
||||
before do
|
||||
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do
|
||||
Fabricate(:status, conversation: conversation)
|
||||
end
|
||||
end
|
||||
|
||||
it 'includes a next page link' do
|
||||
subject
|
||||
|
||||
expect(response.parsed_body['first']['next']).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #items' do
|
||||
subject { get items_context_path(id: conversation.id, page: 0, min_id: nil), headers: nil }
|
||||
|
||||
context 'with few statuses' do
|
||||
before do
|
||||
3.times do
|
||||
Fabricate(:status, conversation: conversation)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns http success and correct media type and correct items' do
|
||||
subject
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
|
||||
expect(response.media_type)
|
||||
.to eq 'application/activity+json'
|
||||
|
||||
expect(response.parsed_body[:type])
|
||||
.to eq 'Collection'
|
||||
|
||||
expect(response.parsed_body[:first][:items])
|
||||
.to be_an(Array)
|
||||
.and have_attributes(size: 3)
|
||||
|
||||
expect(response.parsed_body[:first][:next]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with many statuses' do
|
||||
before do
|
||||
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do
|
||||
Fabricate(:status, conversation: conversation)
|
||||
end
|
||||
end
|
||||
|
||||
it 'includes a next page link' do
|
||||
subject
|
||||
|
||||
expect(response.parsed_body['first']['next']).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with page requested' do
|
||||
before do
|
||||
(ActivityPub::ContextsController::DESCENDANTS_LIMIT + 1).times do |_i|
|
||||
Fabricate(:status, conversation: conversation)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns the correct items' do
|
||||
get items_context_path(id: conversation.id, page: 0, min_id: nil), headers: nil
|
||||
next_page = response.parsed_body['first']['next']
|
||||
get next_page, headers: nil
|
||||
|
||||
expect(response.parsed_body['items'])
|
||||
.to be_an(Array)
|
||||
.and have_attributes(size: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,6 +23,7 @@ RSpec.describe ActivityPub::NoteSerializer do
|
||||
'zh-TW' => a_kind_of(String),
|
||||
}),
|
||||
'replies' => replies_collection_values,
|
||||
'context' => ActivityPub::TagManager.instance.uri_for(parent.conversation),
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user