<commit_before>require_relative 'test_helper'

class ServerResponderTest < AppTest

  def test_root
    get '/'
    assert_match 'Server Responder', last_response.body
  end

  def test_last_job
    get '/last_job'
    assert_match 'last_time', last_response.body
  end

  def test_post_with_bad_api_key_env
    post '/', script_payload.merge(:api_token => 'different_server_key')
    assert_equal "bad api key", last_response.body
  end
  
  def test_process_github_hook_commit__success
    fake_project = {}
    fake_project.expects(:process_github_hook).once
    Project.stubs(:new).returns(fake_project)
    post '/', github_payload.merge('api_token' => ENV['SERVER_RESPONDER_API_KEY'])
  end

  def test_script_payload__success
    app.any_instance.expects(:write_file).with(anything,"9\n").once
    app.any_instance.expects(:reset_artifacts_directory).once
    app.any_instance.expects(:upload_files).once
    File.stubs(:open)
    post '/', script_payload, 'api_token' => ENV['SERVER_RESPONDER_API_KEY']
  end

  def test_authorized_client__token
    app.stubs(:params).returns({'api_token' => ENV['SERVER_RESPONDER_API_KEY']})
    assert_equal true, app.authorized_client?
  end

  def test_authorized_client__signature
    app.stubs(:code_signature).returns('sig')
    app.stubs(:params).returns({'signature' => 'sig', 'payload' => {'script_payload' => 'script'}.to_json})
    assert_equal true, app.authorized_client?
  end

end
<commit_msg>improve coverage<commit_after>require_relative 'test_helper'

class ServerResponderTest < AppTest

  def test_root
    get '/'
    assert_match 'Server Responder', last_response.body
  end

  def test_last_job
    get '/last_job'
    assert_match 'last_time', last_response.body
  end

  def test_post_with_bad_api_key_env
    post '/', script_payload.merge(:api_token => '<PASSWORD>server_key')
    assert_equal "bad api key", last_response.body
  end
  
  def test_process_github_hook_commit__success
    fake_project = {}
    fake_project.expects(:process_github_hook).once
    Project.stubs(:new).returns(fake_project)
    post '/', github_payload.merge('api_token' => ENV['SERVER_RESPONDER_API_KEY'])
  end

  def test_script_payload__success
    app.any_instance.expects(:write_file).with(anything,"9\n").once
    app.any_instance.expects(:reset_artifacts_directory).once
    app.any_instance.expects(:upload_files).once
    File.stubs(:open)
    post '/', script_payload, 'api_token' => ENV['SERVER_RESPONDER_API_KEY']
  end

  def test_authorized_client__token
    app.stubs(:params).returns({'api_token' => ENV['SERVER_RESPONDER_API_KEY']})
    assert_equal true, app.authorized_client?
  end

  def test_authorized_client__signature
    app.stubs(:code_signature).returns('sig')
    app.stubs(:params).returns({'signature' => 'sig', 'payload' => {'script_payload' => 'script'}.to_json})
    assert_equal true, app.authorized_client?
  end

  def test_default_local_location__nothing_set
    assert_equal "/opt/bitnami/apps/projects/", app.default_local_location
  end
  
  def test_default_local_location__env_set
    previous_setting = ENV['LOCAL_REPOS']
    begin
      ENV['LOCAL_REPOS'] = 'test'
      assert_equal "test", app.default_local_location
    ensure
      ENV['LOCAL_REPOS'] = previous_setting
    end
  end

end

{'fraction_non_alphanumeric': 0.11249619945272119, 'fraction_numerical': 0.0006080875646093037, 'mean_word_length': 4.823008849557522, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '6620376', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1088, 'n_words': 168}