Add handling of type filters and handling of ETags

Add API documentation and test cases around ETags for the API.
This commit is contained in:
Maciej Szlosarczyk 2020-05-15 14:43:18 +03:00
parent 960e4084e3
commit 6e5a97ad4d
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
5 changed files with 182 additions and 19 deletions

View file

@ -24,6 +24,41 @@ class ReppV1RetainedDomainsTest < ActionDispatch::IntegrationTest
assert_equal response_json[:domains], expected_objects
end
def test_get_index_with_type_parameter
get repp_v1_retained_domains_path({ 'type' => 'reserved' })
response_json = JSON.parse(response.body, symbolize_names: true)
assert response_json[:count] == 1
expected_objects = [{ name: 'reserved.test',
status: 'reserved',
punycode_name: 'reserved.test' }]
assert_equal response_json[:domains], expected_objects
end
def test_etags_cache
get repp_v1_retained_domains_path({ 'type' => 'reserved' })
etag = response.headers['ETag']
get repp_v1_retained_domains_path({ 'type' => 'reserved' }),
headers: { 'If-None-Match' => etag }
assert_equal response.status, 304
assert_equal response.body, ''
end
def test_etags_cache_valid_for_type_only
get repp_v1_retained_domains_path({ 'type' => 'blocked' })
etag = response.headers['ETag']
get repp_v1_retained_domains_path, headers: { 'If-None-Match' => etag }
assert_equal response.status, 200
response_json = JSON.parse(response.body, symbolize_names: true)
assert response_json[:count] == 3
end
def test_cors_preflight
process :options, repp_v1_retained_domains_path, headers: { 'Origin' => 'https://example.com' }