]> git.openstreetmap.org Git - rails.git/commitdiff
Test if api relation show/full responses contain required elements
authorAnton Khorev <tony29@yandex.ru>
Sat, 1 Feb 2025 12:35:29 +0000 (15:35 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 5 Feb 2025 17:22:16 +0000 (20:22 +0300)
test/controllers/api/relations_controller_test.rb

index 040062153013d2167ce8f1296a11787df9f5d0d7..ad7ce11b0f9fc74766870b0745728d5bef603de8 100644 (file)
@@ -133,8 +133,17 @@ module Api
     end
 
     def test_show
-      get api_relation_path(create(:relation))
+      relation = create(:relation)
+      node = create(:node)
+      create(:relation_member, :relation => relation, :member => node)
+
+      get api_relation_path(relation)
+
       assert_response :success
+      assert_dom "node", :count => 0
+      assert_dom "relation", :count => 1 do
+        assert_dom "> @id", :text => relation.id.to_s
+      end
     end
 
     def test_full_not_found
@@ -148,9 +157,49 @@ module Api
     end
 
     def test_full_empty
-      get relation_full_path(create(:relation))
+      relation = create(:relation)
+
+      get relation_full_path(relation)
+
+      assert_response :success
+      assert_dom "relation", :count => 1 do
+        assert_dom "> @id", :text => relation.id.to_s
+      end
+    end
+
+    def test_full_with_node_member
+      relation = create(:relation)
+      node = create(:node)
+      create(:relation_member, :relation => relation, :member => node)
+
+      get relation_full_path(relation)
+
+      assert_response :success
+      assert_dom "node", :count => 1 do
+        assert_dom "> @id", :text => node.id.to_s
+      end
+      assert_dom "relation", :count => 1 do
+        assert_dom "> @id", :text => relation.id.to_s
+      end
+    end
+
+    def test_full_with_way_member
+      relation = create(:relation)
+      way = create(:way_with_nodes)
+      create(:relation_member, :relation => relation, :member => way)
+
+      get relation_full_path(relation)
+
       assert_response :success
-      # FIXME: check whether this contains the stuff we want!
+      assert_dom "node", :count => 1 do
+        assert_dom "> @id", :text => way.nodes[0].id.to_s
+      end
+      assert_dom "way", :count => 1 do
+        assert_dom "> @id", :text => way.id.to_s
+      end
+      assert_dom "relation", :count => 1 do
+        assert_dom "> @id", :text => relation.id.to_s
+      end
     end
 
     ##