Skip to content

Commit a820478

Browse files
committed
fix: keep unknown api v1 paths inside the api contract
1 parent 392997c commit a820478

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

app/web/routes/api_v1.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def call(router)
2222
HealthRoutes.call(router)
2323
FeedRoutes.call(router)
2424
MetadataRoutes.call(router)
25+
26+
raise NotFoundError
2527
end
2628
end
2729
end

frontend/src/__tests__/useFeedConversion.contract.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('useFeedConversion contract', () => {
2121
feed_token: 'generated-token',
2222
public_url: '/api/v1/feeds/generated-token',
2323
json_public_url: '/api/v1/feeds/generated-token.json',
24-
})
24+
}),
25+
{ status: 201 }
2526
);
2627
})
2728
);

frontend/src/__tests__/useFeedConversion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('useFeedConversion', () => {
4242
data: { feed: mockResult },
4343
}),
4444
{
45-
status: 200,
45+
status: 201,
4646
headers: { 'Content-Type': 'application/json' },
4747
}
4848
)

spec/html2rss/web/api/v1_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ def json_feed_headers_tuple
154154
end
155155
end
156156

157+
describe 'GET /api/v1/unknown', openapi: false do
158+
it 'returns a JSON 404 instead of falling through to feed routes', :aggregate_failures do
159+
get '/api/v1/unknown'
160+
161+
expect(last_response.status).to eq(404)
162+
expect(last_response.content_type).to include('application/json')
163+
expect(JSON.parse(last_response.body)).to include(
164+
'success' => false,
165+
'error' => include(
166+
'message' => Html2rss::Web::NotFoundError::DEFAULT_MESSAGE,
167+
'code' => Html2rss::Web::NotFoundError::CODE
168+
)
169+
)
170+
end
171+
end
172+
157173
describe 'GET /api/v1/health', openapi: {
158174
summary: 'Authenticated health check',
159175
operation_id: 'getHealthStatus',

0 commit comments

Comments
 (0)