<commit_before>require 'test_helper'
class C3Cat3TaskTest < ActiveSupport::TestCase
  include ::Validators
  include ActiveJob::TestHelper

  def setup
    @test = FactoryBot.create(:product_test_static_result)
    @test.product.c3_test = true
    @test.product.c2_test = true
    @task = @test.tasks.create({}, C3Cat3Task)
  end

  def test_task_should_include_c3_cat3_validators
    assert(@task.validators.any? { |v| v.is_a?(MeasurePeriodValidator) })
  end

  def test_should_cause_error_when_measure_is_not_included_in_report_with_c3
    xml = create_rack_test_file('test/fixtures/qrda/cat_III/ep_test_qrda_cat3_missing_measure.xml', 'text/xml')
    perform_enqueued_jobs do
      te = @task.execute(xml, User.first, nil)
      te.reload
      assert_equal 0, te.execution_errors.length, 'should have no errors for the invalid measure ids, this is a c2 validaton'
    end
  end

  def test_should_cause_error_when_performance_rate_is_incorrect_with_c3
    xml = create_rack_test_file('test/fixtures/qrda/cat_III/ep_test_qrda_cat3_bad_performance_rate.xml', 'text/xml')
    perform_enqueued_jobs do
      te = @task.execute(xml, User.first, nil)
      te.reload
      assert_equal 1, te.execution_errors.length, 'should have 1 error for the invalid performance rate'
      msg = 'Reported Performance Rate of 0.5 for Numerator D285D0D1-0AB5-4228-A5A3-F3DE5952F4AF does not match expected value of 0.0.'
      assert_equal msg, te.execution_errors[0].message
    end
  end

  def test_should_error_when_measure_period_is_wrong
    bundle = @test.bundle
    bundle.measure_period_start = 1_420_070_400
    bundle.effective_date = 1_451_520_000
    bundle.save!
    xml = create_rack_test_file('test/fixtures/qrda/cat_III/ep_test_qrda_cat3_bad_mp.xml', 'text/xml')
    perform_enqueued_jobs do
      te = @task.execute(xml, User.first, nil)
      te.reload
      assert_equal 2, te.execution_errors.length, 'should have 2 errors for the invalid reporting period'
      assert_equal 'Reported Measurement Period should start on 20150101', te.execution_errors[0].message
      assert_equal 'Reported Measurement Period should end on 20151231', te.execution_errors[1].message
    end
  end
end<commit_msg>In C3Cat3TaskTest tests are written for errors, not warnings. Filter out warnings for assertions.<commit_after>require 'test_helper'
class C3Cat3TaskTest < ActiveSupport::TestCase
  include ::Validators
  include ActiveJob::TestHelper

  def setup
    @test = FactoryBot.create(:product_test_static_result)
    @test.product.c3_test = true
    @test.product.c2_test = true
    @task = @test.tasks.create({}, C3Cat3Task)
  end

  def test_task_should_include_c3_cat3_validators
    assert(@task.validators.any? { |v| v.is_a?(MeasurePeriodValidator) })
  end

  def test_should_cause_error_when_measure_is_not_included_in_report_with_c3
    xml = create_rack_test_file('test/fixtures/qrda/cat_III/ep_test_qrda_cat3_missing_measure.xml', 'text/xml')
    perform_enqueued_jobs do
      te = @task.execute(xml, User.first, nil)
      te.reload
      assert_equal 0, te.execution_errors.where(:msg_type => :error).length, 'should have no errors for the invalid measure ids, this is a c2 validaton'
    end
  end

  def test_should_cause_error_when_performance_rate_is_incorrect_with_c3
    xml = create_rack_test_file('test/fixtures/qrda/cat_III/ep_test_qrda_cat3_bad_performance_rate.xml', 'text/xml')
    perform_enqueued_jobs do
      te = @task.execute(xml, User.first, nil)
      te.reload
      assert_equal 1, te.execution_errors.where(:msg_type => :error).length, 'should have 1 error for the invalid performance rate'
      msg = 'Reported Performance Rate of 0.5 for Numerator D285D0D1-0AB5-4228-A5A3-F3DE5952F4AF does not match expected value of 0.0.'
      assert_equal msg, te.execution_errors[0].message
    end
  end

  def test_should_error_when_measure_period_is_wrong
    bundle = @test.bundle
    bundle.measure_period_start = 1_420_070_400
    bundle.effective_date = 1_451_520_000
    bundle.save!
    xml = create_rack_test_file('test/fixtures/qrda/cat_III/ep_test_qrda_cat3_bad_mp.xml', 'text/xml')
    perform_enqueued_jobs do
      te = @task.execute(xml, User.first, nil)
      te.reload
      execution_errors = te.execution_errors.where(:msg_type => :error)
      assert_equal 2, execution_errors.length, 'should have 2 errors for the invalid reporting period'
      assert_equal 'Reported Measurement Period should start on 20150101', execution_errors[0].message
      assert_equal 'Reported Measurement Period should end on 20151231', execution_errors[1].message
    end
  end
end
{'fraction_non_alphanumeric': 0.08139787280225744, 'fraction_numerical': 0.035598003038853916, 'mean_word_length': 4.408450704225352, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, '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': '4870619', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1531, 'n_words': 327}