<commit_before>require 'test_helper'

class NotificationsControllerTest < ActionController::TestCase
  include Devise::TestHelpers

  test "should get index as JSON" do
    sign_in users(:standard_user)
    get :index, :format => :json
    assert_not_nil assigns(:notifications)
    assert_response(200)
  end

  test "should mark notification as read" do
    sign_in users(:standard_user)
    post :read, :id => notifications(:one).id, :format => :json
    assert_not_nil assigns(:notification)
    assert_equal true, assigns(:notification).is_read
    assert_equal 'success', JSON.parse(response.body)['status']
    assert_response(200)
  end

  test "should mark all notifications as read" do
    sign_in users(:standard_user)
    post :read_all, :format => :json
    assert_not_nil assigns(:notifications)
    assigns(:notifications).each do |notification|
      assert_equal true, notification.is_read
    end
    assert_equal 'success', JSON.parse(response.body)['status']
    assert_response(200)
  end

  test "should prevent users marking others notifications read" do
    sign_in users(:editor)
    post :read, :id => notifications(:one).id, :format => :json
    assert_response(401)
  end

  test "should require authentication to get index" do
    sign_out :user
    get :index, :format => :json
    assert_response(302)<commit_msg>fix response code<commit_after>require 'test_helper'

class NotificationsControllerTest < ActionController::TestCase
  include Devise::TestHelpers

  test "should get index as JSON" do
    sign_in users(:standard_user)
    get :index, :format => :json
    assert_not_nil assigns(:notifications)
    assert_response(200)
  end

  test "should mark notification as read" do
    sign_in users(:standard_user)
    post :read, :id => notifications(:one).id, :format => :json
    assert_not_nil assigns(:notification)
    assert_equal true, assigns(:notification).is_read
    assert_equal 'success', JSON.parse(response.body)['status']
    assert_response(200)
  end

  test "should mark all notifications as read" do
    sign_in users(:standard_user)
    post :read_all, :format => :json
    assert_not_nil assigns(:notifications)
    assigns(:notifications).each do |notification|
      assert_equal true, notification.is_read
    end
    assert_equal 'success', JSON.parse(response.body)['status']
    assert_response(200)
  end

  test "should prevent users marking others notifications read" do
    sign_in users(:editor)
    post :read, :id => notifications(:one).id, :format => :json
    assert_response(401)
  end

  test "should require authentication to get index" do
    sign_out :user
    get :index, :format => :json
    assert_response(401)  # Devise seems to respond 401 for JSON requests.
{'fraction_non_alphanumeric': 0.09773887673231219, 'fraction_numerical': 0.012035010940919038, 'mean_word_length': 4.315891472868217, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5444761', 'n_tokens_mistral': 834, 'n_tokens_neox': 783, 'n_words': 231}