diff --git a/test/integration/admin_area/zones_test.rb b/test/integration/admin_area/zones_test.rb index bf7c07d7b..69fe650c5 100644 --- a/test/integration/admin_area/zones_test.rb +++ b/test/integration/admin_area/zones_test.rb @@ -24,4 +24,88 @@ class AdminAreaZonesIntegrationTest < ApplicationIntegrationTest assert_equal "attachment; filename=\"test.txt\"; filename*=UTF-8''test.txt", response.headers['Content-Disposition'] assert_not_empty response.body end + + def test_shows_new_form + get new_admin_zone_path + assert_response :success + end + + def test_shows_index + get admin_zones_path + assert_response :success + end + + def test_creates_zone_successfully + assert_difference 'DNS::Zone.count' do + post admin_zones_path, params: { + zone: { + origin: 'example.org', + ttl: 3600, + refresh: 1200, + retry: 1800, + expire: 3600000, + minimum_ttl: 600, + email: 'admin@example.org', + master_nameserver: 'ns1.example.org' + + } + } + end + + assert_redirected_to admin_zones_url + follow_redirect! + assert_response :success + end + + def test_fails_to_create_zone_with_invalid_data + assert_no_difference 'DNS::Zone.count' do + post admin_zones_path, params: { + zone: { + origin: '', + email: '' + } + } + + assert_response :success + end + end + + def test_shows_edit_form + get edit_admin_zone_path(@zone) + assert_response :success + end + + def test_fails_to_update_zone_with_invalid_data + patch admin_zone_path(@zone), params: { zone: { ttl: '' }} + + assert_response :success + + assert_includes response.body, "Ttl", "Ttl field error should be shown" + assert_includes response.body, "Ttl is missing", "Presence validation message expected" + + @zone.reload + refute_equal '', @zone.ttl, "Ttl should not have changed" + end + + def test_redirects_to_index_after_successful_operations + # Test redirect_to_index private method through public methods + post admin_zones_path, params: { + zone: { + origin: 'redirect-test.org', + ttl: 3600, + refresh: 1200, + retry: 1800, + expire: 3600000, + minimum_ttl: 600, + email: 'admin@redirect-test.org', + master_nameserver: 'ns1.redirect-test.org' + } + } + + assert_redirected_to admin_zones_url + + follow_redirect! + assert_response :success + assert_includes response.body, 'Zone has been created' + end end