]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/api/notes_controller_test.rb
Move common query time condition to mixin
[rails.git] / test / controllers / api / notes_controller_test.rb
index 5f69e6a2ac025e9eadf11a85795d040c349202c6..a2c9dc8a4fd8f917b7e43d97b8014ed0cf5c4826 100644 (file)
@@ -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)
@@ -1057,6 +1068,29 @@ module Api
       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
       notes = Array.new(5) do |i|
         position = ((1.0 + (i * 0.1)) * GeoRecord::SCALE).to_i