<commit_before>require "helper"
require "rack/test"

class PinglishTest < MiniTest::Unit::TestCase
  include Rack::Test::Methods

  FakeApp = lambda { |env| [404, {}, []] }

  def app
    Rack::Builder.new do |builder|
      builder.use Pinglish
      builder.run FakeApp
    end
  end

  def test_default_path_and_status
    get '/_ping'
    assert_equal 200, last_response.status
  end

  def test_customizing_path
    app = Rack::Builder.new do |builder|
      builder.use Pinglish, "/_piiiiing"<commit_msg>Added test for json response.<commit_after>require "helper"
require "rack/test"

class PinglishTest < MiniTest::Unit::TestCase
  include Rack::Test::Methods

  FakeApp = lambda { |env| [404, {}, []] }

  def app
    Rack::Builder.new do |builder|
      builder.use Pinglish
      builder.run FakeApp
    end
  end

  def test_default_path_and_status
    get '/_ping'
    assert_equal 200, last_response.status
  end

  def test_json_response
    get '/_ping'
    json = JSON.load(last_response.body)

    assert_in_delta Time.now.to_i, json['now'].to_i, 2
    assert_equal 'ok', json['status']
  end

  def test_customizing_path
    app = Rack::Builder.new do |builder|
      builder.use Pinglish, "/_piiiiing"
{'fraction_non_alphanumeric': 0.10737704918032787, 'fraction_numerical': 0.010655737704918032, 'mean_word_length': 3.44, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '882120', 'n_tokens_mistral': 436, 'n_tokens_neox': 410, 'n_words': 99}