]> git.openstreetmap.org Git - rails.git/commitdiff
Test legacy api changeset subscribe/unsubscribe paths
authorAnton Khorev <tony29@yandex.ru>
Thu, 13 Mar 2025 14:25:36 +0000 (17:25 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 14 Mar 2025 17:09:55 +0000 (20:09 +0300)
test/controllers/api/changeset_subscriptions_controller_test.rb

index bbf9d8dc8ae0533356dbf3bd9f0cef302d8d2e9e..e0d4ca66965944433d9f1cbbab219b0809cecf0a 100644 (file)
@@ -21,6 +21,23 @@ module Api
         { :path => "/api/0.6/changeset/1/subscription.json", :method => :delete },
         { :controller => "api/changeset_subscriptions", :action => "destroy", :changeset_id => "1", :format => "json" }
       )
+
+      assert_recognizes(
+        { :controller => "api/changeset_subscriptions", :action => "create", :changeset_id => "1" },
+        { :path => "/api/0.6/changeset/1/subscribe", :method => :post }
+      )
+      assert_recognizes(
+        { :controller => "api/changeset_subscriptions", :action => "create", :changeset_id => "1", :format => "json" },
+        { :path => "/api/0.6/changeset/1/subscribe.json", :method => :post }
+      )
+      assert_recognizes(
+        { :controller => "api/changeset_subscriptions", :action => "destroy", :changeset_id => "1" },
+        { :path => "/api/0.6/changeset/1/unsubscribe", :method => :post }
+      )
+      assert_recognizes(
+        { :controller => "api/changeset_subscriptions", :action => "destroy", :changeset_id => "1", :format => "json" },
+        { :path => "/api/0.6/changeset/1/unsubscribe.json", :method => :post }
+      )
     end
 
     def test_create_by_unauthorized
@@ -89,6 +106,20 @@ module Api
       end
     end
 
+    def test_create_legacy
+      user = create(:user)
+      auth_header = bearer_authorization_header user
+      changeset = create(:changeset, :closed)
+
+      assert_difference "ChangesetSubscription.count", 1 do
+        assert_difference "changeset.subscribers.count", 1 do
+          post "/api/0.6/changeset/#{changeset.id}/subscribe", :headers => auth_header
+
+          assert_response :success
+        end
+      end
+    end
+
     def test_destroy_by_unauthorized
       changeset = create(:changeset, :closed)
 
@@ -155,5 +186,20 @@ module Api
         end
       end
     end
+
+    def test_destroy_legacy
+      user = create(:user)
+      auth_header = bearer_authorization_header user
+      changeset = create(:changeset, :closed)
+      changeset.subscribers.push(user)
+
+      assert_difference "ChangesetSubscription.count", -1 do
+        assert_difference "changeset.subscribers.count", -1 do
+          post "/api/0.6/changeset/#{changeset.id}/unsubscribe", :headers => auth_header
+
+          assert_response :success
+        end
+      end
+    end
   end
 end