require 'test_helper' class RuleSetProcessorTest < ActiveSupport::TestCase test "mark cron from subject" do email = email_from_eml_with_rules("cron_subject.eml") assert_predicate email, :cron? end test "mark cron from headers" do email = email_from_eml_with_rules("cron_headers.eml") assert_predicate email, :cron? end test "mark not cron" do email = email_from_eml_with_rules("cron_not.eml") assert_not_predicate email, :cron? end test "single issue" do email = email_from_eml_with_rules("issues_single.eml") expected = ["49123"] actual = email.issues assert_equal expected, actual end test "multiple issues" do email = email_from_eml_with_rules("issues_multiple.eml") expected = ["49123", "12345"] actual = email.issues assert_equal expected, actual end test "single organisation" do email = email_from_eml_with_rules("organisations_single.eml") expected = ["quux"] actual = email.organisations assert_equal expected, actual end test "multiple organisations" do email = email_from_eml_with_rules("organisations_multiple.eml") expected = ["quux", "foobar"] actual = email.organisations assert_equal expected, actual end test "invalid subject type" do email = Email.new processor = RuleSetProcessor.new email = processor.process(rule_sets(:invalid_subject), email) assert_not_predicate email, :changed? end test "invalid condition type" do email = Email.new processor = RuleSetProcessor.new email = processor.process(rule_sets(:invalid_condition_type), email) assert_not_predicate email, :changed? end test "invalid operator" do email = Email.new processor = RuleSetProcessor.new email = processor.process(rule_sets(:invalid_operator), email) assert_not_predicate email, :changed? end end