mirror of
https://github.com/funamitech/mastodon
synced 2024-11-23 22:57:05 +09:00
Use built-in response.parsed_body
for JSON response specs (#31674)
This commit is contained in:
parent
388d5473e1
commit
40f993b3a0
@ -94,7 +94,7 @@ RSpec.describe 'Domain Blocks' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq(
|
||||
expect(body_as_json).to match(
|
||||
{
|
||||
id: domain_block.id.to_s,
|
||||
domain: domain_block.domain,
|
||||
|
@ -26,7 +26,7 @@ describe 'Translation Languages' do
|
||||
.to have_http_status(200)
|
||||
|
||||
expect(body_as_json)
|
||||
.to eq({ und: %w(en de), en: ['de'] })
|
||||
.to match({ und: %w(en de), en: ['de'] })
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -60,7 +60,7 @@ RSpec.describe 'Lists' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: list.id.to_s,
|
||||
title: list.title,
|
||||
replies_policy: list.replies_policy,
|
||||
@ -144,7 +144,7 @@ RSpec.describe 'Lists' do
|
||||
expect(response).to have_http_status(200)
|
||||
list.reload
|
||||
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: list.id.to_s,
|
||||
title: list.title,
|
||||
replies_policy: list.replies_policy,
|
||||
|
@ -133,7 +133,7 @@ RSpec.describe 'Requests' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({ merged: true })
|
||||
expect(body_as_json).to match({ merged: true })
|
||||
end
|
||||
end
|
||||
|
||||
@ -146,7 +146,7 @@ RSpec.describe 'Requests' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({ merged: false })
|
||||
expect(body_as_json).to match({ merged: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ RSpec.describe 'Sources' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: status.id.to_s,
|
||||
text: status.text,
|
||||
spoiler_text: status.spoiler_text,
|
||||
@ -51,7 +51,7 @@ RSpec.describe 'Sources' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: status.id.to_s,
|
||||
text: status.text,
|
||||
spoiler_text: status.spoiler_text,
|
||||
|
@ -154,7 +154,7 @@ describe '/api/v1/statuses' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to eq [{ id: bob.id.to_s, acct: bob.acct }]
|
||||
expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to match [{ id: bob.id.to_s, acct: bob.acct }]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,7 +63,7 @@ RSpec.describe 'Filters' do
|
||||
expect(json[:title]).to eq 'magic'
|
||||
expect(json[:filter_action]).to eq 'hide'
|
||||
expect(json[:context]).to eq ['home']
|
||||
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to eq [{ keyword: 'magic', whole_word: true }]
|
||||
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to match [{ keyword: 'magic', whole_word: true }]
|
||||
end
|
||||
|
||||
it 'creates a filter', :aggregate_failures do
|
||||
|
@ -235,7 +235,7 @@ RSpec.describe 'Notifications' do
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json[:partial_accounts].size).to be > 0
|
||||
expect(body_as_json[:partial_accounts][0].keys).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url)
|
||||
expect(body_as_json[:partial_accounts][0].keys.map(&:to_sym)).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url)
|
||||
expect(body_as_json[:partial_accounts].pluck(:id)).to_not include(recent_account.id.to_s)
|
||||
expect(body_as_json[:accounts].pluck(:id)).to include(recent_account.id.to_s)
|
||||
end
|
||||
|
@ -39,11 +39,7 @@ RSpec.configure do |config|
|
||||
end
|
||||
|
||||
def body_as_json
|
||||
json_str_to_hash(response.body)
|
||||
end
|
||||
|
||||
def json_str_to_hash(str)
|
||||
JSON.parse(str, symbolize_names: true)
|
||||
response.parsed_body
|
||||
end
|
||||
|
||||
def serialized_record_json(record, serializer, adapter: nil)
|
||||
|
@ -9,7 +9,9 @@ end
|
||||
|
||||
RSpec::Matchers.define :match_json_values do |values|
|
||||
match do |string|
|
||||
expect(json_str_to_hash(string))
|
||||
parsed_json = JSON.parse(string, symbolize_names: true)
|
||||
|
||||
expect(parsed_json)
|
||||
.to include(values)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user