0
0
Fork 0

Add response.content_type checks for JSON to api/v1 request specs (#31981)

This commit is contained in:
Matt Jankowski 2024-09-20 09:13:04 -04:00 committed by GitHub
parent a7dbf6f5a5
commit 66326065b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
98 changed files with 930 additions and 14 deletions

View file

@ -18,6 +18,8 @@ RSpec.describe '/api/v1/statuses' do
get '/api/v1/statuses', headers: headers, params: { id: [status.id, other_status.id, 123_123] }
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body).to contain_exactly(
hash_including(id: status.id.to_s),
hash_including(id: other_status.id.to_s)
@ -39,6 +41,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
end
context 'when post includes filtered terms' do
@ -52,6 +56,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body[:filtered][0]).to include({
filter: a_hash_including({
id: user.account.custom_filters.first.id.to_s,
@ -75,6 +81,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body[:filtered][0]).to include({
filter: a_hash_including({
id: user.account.custom_filters.first.id.to_s,
@ -97,6 +105,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body[:reblog][:filtered][0]).to include({
filter: a_hash_including({
id: user.account.custom_filters.first.id.to_s,
@ -121,6 +131,8 @@ RSpec.describe '/api/v1/statuses' 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')
end
end
@ -139,6 +151,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['X-RateLimit-Limit']).to eq RateLimiter::FAMILIES[:statuses][:limit].to_s
expect(response.headers['X-RateLimit-Remaining']).to eq (RateLimiter::FAMILIES[:statuses][:limit] - 1).to_s
end
@ -154,6 +168,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(422)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to match [{ id: bob.id.to_s, acct: bob.acct }]
end
end
@ -165,6 +181,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(422)
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['X-RateLimit-Limit']).to eq RateLimiter::FAMILIES[:statuses][:limit].to_s
end
end
@ -179,6 +197,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(429)
expect(response.content_type)
.to start_with('application/json')
expect(response.headers['X-RateLimit-Limit']).to eq RateLimiter::FAMILIES[:statuses][:limit].to_s
expect(response.headers['X-RateLimit-Remaining']).to eq '0'
end
@ -191,6 +211,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(404)
expect(response.content_type)
.to start_with('application/json')
end
end
@ -202,6 +224,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
end
it 'creates a scheduled status' do
@ -215,6 +239,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(422)
expect(response.content_type)
.to start_with('application/json')
expect(account.scheduled_statuses).to be_empty
end
end
@ -235,6 +261,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(Status.find_by(id: status.id)).to be_nil
end
end
@ -253,6 +281,8 @@ RSpec.describe '/api/v1/statuses' do
subject
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(status.reload.text).to eq 'I am updated'
end
end
@ -267,6 +297,8 @@ RSpec.describe '/api/v1/statuses' do
get "/api/v1/statuses/#{status.id}"
expect(response).to have_http_status(404)
expect(response.content_type)
.to start_with('application/json')
end
end
@ -279,6 +311,8 @@ RSpec.describe '/api/v1/statuses' 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
@ -291,6 +325,8 @@ RSpec.describe '/api/v1/statuses' do
get "/api/v1/statuses/#{status.id}"
expect(response).to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
end
end
@ -303,6 +339,8 @@ RSpec.describe '/api/v1/statuses' 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