From dc3c5aa783cb01ea72f2d8432ce91cc082f254b9 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 5 Jul 2025 02:42:15 +0300 Subject: [PATCH] Split create node with invalid payload tests --- test/controllers/api/nodes_controller_test.rb | 102 ++++++++++-------- 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/test/controllers/api/nodes_controller_test.rb b/test/controllers/api/nodes_controller_test.rb index 2c5237195..393be7d57 100644 --- a/test/controllers/api/nodes_controller_test.rb +++ b/test/controllers/api/nodes_controller_test.rb @@ -132,60 +132,70 @@ module Api end end - def test_create_invalid_xml - ## Only test public user here, as test_create should cover what's the forbidden - ## that would occur here + def test_create_with_invalid_osm_structure + with_unchanging_request do |headers| + osm = "" - user = create(:user) - changeset = create(:changeset, :user => user) + post api_nodes_path, :params => osm, :headers => headers - auth_header = bearer_authorization_header user - lat = 3.434 - lon = 3.23 + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal "Cannot parse valid node from xml string . XML doesn't contain an osm/node element.", @response.body + end + end - # test that the upload is rejected when xml is valid, but osm doc isn't - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - assert_response :bad_request, "node upload did not return bad_request status" - assert_equal "Cannot parse valid node from xml string . XML doesn't contain an osm/node element.", @response.body + def test_create_without_lat + with_unchanging_request do |headers, changeset| + osm = "" - # test that the upload is rejected when no lat is supplied - # create a minimal xml file - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - # hope for success - assert_response :bad_request, "node upload did not return bad_request status" - assert_equal "Cannot parse valid node from xml string . lat missing", @response.body + post api_nodes_path, :params => osm, :headers => headers - # test that the upload is rejected when no lon is supplied - # create a minimal xml file - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - # hope for success - assert_response :bad_request, "node upload did not return bad_request status" - assert_equal "Cannot parse valid node from xml string . lon missing", @response.body + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal "Cannot parse valid node from xml string . lat missing", @response.body + end + end - # test that the upload is rejected when lat is non-numeric - # create a minimal xml file - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - # hope for success - assert_response :bad_request, "node upload did not return bad_request status" - assert_equal "Cannot parse valid node from xml string . lat not a number", @response.body + def test_create_without_lon + with_unchanging_request do |headers, changeset| + osm = "" - # test that the upload is rejected when lon is non-numeric - # create a minimal xml file - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - # hope for success - assert_response :bad_request, "node upload did not return bad_request status" - assert_equal "Cannot parse valid node from xml string . lon not a number", @response.body + post api_nodes_path, :params => osm, :headers => headers - # test that the upload is rejected when we have a tag which is too long - xml = "" - post api_nodes_path, :params => xml, :headers => auth_header - assert_response :bad_request, "node upload did not return bad_request status" - assert_match(/ v: is too long \(maximum is 255 characters\) /, @response.body) + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal "Cannot parse valid node from xml string . lon missing", @response.body + end + end + + def test_create_with_non_numeric_lat + with_unchanging_request do |headers, changeset| + osm = "" + + post api_nodes_path, :params => osm, :headers => headers + + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal "Cannot parse valid node from xml string . lat not a number", @response.body + end + end + + def test_create_with_non_numeric_lon + with_unchanging_request do |headers, changeset| + osm = "" + + post api_nodes_path, :params => osm, :headers => headers + + assert_response :bad_request, "node upload did not return bad_request status" + assert_equal "Cannot parse valid node from xml string . lon not a number", @response.body + end + end + + def test_create_with_tag_too_long + with_unchanging_request do |headers, changeset| + osm = "" + + post api_nodes_path, :params => osm, :headers => headers + + assert_response :bad_request, "node upload did not return bad_request status" + assert_match(/ v: is too long \(maximum is 255 characters\) /, @response.body) + end end def test_show_not_found -- 2.39.5