EvoBal/test/services/rule_set_processor_test.rb

84 lines
1.8 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 ticket" do
email = email_from_eml_with_rules("tickets_single.eml")
expected = ["49123"]
actual = email.tickets
assert_equal expected, actual
end
test "multiple tickets" do
email = email_from_eml_with_rules("tickets_multiple.eml")
expected = ["49123", "12345"]
actual = email.tickets
assert_equal expected, actual
end
test "single client" do
email = email_from_eml_with_rules("clients_single.eml")
expected = ["quux"]
actual = email.clients
assert_equal expected, actual
end
test "multiple clients" do
email = email_from_eml_with_rules("clients_multiple.eml")
expected = ["quux", "foobar"]
actual = email.clients
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