]> git.openstreetmap.org Git - rails.git/commitdiff
Test api old element index accessed as moderator
authorAnton Khorev <tony29@yandex.ru>
Sun, 9 Feb 2025 15:27:01 +0000 (18:27 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 10 Feb 2025 23:08:28 +0000 (02:08 +0300)
test/controllers/api/old_nodes_controller_test.rb
test/controllers/api/old_relations_controller_test.rb
test/controllers/api/old_ways_controller_test.rb

index 2dea49d4c55408c9977dbe82fc07d4f11f7ba03e..e24693a415e72712069bb71c0f582ba1f284dfc0 100644 (file)
@@ -86,6 +86,24 @@ module Api
                  "redacted node #{node.id} version 1 shouldn't be present in the history, even when logged in and passing flag."
     end
 
+    def test_index_redacted_moderator
+      node = create(:node, :with_history, :version => 2)
+      node.old_nodes.find_by(:version => 1).redact!(create(:redaction))
+      auth_header = bearer_authorization_header create(:moderator_user)
+
+      get api_node_versions_path(node), :headers => auth_header
+
+      assert_response :success, "Redaction shouldn't have stopped history working."
+      assert_dom "osm node[id='#{node.id}'][version='1']", 0,
+                 "node #{node.id} version 1 should not be present in the history for moderators when not passing flag."
+
+      get api_node_versions_path(node, :show_redactions => "true"), :headers => auth_header
+
+      assert_response :success, "Redaction shouldn't have stopped history working."
+      assert_dom "osm node[id='#{node.id}'][version='1']", 1,
+                 "node #{node.id} version 1 should still be present in the history for moderators when passing flag."
+    end
+
     def test_show
       node = create(:node, :version => 2)
       create(:old_node, :node_id => node.id, :version => 1, :latitude => 60 * OldNode::SCALE, :longitude => 30 * OldNode::SCALE)
@@ -238,16 +256,6 @@ module Api
       assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
       get api_node_version_path(node_v3.node_id, node_v3.version, :show_redactions => "true"), :headers => auth_header
       assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
-
-      # and when accessed via history
-      get api_node_versions_path(node)
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
-                    "node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag."
-      get api_node_versions_path(node, :show_redactions => "true"), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1,
-                    "node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag."
     end
 
     # testing that if the moderator drops auth, he can't see the
@@ -266,12 +274,6 @@ module Api
       # check can't see the redacted data
       get api_node_version_path(node_v3.node_id, node_v3.version), :headers => auth_header
       assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
-
-      # and when accessed via history
-      get api_node_versions_path(node), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0,
-                    "redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history."
     end
 
     ##
index 75fa5c77ac874dae373a6634793a43844fdc19c7..aac46ad6504744ecbe498a1ffea0834282ca24b4 100644 (file)
@@ -89,6 +89,24 @@ module Api
                  "redacted relation #{relation.id} version 1 shouldn't be present in the history, even when logged in and passing flag."
     end
 
+    def test_index_redacted_moderator
+      relation = create(:relation, :with_history, :version => 2)
+      relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
+      auth_header = bearer_authorization_header create(:moderator_user)
+
+      get api_relation_versions_path(relation), :headers => auth_header
+
+      assert_response :success, "Redaction shouldn't have stopped history working."
+      assert_dom "osm relation[id='#{relation.id}'][version='1']", 0,
+                 "relation #{relation.id} version 1 should not be present in the history for moderators when not passing flag."
+
+      get api_relation_versions_path(relation, :show_redactions => "true"), :headers => auth_header
+
+      assert_response :success, "Redaction shouldn't have stopped history working."
+      assert_dom "osm relation[id='#{relation.id}'][version='1']", 1,
+                 "relation #{relation.id} version 1 should still be present in the history for moderators when passing flag."
+    end
+
     def test_show
       relation = create(:relation, :with_history, :version => 2)
       create(:old_relation_tag, :old_relation => relation.old_relations[0], :k => "k1", :v => "v1")
@@ -225,16 +243,6 @@ module Api
       assert_response :forbidden, "After redaction, relation should be gone for moderator, when flag not passed."
       get api_relation_version_path(relation_v3.relation_id, relation_v3.version, :show_redactions => "true"), :headers => auth_header
       assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed."
-
-      # and when accessed via history
-      get api_relation_versions_path(relation), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
-                    "relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag."
-      get api_relation_versions_path(relation, :show_redactions => "true"), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1,
-                    "relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag."
     end
 
     # testing that if the moderator drops auth, he can't see the
@@ -254,12 +262,6 @@ module Api
       # check can't see the redacted data
       get api_relation_version_path(relation_v3.relation_id, relation_v3.version), :headers => auth_header
       assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
-
-      # and when accessed via history
-      get api_relation_versions_path(relation), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0,
-                    "redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history."
     end
 
     ##
index 9464b6232476b90c2c6f68a268270970a261ffe9..c365f329742a46937eefeabc1bc2230922b46afe 100644 (file)
@@ -96,6 +96,24 @@ module Api
                  "redacted node #{way.id} version 1 shouldn't be present in the history, even when logged in and passing flag."
     end
 
+    def test_index_redacted_moderator
+      way = create(:way, :with_history, :version => 2)
+      way.old_ways.find_by(:version => 1).redact!(create(:redaction))
+      auth_header = bearer_authorization_header create(:moderator_user)
+
+      get api_way_versions_path(way), :headers => auth_header
+
+      assert_response :success, "Redaction shouldn't have stopped history working."
+      assert_dom "osm way[id='#{way.id}'][version='1']", 0,
+                 "way #{way.id} version 1 should not be present in the history for moderators when not passing flag."
+
+      get api_way_versions_path(way, :show_redactions => "true"), :headers => auth_header
+
+      assert_response :success, "Redaction shouldn't have stopped history working."
+      assert_dom "osm way[id='#{way.id}'][version='1']", 1,
+                 "way #{way.id} version 1 should still be present in the history for moderators when passing flag."
+    end
+
     def test_show
       way = create(:way, :with_history, :version => 2)
 
@@ -233,16 +251,6 @@ module Api
       assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
       get api_way_version_path(way_v3.way_id, way_v3.version, :show_redactions => "true"), :headers => auth_header
       assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
-
-      # and when accessed via history
-      get api_way_versions_path(way), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
-                    "way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag."
-      get api_way_versions_path(way, :show_redactions => "true"), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1,
-                    "way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag."
     end
 
     # testing that if the moderator drops auth, he can't see the
@@ -261,12 +269,6 @@ module Api
       # check can't see the redacted data
       get api_way_version_path(way_v3.way_id, way_v3.version), :headers => auth_header
       assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
-
-      # and when accessed via history
-      get api_way_versions_path(way), :headers => auth_header
-      assert_response :success, "Redaction shouldn't have stopped history working."
-      assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0,
-                    "redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history."
     end
 
     ##