mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-21 17:53:18 +00:00
Implement FEP 7888: Part 1 - publish conversation context (#35959)
This commit is contained in:
parent
9463a31107
commit
65b4a0a6f1
15 changed files with 309 additions and 12 deletions
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue