1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-11-30 21:32:30 +00:00

fix(smtp-sender): fixes SMTPSender.smtp_relays

هذا الالتزام موجود في:
Adam Cooke
2024-03-21 12:27:40 +00:00
الأصل 6ef388577e
التزام b3264b9427
2 ملفات معدلة مع 40 إضافات و3 حذوفات

عرض الملف

@@ -244,11 +244,11 @@ class SMTPSender < BaseSender
relays = Postal::Config.postal.smtp_relays
return nil if relays.nil?
relays.map do |relay|
relays = relays.map do |relay|
next unless relay.host.present?
SMTPClient::Server.new(relay.host, relay.port, ssl_mode: relay.ssl_mode)
end.compact
SMTPClient::Server.new(relay.host, port: relay.port, ssl_mode: relay.ssl_mode)
end
@smtp_relays = relays.empty? ? nil : relays
end

عرض الملف

@@ -524,4 +524,41 @@ RSpec.describe SMTPSender do
expect(sender.endpoints).to all have_received(:finish_smtp_session).at_least(:once)
end
end
describe ".smtp_relays" do
before do
if described_class.instance_variable_defined?("@smtp_relays")
described_class.remove_instance_variable("@smtp_relays")
end
end
it "returns nil if smtp relays is nil" do
allow(Postal::Config.postal).to receive(:smtp_relays).and_return(nil)
expect(described_class.smtp_relays).to be nil
end
it "returns nil if there are no smtp relays" do
allow(Postal::Config.postal).to receive(:smtp_relays).and_return([])
expect(described_class.smtp_relays).to be nil
end
it "does not return relays where the host is nil" do
allow(Postal::Config.postal).to receive(:smtp_relays).and_return([
Hashie::Mash.new(host: nil, port: 25, ssl_mode: "Auto"),
Hashie::Mash.new(host: "test.example.com", port: 25, ssl_mode: "Auto"),
])
expect(described_class.smtp_relays).to match [kind_of(SMTPClient::Server)]
end
it "returns relays with options" do
allow(Postal::Config.postal).to receive(:smtp_relays).and_return([
Hashie::Mash.new(host: "test.example.com", port: 25, ssl_mode: "Auto"),
Hashie::Mash.new(host: "test2.example.com", port: 2525, ssl_mode: "TLS"),
])
expect(described_class.smtp_relays).to match [
have_attributes(hostname: "test.example.com", port: 25, ssl_mode: "Auto"),
have_attributes(hostname: "test2.example.com", port: 2525, ssl_mode: "TLS"),
]
end
end
end