Extract api/v1/statuses#context to standalone controller (#38348)
This commit is contained in:
1 parent
c3afdb760c
commit
5f33cf0b0a
5 files changed
+160
-116
No files matched your search
@@ -0,0 +1,90 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'API V1 Statuses Contexts' do
|
||||
describe 'GET /api/v1/statuses/:status_id/context' do
|
||||
context 'with an oauth token' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:client_app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: client_app, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
let(:scopes) { 'read:statuses' }
|
||||
|
||||
context 'with a public status' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before { Fabricate(:status, account: user.account, thread: status) }
|
||||
|
||||
it 'returns http success' do
|
||||
get "/api/v1/statuses/#{status.id}/context", headers: headers
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq('application/json')
|
||||
expect(response.parsed_body)
|
||||
.to include(ancestors: be_an(Array).and(be_empty))
|
||||
.and include(descendants: be_an(Array).and(be_present))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a public status that is a reply' do
|
||||
let(:status) { Fabricate(:status, account: user.account, thread: Fabricate(:status)) }
|
||||
|
||||
before { Fabricate(:status, account: user.account, thread: status) }
|
||||
|
||||
it 'returns http success' do
|
||||
get "/api/v1/statuses/#{status.id}/context", headers: headers
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq('application/json')
|
||||
expect(response.parsed_body)
|
||||
.to include(ancestors: be_an(Array).and(be_present))
|
||||
.and include(descendants: be_an(Array).and(be_present))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an oauth token' do
|
||||
context 'with a public status' do
|
||||
let(:status) { Fabricate(:status, visibility: :public) }
|
||||
|
||||
before { Fabricate(:status, thread: status) }
|
||||
|
||||
it 'returns http success' do
|
||||
get "/api/v1/statuses/#{status.id}/context"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq('application/json')
|
||||
expect(response.parsed_body)
|
||||
.to include(ancestors: be_an(Array).and(be_empty))
|
||||
.and include(descendants: be_an(Array).and(be_present))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a public status that is a reply' do
|
||||
let(:status) { Fabricate(:status, visibility: :public, thread: Fabricate(:status)) }
|
||||
|
||||
before { Fabricate(:status, thread: status) }
|
||||
|
||||
it 'returns http success' do
|
||||
get "/api/v1/statuses/#{status.id}/context"
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(response.media_type)
|
||||
.to eq('application/json')
|
||||
expect(response.parsed_body)
|
||||
.to include(ancestors: be_an(Array).and(be_present))
|
||||
.and include(descendants: be_an(Array).and(be_present))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -132,38 +132,6 @@ RSpec.describe '/api/v1/statuses' do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/statuses/:id/context' do
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
Fabricate(:status, account: user.account, thread: status)
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get "/api/v1/statuses/#{status.id}/context", headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(response.headers['Mastodon-Async-Refresh']).to be_nil
|
||||
end
|
||||
|
||||
context 'with a remote status' do
|
||||
let(:status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com'), created_at: 1.hour.ago, updated_at: 1.hour.ago) }
|
||||
|
||||
it 'returns http success and queues discovery of new posts' do
|
||||
expect { get "/api/v1/statuses/#{status.id}/context", headers: headers }
|
||||
.to enqueue_sidekiq_job(ActivityPub::FetchAllRepliesWorker)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(response.headers['Mastodon-Async-Refresh']).to match(/result_count=0/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/statuses' do
|
||||
subject do
|
||||
post '/api/v1/statuses', headers: headers, params: params
|
||||
@@ -606,20 +574,6 @@ RSpec.describe '/api/v1/statuses' do
|
||||
.to start_with('application/json')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/statuses/:id/context' do
|
||||
before do
|
||||
Fabricate(:status, thread: status)
|
||||
end
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
get "/api/v1/statuses/#{status.id}/context"
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a public status' do
|
||||
@@ -634,20 +588,6 @@ RSpec.describe '/api/v1/statuses' do
|
||||
.to start_with('application/json')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/statuses/:id/context' do
|
||||
before do
|
||||
Fabricate(:status, thread: status)
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get "/api/v1/statuses/#{status.id}/context"
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user