+ def test_comment_twice_success
+ open_note_with_comment = create(:note_with_comments)
+ user = create(:user)
+ auth_header = bearer_authorization_header 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(open_note_with_comment, :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 2, js["properties"]["comments"].count
+
+ subscription = NoteSubscription.last
+ assert_equal user, subscription.user
+ assert_equal open_note_with_comment, subscription.note
+
+ assert_difference "NoteComment.count", 1 do
+ assert_no_difference "NoteSubscription.count" do
+ assert_no_difference "ActionMailer::Base.deliveries.size" do
+ perform_enqueued_jobs do
+ post comment_api_note_path(open_note_with_comment, :text => "This is a second 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 3, js["properties"]["comments"].count
+ end
+