Skip to content

Commit cafa1bf

Browse files
committed
test: tighten feed response smoke coverage
1 parent de0e657 commit cafa1bf

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

spec/html2rss/web/feeds/responder_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ def resolved_source
6060
expect(response_tuple(write_response)).to eq([200, 'application/xml', '<rss/>'])
6161
end
6262

63-
it 'marks the response as cacheable' do
63+
it 'marks the response as cacheable', :aggregate_failures do
6464
write_response
6565

66+
expect(response['Cache-Control']).to include('max-age=600')
6667
expect(response['Cache-Control']).to include('public')
68+
expect(response['Vary']).to eq('Accept')
6769
end
6870

6971
it 'emits success after writing the response' do
@@ -112,10 +114,11 @@ def resolved_source
112114
expect(response_tuple(write_response)).to eq([500, 'application/feed+json', '{"title":"Error"}'])
113115
end
114116

115-
it 'marks the response as non-cacheable' do
117+
it 'marks the response as non-cacheable', :aggregate_failures do
116118
write_response
117119

118120
expect(response['Cache-Control']).to include('no-store')
121+
expect(response['Vary']).to eq('Accept')
119122
end
120123
end
121124

spec/smoke/docker_spec.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ def get_json(path, headers: {})
1616
perform_request(uri, request)
1717
end
1818

19+
def get_response(path, headers: {})
20+
uri = URI.join(base_url, path)
21+
request = Net::HTTP::Get.new(uri, headers)
22+
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(request) }
23+
[response, response.body.to_s]
24+
end
25+
1926
def post_json(path, body:, headers: {})
2027
uri = URI.join(base_url, path)
2128
request = Net::HTTP::Post.new(uri, headers.merge('Content-Type' => 'application/json'))
@@ -28,6 +35,18 @@ def perform_request(uri, request)
2835
[response, response.body.to_s.empty? ? {} : JSON.parse(response.body)]
2936
end
3037

38+
def expect_created_feed_response(body)
39+
expect(body.fetch('success')).to be(true)
40+
expect(body.dig('data', 'feed', 'public_url')).to match(%r{^/api/v1/feeds/})
41+
expect(body.dig('data', 'feed', 'json_public_url')).to match(%r{^/api/v1/feeds/.+\.json$})
42+
end
43+
44+
def expect_json_feed_response(path)
45+
feed_response, = get_response(path, headers: { 'Accept' => 'application/feed+json' })
46+
expect(feed_response['Content-Type']).to include('application/feed+json')
47+
expect(feed_response.code).not_to eq('401')
48+
end
49+
3150
it 'exposes health endpoints without authentication requirements', :aggregate_failures do
3251
response, payload = get_json('/api/v1/health/ready')
3352
expect(response).to be_a(Net::HTTPOK)
@@ -72,9 +91,8 @@ def perform_request(uri, request)
7291
headers: { 'Authorization' => "Bearer #{feed_token}" })
7392

7493
expect(response.code).to eq('201')
75-
expect(body.fetch('success')).to be(true)
76-
expect(body.dig('data', 'feed', 'public_url')).to match(%r{^/api/v1/feeds/})
77-
expect(body.dig('data', 'feed', 'json_public_url')).to match(%r{^/api/v1/feeds/.+\.json$})
94+
expect_created_feed_response(body)
95+
expect_json_feed_response(body.dig('data', 'feed', 'json_public_url'))
7896
end
7997

8098
it 'returns forbidden for authenticated creation when auto source is disabled', :aggregate_failures do

0 commit comments

Comments
 (0)