Files
eminuxCRM/test/models/mail_identity_test.rb
eminuxandCursor 36b3ffe507
CI / scan_ruby (push) Failing after 13m27s
CI / scan_js (push) Successful in 11m45s
CI / lint (push) Failing after 12m4s
Aggiunge IMAP bounce e flag email non valide nel CRM.
Permette di leggere i bounce dalla stessa MailIdentity SMTP, aggiornare le email in anagrafica e saltare gli indirizzi invalidi nei mailing.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 19:46:04 +02:00

80 lines
2.3 KiB
Ruby

require "test_helper"
class MailIdentityTest < ActiveSupport::TestCase
test "smtp settings use starttls on port 587" do
identity = MailIdentity.new(
name: "Test",
from_name: "Test",
from_email: "hello@example.com",
smtp_host: "smtp.example.com",
smtp_port: 587,
encryption: "starttls",
smtp_authentication: "plain",
active: true
)
assert identity.valid?
settings = identity.smtp_settings
assert settings[:enable_starttls_auto]
assert_not settings[:ssl]
end
test "smtp settings use ssl on port 465" do
identity = MailIdentity.new(
name: "Test",
from_name: "Test",
from_email: "hello@example.com",
smtp_host: "smtps.example.com",
smtp_port: 465,
encryption: "tls",
smtp_authentication: "plain",
active: true
)
assert identity.valid?
settings = identity.smtp_settings
assert settings[:ssl]
assert_not settings[:enable_starttls_auto]
assert_equal 15, settings[:open_timeout]
assert_equal 60, settings[:read_timeout]
end
test "rejects ssl encryption on port 587" do
identity = MailIdentity.new(
name: "Test",
from_name: "Test",
from_email: "hello@example.com",
smtp_host: "smtps.example.com",
smtp_port: 587,
encryption: "tls",
smtp_authentication: "plain",
active: true
)
assert_not identity.valid?
assert_includes identity.errors[:smtp_port], "con SSL/TLS va usata la porta 465 (es. smtps.aruba.it)"
end
test "infers aruba imap host from smtp" do
identity = MailIdentity.new(
name: "Aruba",
from_name: "Info",
from_email: "info@example.com",
smtp_host: "smtps.aruba.it",
smtp_port: 465,
encryption: "tls",
smtp_authentication: "plain",
smtp_username: "info@example.com",
smtp_password: "secret",
active: true
)
assert identity.valid?
assert_equal "imaps.aruba.it", identity.effective_imap_host
assert_equal 993, identity.effective_imap_port
assert identity.imap_ready?
settings = identity.imap_settings
assert_equal "imaps.aruba.it", settings[:address]
assert_equal 993, settings[:port]
assert settings[:ssl]
assert_equal "info@example.com", settings[:user_name]
assert_equal "secret", settings[:password]
end
end