1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Use include_pagination_headers in more places (#30999)

This commit is contained in:
Matt Jankowski 2024-07-12 04:30:52 -04:00 committed by GitHub
parent 28ad3588e4
commit 43e24dbb13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 31 additions and 42 deletions

View file

@ -10,12 +10,15 @@ describe 'API V1 Accounts Statuses' do
describe 'GET /api/v1/accounts/:account_id/statuses' do
it 'returns expected headers', :aggregate_failures do
Fabricate(:status, account: user.account)
status = Fabricate(:status, account: user.account)
get "/api/v1/accounts/#{user.account.id}/statuses", params: { limit: 1 }, headers: headers
expect(response).to have_http_status(200)
expect(links_from_header.size)
.to eq(2)
expect(response)
.to have_http_status(200)
.and include_pagination_headers(
prev: api_v1_account_statuses_url(limit: 1, min_id: status.id),
next: api_v1_account_statuses_url(limit: 1, max_id: status.id)
)
end
context 'with only media' do
@ -55,16 +58,9 @@ describe 'API V1 Accounts Statuses' do
it 'returns http success and includes a header link' do
get "/api/v1/accounts/#{user.account.id}/statuses", params: { pinned: true }, headers: headers
expect(response).to have_http_status(200)
expect(links_from_header.size)
.to eq(1)
expect(links_from_header)
.to contain_exactly(
have_attributes(
href: /pinned=true/,
attr_pairs: contain_exactly(['rel', 'prev'])
)
)
expect(response)
.to have_http_status(200)
.and include_pagination_headers(prev: api_v1_account_statuses_url(pinned: true, min_id: Status.first.id))
end
end
@ -77,19 +73,11 @@ describe 'API V1 Accounts Statuses' do
it 'returns http success and header pagination links to prev and next' do
get "/api/v1/accounts/#{user.account.id}/statuses", params: { pinned: true }, headers: headers
expect(response).to have_http_status(200)
expect(links_from_header.size)
.to eq(2)
expect(links_from_header)
.to contain_exactly(
have_attributes(
href: /pinned=true/,
attr_pairs: contain_exactly(['rel', 'next'])
),
have_attributes(
href: /pinned=true/,
attr_pairs: contain_exactly(['rel', 'prev'])
)
expect(response)
.to have_http_status(200)
.and include_pagination_headers(
prev: api_v1_account_statuses_url(pinned: true, min_id: Status.first.id),
next: api_v1_account_statuses_url(pinned: true, max_id: Status.first.id)
)
end
end
@ -138,12 +126,4 @@ describe 'API V1 Accounts Statuses' do
end
end
end
private
def links_from_header
response
.headers['Link']
.links
end
end

View file

@ -20,8 +20,12 @@ RSpec.describe 'API V1 Conversations' do
it 'returns pagination headers', :aggregate_failures do
get '/api/v1/conversations', params: { limit: 1 }, headers: headers
expect(response).to have_http_status(200)
expect(response.headers['Link'].links.size).to eq(2)
expect(response)
.to have_http_status(200)
.and include_pagination_headers(
prev: api_v1_conversations_url(limit: 1, min_id: Status.first.id),
next: api_v1_conversations_url(limit: 1, max_id: Status.first.id)
)
end
it 'returns conversations', :aggregate_failures do

View file

@ -29,8 +29,10 @@ RSpec.describe 'API V1 Statuses Favourited by Accounts' do
expect(response)
.to have_http_status(200)
expect(response.headers['Link'].links.size)
.to eq(2)
.and include_pagination_headers(
prev: api_v1_status_favourited_by_index_url(limit: 2, since_id: Favourite.last.id),
next: api_v1_status_favourited_by_index_url(limit: 2, max_id: Favourite.first.id)
)
expect(body_as_json.size)
.to eq(2)

View file

@ -28,8 +28,10 @@ RSpec.describe 'API V1 Statuses Reblogged by Accounts' do
expect(response)
.to have_http_status(200)
expect(response.headers['Link'].links.size)
.to eq(2)
.and include_pagination_headers(
prev: api_v1_status_reblogged_by_index_url(limit: 2, since_id: bob.statuses.first.id),
next: api_v1_status_reblogged_by_index_url(limit: 2, max_id: alice.statuses.first.id)
)
expect(body_as_json.size)
.to eq(2)

View file

@ -83,7 +83,8 @@ RSpec.describe 'API V2 Admin Accounts' do
let(:params) { { limit: 1 } }
it 'sets the correct pagination headers' do
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v2_admin_accounts_url(limit: 1, max_id: admin_account.id)
expect(response)
.to include_pagination_headers(next: api_v2_admin_accounts_url(limit: 1, max_id: admin_account.id))
end
end
end