EvoBal/test/services/rule_set_processor_test.rb

119 lines
2.9 KiB
Ruby

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
test "postponed to valid future date" do
email = Email.new(subject: "Postponable")
processor = RuleSetProcessor.new
email = processor.process(rule_sets(:postpone_future_valid), email)
assert_not_nil email.postponed_until
assert_predicate email, :postponed?
end
test "postponed to valid past date" do
email = Email.new(subject: "Postponable")
processor = RuleSetProcessor.new
email = processor.process(rule_sets(:postpone_past_valid), email)
assert_not_nil email.postponed_until
assert_not_predicate email, :postponed?
end
test "postponed to invalid date" do
email = Email.new(subject: "Postponable")
processor = RuleSetProcessor.new
email = processor.process(rule_sets(:postpone_invalid), email)
assert_nil email.postponed_until
assert_not_predicate email, :postponed?
end
test "junk mail" do
email = Email.new(subject: "Junk")
processor = RuleSetProcessor.new
email = processor.process(rule_sets(:junk), email)
assert_predicate email, :junk?
end
end