namespace email settings keys per adapter
All checks were successful
deploy / deploy (push) Successful in 57s
All checks were successful
deploy / deploy (push) Successful in 57s
Settings keys like api_key were shared across providers, so switching from e.g. Postmark to SendGrid showed the old API key. Now each adapter gets its own namespaced key (email_postmark_api_key, etc.) so credentials persist independently and switching back pre-fills previously saved values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -55,14 +55,14 @@ defmodule Berrypod.Mailer.AdaptersTest do
|
||||
end
|
||||
|
||||
describe "field_keys/1" do
|
||||
test "returns settings keys prefixed with email_" do
|
||||
test "returns namespaced settings keys" do
|
||||
smtp = Adapters.get("smtp")
|
||||
keys = Adapters.field_keys(smtp)
|
||||
|
||||
assert "email_relay" in keys
|
||||
assert "email_port" in keys
|
||||
assert "email_username" in keys
|
||||
assert "email_password" in keys
|
||||
assert "email_smtp_relay" in keys
|
||||
assert "email_smtp_port" in keys
|
||||
assert "email_smtp_username" in keys
|
||||
assert "email_smtp_password" in keys
|
||||
end
|
||||
end
|
||||
|
||||
@@ -70,9 +70,16 @@ defmodule Berrypod.Mailer.AdaptersTest do
|
||||
test "returns unique keys from all adapters" do
|
||||
keys = Adapters.all_field_keys()
|
||||
assert is_list(keys)
|
||||
assert "email_api_key" in keys
|
||||
assert "email_relay" in keys
|
||||
assert "email_postmark_api_key" in keys
|
||||
assert "email_smtp_relay" in keys
|
||||
assert length(keys) == length(Enum.uniq(keys))
|
||||
end
|
||||
end
|
||||
|
||||
describe "settings_key/2" do
|
||||
test "namespaces key with adapter" do
|
||||
assert Adapters.settings_key("postmark", "api_key") == "email_postmark_api_key"
|
||||
assert Adapters.settings_key("smtp", "relay") == "email_smtp_relay"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ defmodule Berrypod.MailerTest do
|
||||
describe "load_config/0" do
|
||||
test "loads adapter config from settings" do
|
||||
Settings.put_setting("email_adapter", "postmark")
|
||||
Settings.put_secret("email_api_key", "pm_test_key_123")
|
||||
Settings.put_secret("email_postmark_api_key", "pm_test_key_123")
|
||||
|
||||
Mailer.load_config()
|
||||
|
||||
@@ -37,10 +37,10 @@ defmodule Berrypod.MailerTest do
|
||||
|
||||
test "loads SMTP config with multiple fields" do
|
||||
Settings.put_setting("email_adapter", "smtp")
|
||||
Settings.put_setting("email_relay", "smtp.example.com")
|
||||
Settings.put_setting("email_port", 465, "integer")
|
||||
Settings.put_setting("email_username", "user@example.com")
|
||||
Settings.put_secret("email_password", "secret123")
|
||||
Settings.put_setting("email_smtp_relay", "smtp.example.com")
|
||||
Settings.put_setting("email_smtp_port", 465, "integer")
|
||||
Settings.put_setting("email_smtp_username", "user@example.com")
|
||||
Settings.put_secret("email_smtp_password", "secret123")
|
||||
|
||||
Mailer.load_config()
|
||||
|
||||
@@ -67,7 +67,7 @@ defmodule Berrypod.MailerTest do
|
||||
|
||||
test "returns adapter key and config when configured from settings" do
|
||||
Settings.put_setting("email_adapter", "postmark")
|
||||
Settings.put_secret("email_api_key", "pm_test_key_123")
|
||||
Settings.put_secret("email_postmark_api_key", "pm_test_key_123")
|
||||
|
||||
Mailer.load_config()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user