From fb72adf410f5f58ff304a582d5879d354e746718 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 4 May 2025 02:50:34 +0300 Subject: [PATCH] Refactor api changeset test_upload_not_found --- .../api/changesets/uploads_controller_test.rb | 50 +++++++++++ .../api/changesets_controller_test.rb | 84 ------------------- 2 files changed, 50 insertions(+), 84 deletions(-) diff --git a/test/controllers/api/changesets/uploads_controller_test.rb b/test/controllers/api/changesets/uploads_controller_test.rb index 93a538a3a..97c614d05 100644 --- a/test/controllers/api/changesets/uploads_controller_test.rb +++ b/test/controllers/api/changesets/uploads_controller_test.rb @@ -715,6 +715,24 @@ module Api assert_equal 0, Relation.find(relation.id).tags.size, "relation #{relation.id} should now have no tags" end + def test_upload_modify_unknown_node_placeholder + check_upload_results_in_not_found do |changeset| + "" + end + end + + def test_upload_modify_unknown_way_placeholder + check_upload_results_in_not_found do |changeset| + "" + end + end + + def test_upload_modify_unknown_relation_placeholder + check_upload_results_in_not_found do |changeset| + "" + end + end + # ------------------------------------- # Test deleting elements. # ------------------------------------- @@ -910,6 +928,24 @@ module Api assert_equal "Precondition failed: Node #{node.id} is still used by ways #{way.id}.", @response.body end + def test_upload_delete_unknown_node_placeholder + check_upload_results_in_not_found do |changeset| + "" + end + end + + def test_upload_delete_unknown_way_placeholder + check_upload_results_in_not_found do |changeset| + "" + end + end + + def test_upload_delete_unknown_relation_placeholder + check_upload_results_in_not_found do |changeset| + "" + end + end + # ------------------------------------- # Test combined element changes. # ------------------------------------- @@ -1061,6 +1097,20 @@ module Api assert_equal 2, node.version assert_not node.visible end + + private + + def check_upload_results_in_not_found(&) + changeset = create(:changeset) + diff = "#{yield changeset}" + auth_header = bearer_authorization_header changeset.user + + post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header + + assert_response :not_found + changeset.reload + assert_equal 0, changeset.num_changes + end end end end diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index 5d6a48357..aecfa18ab 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -787,90 +787,6 @@ module Api assert_equal 0.3 * GeoRecord::SCALE, changeset.max_lat, "max_lat should be 0.3 degrees" end - def test_upload_not_found - changeset = create(:changeset) - - auth_header = bearer_authorization_header changeset.user - - # modify node - diff = <<~CHANGESET - - - - - - CHANGESET - - # upload it - post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header - assert_response :not_found, "Node should not be found" - - # modify way - diff = <<~CHANGESET - - - - - - CHANGESET - - # upload it - post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header - assert_response :not_found, "Way should not be found" - - # modify relation - diff = <<~CHANGESET - - - - - - CHANGESET - - # upload it - post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header - assert_response :not_found, "Relation should not be found" - - # delete node - diff = <<~CHANGESET - - - - - - CHANGESET - - # upload it - post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header - assert_response :not_found, "Node should not be deleted" - - # delete way - diff = <<~CHANGESET - - - - - - CHANGESET - - # upload it - post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header - assert_response :not_found, "Way should not be deleted" - - # delete relation - diff = <<~CHANGESET - - - - - - CHANGESET - - # upload it - post api_changeset_upload_path(changeset), :params => diff, :headers => auth_header - assert_response :not_found, "Relation should not be deleted" - end - ## # test initial rate limit def test_upload_initial_rate_limit -- 2.39.5