Skip to content

Commit

Permalink
fix(smtp-sender): fixes SMTPSender.smtp_relays
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Mar 21, 2024
1 parent 6ef3885 commit b3264b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/senders/smtp_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ def smtp_relays
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
Expand Down
37 changes: 37 additions & 0 deletions spec/senders/smtp_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,41 @@
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

0 comments on commit b3264b9

Please sign in to comment.