X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/dbb462ca0ff432c94c00911340ab4c7619504844..47d55a2b0f6057cb96b2bd4c98748f87365d8d02:/test/controllers/api/notes_controller_test.rb diff --git a/test/controllers/api/notes_controller_test.rb b/test/controllers/api/notes_controller_test.rb index f814d8c6e..17ceb1b9e 100644 --- a/test/controllers/api/notes_controller_test.rb +++ b/test/controllers/api/notes_controller_test.rb @@ -230,6 +230,17 @@ module Api assert_equal note, subscription.note end + def test_create_no_scope_fail + user = create(:user) + auth_header = bearer_authorization_header user, :scopes => %w[read_prefs] + + assert_no_difference "Note.count" do + post api_notes_path(:lat => -1.0, :lon => -1.0, :text => "This is a description", :format => "json"), :headers => auth_header + + assert_response :forbidden + end + end + def test_comment_success open_note_with_comment = create(:note_with_comments) user = create(:user) @@ -271,6 +282,58 @@ module Api assert_equal user.display_name, js["properties"]["comments"].last["user"] end + def test_comment_without_notifications_success + # Ensure that emails are sent to users + first_user = create(:user) + second_user = create(:user) + third_user = create(:user) + + note_with_comments_by_users = create(:note) do |note| + create(:note_comment, :note => note, :author => first_user) + create(:note_comment, :note => note, :author => second_user) + end + + auth_header = bearer_authorization_header third_user + + assert_difference "NoteComment.count", 1 do + assert_difference "NoteSubscription.count", 1 do + assert_no_difference "ActionMailer::Base.deliveries.size" do + perform_enqueued_jobs do + post comment_api_note_path(note_with_comments_by_users, :text => "This is an additional comment", :format => "json"), :headers => auth_header + end + end + end + end + assert_response :success + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal "Feature", js["type"] + assert_equal note_with_comments_by_users.id, js["properties"]["id"] + assert_equal "open", js["properties"]["status"] + assert_equal 3, js["properties"]["comments"].count + assert_equal "commented", js["properties"]["comments"].last["action"] + assert_equal "This is an additional comment", js["properties"]["comments"].last["text"] + assert_equal third_user.display_name, js["properties"]["comments"].last["user"] + + subscription = NoteSubscription.last + assert_equal third_user, subscription.user + assert_equal note_with_comments_by_users, subscription.note + + get api_note_path(note_with_comments_by_users, :format => "json") + assert_response :success + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal "Feature", js["type"] + assert_equal note_with_comments_by_users.id, js["properties"]["id"] + assert_equal "open", js["properties"]["status"] + assert_equal 3, js["properties"]["comments"].count + assert_equal "commented", js["properties"]["comments"].last["action"] + assert_equal "This is an additional comment", js["properties"]["comments"].last["text"] + assert_equal third_user.display_name, js["properties"]["comments"].last["user"] + + ActionMailer::Base.deliveries.clear + end + def test_comment_with_notifications_success # Ensure that emails are sent to users first_user = create(:user) @@ -281,6 +344,8 @@ module Api create(:note_comment, :note => note, :author => first_user) create(:note_comment, :note => note, :author => second_user) end + create(:note_subscription, :note => note_with_comments_by_users, :user => first_user) + create(:note_subscription, :note => note_with_comments_by_users, :user => second_user) auth_header = bearer_authorization_header third_user