]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/api/notes_controller_test.rb
add lock, information and water classes for nominatim terms
[rails.git] / test / controllers / api / notes_controller_test.rb
index f814d8c6e6424c13ec0788a5d5f4e170d6ca3da3..5f69e6a2ac025e9eadf11a85795d040c349202c6 100644 (file)
@@ -271,6 +271,58 @@ module Api
       assert_equal user.display_name, js["properties"]["comments"].last["user"]
     end
 
       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)
     def test_comment_with_notifications_success
       # Ensure that emails are sent to users
       first_user = create(:user)
@@ -281,6 +333,8 @@ module Api
         create(:note_comment, :note => note, :author => first_user)
         create(:note_comment, :note => note, :author => second_user)
       end
         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
 
 
       auth_header = bearer_authorization_header third_user