mirror of
https://github.com/funamitech/mastodon
synced 2024-11-27 14:29:03 +09:00
Register an XML encoder for response tests (#32220)
This commit is contained in:
parent
d95f6f4410
commit
cc8d723e71
@ -3,45 +3,62 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'The /.well-known/host-meta request' do
|
RSpec.describe 'The /.well-known/host-meta request' do
|
||||||
it 'returns http success with valid XML response' do
|
context 'without extension format or accept header' do
|
||||||
get '/.well-known/host-meta'
|
it 'returns http success with expected XML' do
|
||||||
|
get '/.well-known/host-meta'
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
.and have_attributes(
|
.and have_attributes(
|
||||||
media_type: 'application/xrd+xml'
|
media_type: 'application/xrd+xml'
|
||||||
)
|
)
|
||||||
|
|
||||||
doc = Nokogiri::XML(response.parsed_body)
|
expect(xrd_link_template_value)
|
||||||
expect(doc.at_xpath('/xrd:XRD/xrd:Link[@rel="lrdd"]/@template', 'xrd' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0').value)
|
.to eq 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}'
|
||||||
.to eq 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}'
|
end
|
||||||
|
|
||||||
|
def xrd_link_template_value
|
||||||
|
response
|
||||||
|
.parsed_body
|
||||||
|
.at_xpath('/xrd:XRD/xrd:Link[@rel="lrdd"]/@template', 'xrd' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0')
|
||||||
|
.value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success with valid JSON response with .json extension' do
|
context 'with a .json format extension' do
|
||||||
get '/.well-known/host-meta.json'
|
it 'returns http success with expected JSON' do
|
||||||
|
get '/.well-known/host-meta.json'
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
.and have_attributes(
|
.and have_attributes(
|
||||||
media_type: 'application/json'
|
media_type: 'application/json'
|
||||||
)
|
)
|
||||||
|
expect(response.parsed_body)
|
||||||
expect(response.parsed_body)
|
.to include(expected_json_template)
|
||||||
.to include(
|
end
|
||||||
links: [
|
|
||||||
'rel' => 'lrdd',
|
|
||||||
'template' => 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}',
|
|
||||||
]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success with valid JSON response with Accept header' do
|
context 'with a JSON `Accept` header' do
|
||||||
get '/.well-known/host-meta', headers: { 'Accept' => 'application/json' }
|
it 'returns http success with expected JSON' do
|
||||||
|
get '/.well-known/host-meta', headers: { 'Accept' => 'application/json' }
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
.and have_attributes(
|
.and have_attributes(
|
||||||
media_type: 'application/json'
|
media_type: 'application/json'
|
||||||
)
|
)
|
||||||
|
expect(response.parsed_body)
|
||||||
|
.to include(expected_json_template)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def expected_json_template
|
||||||
|
{
|
||||||
|
links: [
|
||||||
|
'rel' => 'lrdd',
|
||||||
|
'template' => 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}',
|
||||||
|
],
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
spec/support/response_encoders.rb
Normal file
4
spec/support/response_encoders.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
ActionDispatch::IntegrationTest
|
||||||
|
.register_encoder :xml, response_parser: ->(body) { Nokogiri::XML(body) }
|
Loading…
Reference in New Issue
Block a user