EvoBal/test/services/email_importer_test.rb

114 lines
2.8 KiB
Ruby

require 'test_helper'
class EmailImporterTest < ActiveSupport::TestCase
test "convert html to text when not multipart html only" do
email = email_from_eml("html_only.eml")
assert_match(/Attention, plus que quelques jours pour bénéficier du FNE !/, email.plain_body)
assert_no_html email.plain_body
end
test "convert html to text when multipart and html only" do
email = email_from_eml("html_only_multipart.eml")
assert_match(/Complément d''information : suite du ticket 2009P88471/, email.plain_body)
assert_no_html email.plain_body
end
test "convert html to text when base64-encoded html only" do
email = email_from_eml("html_only_base64.eml")
assert_match(/Type: Health and Safety/, email.plain_body)
assert_no_html email.plain_body
end
test "mark cron from subject" do
email = email_from_eml("cron_subject.eml")
assert_predicate email, :cron?
end
test "mark cron from headers" do
email = email_from_eml("cron_headers.eml")
assert_predicate email, :cron?
end
test "mark not cron" do
email = email_from_eml("cron_not.eml")
assert_not_predicate email, :cron?
end
test "single delivered-to" do
email = email_from_eml("delivered_to_single.eml")
expected = ["delivered-to-1@example.com"]
actual = email.delivered_to
assert_equal expected, actual
end
test "multiple delivered-to" do
email = email_from_eml("delivered_to_multiple.eml")
expected = ["delivered-to-1@example.com", "delivered-to-2@example.com", "delivered-to-3@example.com"]
actual = email.delivered_to
assert_equal expected, actual
end
test "missing delivered-to fallback to To field" do
email = email_from_eml("delivered_to_missing.eml")
expected = ["to-foo@example.com"]
actual = email.delivered_to
assert_equal expected, actual
end
test "single ticket" do
email = email_from_eml("tickets_single.eml")
expected = ["49123"]
actual = email.tickets
assert_equal expected, actual
end
test "multiple tickets" do
email = email_from_eml("tickets_multiple.eml")
expected = ["49123", "12345"]
actual = email.tickets
assert_equal expected, actual
end
test "single client" do
email = email_from_eml("clients_single.eml")
expected = ["42QUUX4567"]
actual = email.clients
assert_equal expected, actual
end
test "multiple clients" do
email = email_from_eml("clients_multiple.eml")
expected = ["42QUUX4567", "75FOOB0123"]
actual = email.clients
assert_equal expected, actual
end
test "mail without content-type" do
email = email_from_eml("no_content_type.eml")
expected = /This is a RAID status update from megaraidsas-statusd/
assert_match(expected, email.plain_body)
end
end