First draft of API to get a single collection (#37053)

This commit is contained in:
David Roetzel authored and GitHub committed 2025-12-01 15:04:52 +00:00
1 parent 1f9ddb7cf6
commit 2d203ca72a
11 files changed
+152 -5

No files matched your search

@@ -5,6 +5,50 @@ require 'rails_helper'
RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
include_context 'with API authentication', oauth_scopes: 'read:collections write:collections'
describe 'GET /api/v1_alpha/collections/:id' do
subject do
get "/api/v1_alpha/collections/#{collection.id}", headers: headers
end
let(:collection) { Fabricate(:collection) }
let!(:items) { Fabricate.times(2, :collection_item, collection:) }
shared_examples 'unfiltered, successful request' do
it 'includes all items in the response' do
subject
expect(response).to have_http_status(200)
expect(response.parsed_body[:items].size).to eq 2
end
end
context 'when user is not signed in' do
let(:headers) { {} }
it_behaves_like 'unfiltered, successful request'
end
context 'when user is signed in' do
context 'when the user has not blocked or muted anyone' do
it_behaves_like 'unfiltered, successful request'
end
context 'when the user has blocked an account' do
before do
user.account.block!(items.first.account)
end
it 'only includes the non-blocked account in the response' do
subject
expect(response).to have_http_status(200)
expect(response.parsed_body[:items].size).to eq 1
expect(response.parsed_body[:items][0]['position']).to eq items.last.position
end
end
end
end
describe 'POST /api/v1_alpha/collections' do
subject do
post '/api/v1_alpha/collections', headers: headers, params: params