<commit_before>require 'test_helper'

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

  test "shouldn't allow unauthenticated users to write" do
    sign_out(:users)
    put :create_feedback, :id => 23653, :type => 'tpu-', :key => api_keys(:one).key
    json = JSON.parse(@response.body)
    assert_response(401)
    assert_equal 401, json['error_code']
    assert_equal 'unauthorized', json['error_name']
  end

  test "should return created and post feedback" do
    sign_in users(:admin_user)
    put :create_feedback, :id => 23653, :type => 'tpu-', :key => api_keys(:one).key
    assert_nothing_raised JSON::ParserError do
      JSON.parse(@response.body)
    end
    assert_response(201)
  end

  test "should associate feedback with API key" do
    sign_in users(:admin_user)

    assert_difference ApiKey.find(api_keys(:one).id).feedbacks do
      put :create_feedback, :id => 23653, :type => 'tpu-', :key => api_keys(:one).key
      assert_nothing_raised JSON::ParserError do
        JSON.parse(@response.body)
      end
      assert_response(201)
    end
  end
end<commit_msg>That's a post route now<commit_after>require 'test_helper'

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

  test "shouldn't allow unauthenticated users to write" do
    sign_out(:users)
    put :create_feedback, :id => 23653, :type => 'tpu-', :key => api_keys(:one).key
    json = JSON.parse(@response.body)
    assert_response(401)
    assert_equal 401, json['error_code']
    assert_equal 'unauthorized', json['error_name']
  end

  test "should return created and post feedback" do
    sign_in users(:admin_user)
    put :create_feedback, :id => 23653, :type => 'tpu-', :key => api_keys(:one).key
    assert_nothing_raised JSON::ParserError do
      JSON.parse(@response.body)
    end
    assert_response(201)
  end

  test "should associate feedback with API key" do
    sign_in users(:admin_user)

    assert_difference ApiKey.find(api_keys(:one).id).feedbacks do
      post :create_feedback, :id => 23653, :type => 'tpu-', :key => api_keys(:one).key
      assert_nothing_raised JSON::ParserError do
        JSON.parse(@response.body)
      end
      assert_response(201)
    end
  end
end
{'fraction_non_alphanumeric': 0.11762094984465157, 'fraction_numerical': 0.023968042609853527, 'mean_word_length': 3.9106753812636166, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '5094314', 'n_tokens_mistral': 773, 'n_tokens_neox': 707, 'n_words': 181}