<commit_before>require 'test_helper'

class ApplicationTest < ActionDispatch::IntegrationTest
	Rails.backtrace_cleaner.remove_silencers!

	# load every fixture into an array 
  @jsons = []
  @parsed_jsons = []
  @curls = []
  @parsed_curls = []
  Dir.glob(Rails.root.to_s + '/test/fixtures/*.json') do |file|
    puts 'loading ' + file
    @jsons << File.read(file).to_s
    @parsed_jsons << JSON.parse(File.read(file))
    curl = Curl::Easy.http_post('http://localhost:3000/determinations/eval.json', File.read(file)) do |c|
      c.headers['Content-Type'] = 'application/json;charset=UTF-8'
      c.headers['Accept'] = 'application/json'
    end
    @curls << curl.body_str
    @parsed_curls << JSON.parse(curl.body_str)
  end

	def setup
		@json = JSON.parse(File.read(Rails.root.to_s + '/test/fixtures/4_person_family.json'))
	end

  @curls.each do |curl|
    @i = @i + 1 || 1
    test "the response should contain major fields like determination date and applicants #{@i}" do
    	# determination date is present 
    	assert_match /Determination Date/, curl
    	# determination date is set to today
    	assert_match Time.now.strftime('%Y-%m-%d'), curl
      # has applicants in it
      assert_match /Applicants/, curl
    end
  end

  # @@curl_parsed.
  # test 'the response should contain the correct number of applicants' do 
  	# the return string has 'applicants'
  	# assert_match /Applicants/, @@curl
  	# there are an equal number of people on application and applicants with decision
  	# assert_equal @json['People'].count, @@curl_parsed['Applicants'].count
  # end

  # test 'the response should contain a yes or no determination for medicaid and CHIP' do
  	# @@curl_parsed['Applicants'].each do |applicant|
  		# check for yes-no on medicaid for each applicant
  		# assert ["Y","N"].include? applicant['Medicaid Eligible']
  		# check for yes-no on chip for each applicant
  		# assert ["Y","N"].include? applicant['CHIP Eligible']
  	# end
  # end
end<commit_msg>refactor app tests into a loop, so the texts run for each app fixture<commit_after>require 'test_helper'

class ApplicationTest < ActionDispatch::IntegrationTest
	Rails.backtrace_cleaner.remove_silencers!

	# load every fixture into an array 
  @fixtures = []

  Dir.glob(Rails.root.to_s + '/test/fixtures/*.json') do |file|
    puts 'loading ' + file
    json = File.read(file).to_s
    parsed_json = JSON.parse(File.read(file))
    curl = Curl::Easy.http_post('http://localhost:3000/determinations/eval.json', File.read(file)) do |c|
      c.headers['Content-Type'] = 'application/json;charset=UTF-8'
      c.headers['Accept'] = 'application/json'
    end
    curl = curl.body_str
    parsed_curl = JSON.parse(curl)
    @fixtures << {name: file.gsub(/\.json/,'').gsub(/#{Rails.root.to_s}\/test\/fixtures\//,''), application: json, application_json: parsed_json, response: curl, response_json: parsed_curl}
  end

	def setup
	end

  @fixtures.each do |app|
    test "the response should contain major fields like determination date and applicants #{app[:name]}" do
    	# determination date is present 
    	assert_match /Determination Date/, app[:response]
    	# determination date is set to today
    	assert_match Time.now.strftime('%Y-%m-%d'), app[:response]
    end

    test "the response should contain the correct number of applicants #{app[:name]}" do 
    	# the return string has 'applicants'
    	assert_match /Applicants/, app[:response]
    	# there are an equal number of people on application and applicants with decision
    	assert_equal app[:application_json]['People'].count, app[:response_json]['Applicants'].count
    end

    test "the response should contain a yes or no determination for medicaid and CHIP #{app[:name]}" do
      app[:response_json]['Applicants'].each do |applicant|
    		# check for yes-no on medicaid for each applicant
    		assert ["Y","N"].include? applicant['Medicaid Eligible']
    		# check for yes-no on chip for each applicant
    		assert ["Y","N"].include? applicant['CHIP Eligible']
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12506166748889985, 'fraction_numerical': 0.003206709422792304, 'mean_word_length': 3.671658986175115, 'pattern_counts': {'":': 0, '<': 15, '<?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': '6798655', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1276, 'n_words': 361}