X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/edd12c6995aa5f8ef5d6c8d898e42d1a5931430f..5bb23f6f5f8fed81f1166a15344e44afa7fbb480:/test/controllers/api/note_subscriptions_controller_test.rb?ds=inline diff --git a/test/controllers/api/note_subscriptions_controller_test.rb b/test/controllers/api/note_subscriptions_controller_test.rb index 45aa33ad1..0e388697c 100644 --- a/test/controllers/api/note_subscriptions_controller_test.rb +++ b/test/controllers/api/note_subscriptions_controller_test.rb @@ -7,6 +7,10 @@ module Api { :path => "/api/0.6/notes/1/subscription", :method => :post }, { :controller => "api/note_subscriptions", :action => "create", :note_id => "1" } ) + assert_routing( + { :path => "/api/0.6/notes/1/subscription", :method => :delete }, + { :controller => "api/note_subscriptions", :action => "destroy", :note_id => "1" } + ) end def test_create @@ -73,5 +77,66 @@ module Api end assert_match "already subscribed", @response.body end + + def test_destroy + user = create(:user) + auth_header = bearer_authorization_header user + other_user = create(:user) + note = create(:note_with_comments) + other_note = create(:note_with_comments) + create(:note_subscription, :user => user, :note => note) + create(:note_subscription, :user => other_user, :note => note) + create(:note_subscription, :user => user, :note => other_note) + + assert_difference "NoteSubscription.count", -1 do + assert_difference "note.subscribers.count", -1 do + delete api_note_subscription_path(note), :headers => auth_header + assert_response :success + end + end + note.reload + assert_equal [other_user], note.subscribers + assert_equal [user], other_note.subscribers + end + + def test_destroy_fail_anonymous + note = create(:note_with_comments) + + delete api_note_subscription_path(note) + assert_response :unauthorized + end + + def test_destroy_fail_no_scope + user = create(:user) + auth_header = bearer_authorization_header user, :scopes => %w[read_prefs] + note = create(:note_with_comments) + create(:note_subscription, :user => user, :note => note) + + assert_no_difference "NoteSubscription.count" do + assert_no_difference "note.subscribers.count" do + delete api_note_subscription_path(note), :headers => auth_header + assert_response :forbidden + end + end + end + + def test_destroy_fail_note_not_found + user = create(:user) + auth_header = bearer_authorization_header user + + delete api_note_subscription_path(999111), :headers => auth_header + assert_response :not_found + assert_match "not found", @response.body + end + + def test_destroy_fail_not_subscribed + user = create(:user) + auth_header = bearer_authorization_header user + note = create(:note_with_comments) + + delete api_note_subscription_path(note), :headers => auth_header + assert_response :not_found + assert_match "not subscribed", @response.body + end end end