]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/api/changeset_comments/visibilities_controller_test.rb
Test api changeset comment hide/unhide at legacy routes
[rails.git] / test / controllers / api / changeset_comments / visibilities_controller_test.rb
index e5a9dbd8310f5f3f780ad62c863611b1650f5302..1e8b562de9e42f162335c074c9959b2a3b607d48 100644 (file)
@@ -93,14 +93,7 @@ module Api
 
         post api_changeset_comment_visibility_path(comment, :format => "json"), :headers => auth_header
 
-        assert_response :success
-        assert_equal "application/json", response.media_type
-        js = ActiveSupport::JSON.decode(@response.body)
-        assert_not_nil js["changeset"]
-        assert_equal comment.changeset_id, js["changeset"]["id"]
-        assert_equal 1, js["changeset"]["comments_count"]
-
-        assert comment.reload.visible
+        check_successful_response_json(comment, :comment_visible => true)
       end
 
       def test_create_with_write_api_scope
@@ -118,14 +111,25 @@ module Api
 
         post api_changeset_comment_visibility_path(comment, :format => "json"), :headers => auth_header
 
-        assert_response :success
-        js = ActiveSupport::JSON.decode(@response.body)
-        assert_equal "application/json", response.media_type
-        assert_not_nil js["changeset"]
-        assert_equal comment.changeset_id, js["changeset"]["id"]
-        assert_equal 1, js["changeset"]["comments_count"]
+        check_successful_response_json(comment, :comment_visible => true)
+      end
 
-        assert comment.reload.visible
+      def test_create_at_legacy_route
+        comment = create(:changeset_comment, :visible => false)
+        auth_header = bearer_authorization_header create(:moderator_user), :scopes => %w[write_api]
+
+        post "/api/0.6/changeset/comment/#{comment.id}/unhide", :headers => auth_header
+
+        check_successful_response_xml(comment, :comment_visible => true)
+      end
+
+      def test_create_at_legacy_route_json
+        comment = create(:changeset_comment, :visible => false)
+        auth_header = bearer_authorization_header create(:moderator_user), :scopes => %w[write_api]
+
+        post "/api/0.6/changeset/comment/#{comment.id}/unhide.json", :headers => auth_header
+
+        check_successful_response_json(comment, :comment_visible => true)
       end
 
       def test_destroy_by_unauthorized
@@ -180,14 +184,7 @@ module Api
 
         delete api_changeset_comment_visibility_path(comment, :format => "json"), :headers => auth_header
 
-        assert_response :success
-        assert_equal "application/json", response.media_type
-        js = ActiveSupport::JSON.decode(@response.body)
-        assert_not_nil js["changeset"]
-        assert_equal comment.changeset_id, js["changeset"]["id"]
-        assert_equal 0, js["changeset"]["comments_count"]
-
-        assert_not comment.reload.visible
+        check_successful_response_json(comment, :comment_visible => false)
       end
 
       def test_destroy_with_write_api_scope
@@ -205,14 +202,25 @@ module Api
 
         delete api_changeset_comment_visibility_path(comment, :format => "json"), :headers => auth_header
 
-        assert_response :success
-        assert_equal "application/json", response.media_type
-        js = ActiveSupport::JSON.decode(@response.body)
-        assert_not_nil js["changeset"]
-        assert_equal comment.changeset_id, js["changeset"]["id"]
-        assert_equal 0, js["changeset"]["comments_count"]
+        check_successful_response_json(comment, :comment_visible => false)
+      end
 
-        assert_not comment.reload.visible
+      def test_destroy_at_legacy_route
+        comment = create(:changeset_comment)
+        auth_header = bearer_authorization_header create(:moderator_user), :scopes => %w[write_api]
+
+        post "/api/0.6/changeset/comment/#{comment.id}/hide", :headers => auth_header
+
+        check_successful_response_xml(comment, :comment_visible => false)
+      end
+
+      def test_destroy_at_legacy_route_json
+        comment = create(:changeset_comment)
+        auth_header = bearer_authorization_header create(:moderator_user), :scopes => %w[write_api]
+
+        post "/api/0.6/changeset/comment/#{comment.id}/hide.json", :headers => auth_header
+
+        check_successful_response_json(comment, :comment_visible => false)
       end
 
       private
@@ -229,6 +237,17 @@ module Api
 
         assert_equal comment_visible, comment.reload.visible
       end
+
+      def check_successful_response_json(comment, comment_visible:)
+        assert_response :success
+        assert_equal "application/json", response.media_type
+        js = ActiveSupport::JSON.decode(@response.body)
+        assert_not_nil js["changeset"]
+        assert_equal comment.changeset_id, js["changeset"]["id"]
+        assert_equal comment_visible ? 1 : 0, js["changeset"]["comments_count"]
+
+        assert_equal comment_visible, comment.reload.visible
+      end
     end
   end
 end