2
0

Add have_cacheable_headers matcher for responses (#31727)

This commit is contained in:
Matt Jankowski
2024-09-03 11:35:19 -04:00
committed by GitHub
parent 490bdb7944
commit e1fa456c7c
11 changed files with 96 additions and 65 deletions

View File

@@ -25,10 +25,10 @@ RSpec.describe ActivityPub::CollectionsController do
context 'without signature' do
let(:remote_account) { nil }
it_behaves_like 'cacheable response'
it 'returns http success and correct media type and correct items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type).to eq 'application/activity+json'
expect(body_as_json[:orderedItems])
@@ -64,10 +64,11 @@ RSpec.describe ActivityPub::CollectionsController do
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
context 'when getting a featured resource' do
it_behaves_like 'cacheable response'
it 'returns http success and correct media type and expected items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type).to eq 'application/activity+json'
expect(body_as_json[:orderedItems])

View File

@@ -25,10 +25,11 @@ RSpec.describe ActivityPub::OutboxesController do
context 'with page not requested' do
let(:page) { nil }
it_behaves_like 'cacheable response'
it 'returns http success and correct media type and headers and items count' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Vary']).to be_nil
expect(body[:totalItems]).to eq 4
@@ -59,10 +60,11 @@ RSpec.describe ActivityPub::OutboxesController do
context 'with page requested' do
let(:page) { 'true' }
it_behaves_like 'cacheable response'
it 'returns http success and correct media type and vary header and items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Vary']).to include 'Signature'

View File

@@ -68,10 +68,11 @@ RSpec.describe ActivityPub::RepliesController do
let(:parent_visibility) { :public }
let(:page_json) { body_as_json[:first] }
it_behaves_like 'cacheable response'
it 'returns http success and correct media type' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_cacheable_headers
expect(response.media_type).to eq 'application/activity+json'
end

View File

@@ -72,13 +72,12 @@ describe StatusesController do
context 'with JSON' do
let(:format) { 'json' }
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
it 'renders ActivityPub Note object successfully', :aggregate_failures do
expect(response)
.to have_http_status(200)
.and have_cacheable_headers.with_vary('Accept, Accept-Language, Cookie')
expect(response.headers).to include(
'Vary' => 'Accept, Accept-Language, Cookie',
'Content-Type' => include('application/activity+json'),
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
)
@@ -380,13 +379,11 @@ describe StatusesController do
context 'with JSON' do
let(:format) { 'json' }
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
it 'renders ActivityPub Note object successfully', :aggregate_failures do
expect(response)
.to have_http_status(200)
.and have_cacheable_headers.with_vary('Accept, Accept-Language, Cookie')
expect(response.headers).to include(
'Vary' => 'Accept, Accept-Language, Cookie',
'Content-Type' => include('application/activity+json'),
'Link' => satisfy { |header| header.to_s.include?('activity+json') }
)