X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/8c0f5752809f7a21aa62babc05f35a8f881d2141..9929c1b585bd0e0b088cc785af06720d46f2dcce:/test/controllers/api/notes_controller_test.rb?ds=sidebyside diff --git a/test/controllers/api/notes_controller_test.rb b/test/controllers/api/notes_controller_test.rb index 5f69e6a2a..c0c67fc91 100644 --- a/test/controllers/api/notes_controller_test.rb +++ b/test/controllers/api/notes_controller_test.rb @@ -230,6 +230,17 @@ module Api assert_equal note, subscription.note end + def test_create_no_scope_fail + user = create(:user) + auth_header = bearer_authorization_header user, :scopes => %w[read_prefs] + + assert_no_difference "Note.count" do + post api_notes_path(:lat => -1.0, :lon => -1.0, :text => "This is a description", :format => "json"), :headers => auth_header + + assert_response :forbidden + end + end + def test_comment_success open_note_with_comment = create(:note_with_comments) user = create(:user) @@ -319,8 +330,6 @@ module Api assert_equal "commented", js["properties"]["comments"].last["action"] assert_equal "This is an additional comment", js["properties"]["comments"].last["text"] assert_equal third_user.display_name, js["properties"]["comments"].last["user"] - - ActionMailer::Base.deliveries.clear end def test_comment_with_notifications_success @@ -384,8 +393,6 @@ module Api assert_equal "commented", js["properties"]["comments"].last["action"] assert_equal "This is an additional comment", js["properties"]["comments"].last["text"] assert_equal third_user.display_name, js["properties"]["comments"].last["user"] - - ActionMailer::Base.deliveries.clear end def test_comment_twice_success @@ -1055,6 +1062,37 @@ module Api assert_select "gpx", :count => 1 do assert_select "wpt", :count => 1 end + + user2 = create(:user) + get search_api_notes_path(:user => user2.id, :format => "xml") + assert_response :success + assert_equal "application/xml", @response.media_type + assert_select "osm", :count => 1 do + assert_select "note", :count => 0 + end + end + + def test_search_by_time_success + note1 = create(:note, :created_at => "2020-02-01T00:00:00Z", :updated_at => "2020-04-01T00:00:00Z") + note2 = create(:note, :created_at => "2020-03-01T00:00:00Z", :updated_at => "2020-05-01T00:00:00Z") + + get search_api_notes_path(:from => "2020-02-15T00:00:00Z", :to => "2020-04-15T00:00:00Z", :format => "xml") + assert_response :success + assert_equal "application/xml", @response.media_type + assert_select "osm", :count => 1 do + assert_select "note", :count => 1 do + assert_select "id", note2.id.to_s + end + end + + get search_api_notes_path(:from => "2020-02-15T00:00:00Z", :to => "2020-04-15T00:00:00Z", :sort => "updated_at", :format => "xml") + assert_response :success + assert_equal "application/xml", @response.media_type + assert_select "osm", :count => 1 do + assert_select "note", :count => 1 do + assert_select "id", note1.id.to_s + end + end end def test_search_by_bbox_success