From a89ed0c80ce45c1561194082ca34df1fd1d705f9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 16 Sep 2025 09:40:11 +0000 Subject: [PATCH] refactor: centralize SIGNUP_ALLOWLIST_EMAILS constant definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define environment variable name as a module attribute in BasicSignupAllowlist and expose it via signup_allowlist_emails/0 function to eliminate duplication across lib and test files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- lib/basic_signup_allowlist.ex | 9 ++++++++- test/basic_signup_allowlist_test.exs | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/basic_signup_allowlist.ex b/lib/basic_signup_allowlist.ex index 66df0e4..d76026f 100644 --- a/lib/basic_signup_allowlist.ex +++ b/lib/basic_signup_allowlist.ex @@ -1,10 +1,17 @@ defmodule BasicSignupAllowlist do import FunCore.BasicSignupAllowlist + @signup_allowlist_emails "SIGNUP_ALLOWLIST_EMAILS" + @moduledoc """ Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable. """ + @doc """ + Returns the name of the environment variable used for the signup allowlist. + """ + def signup_allowlist_emails, do: @signup_allowlist_emails + @doc """ Checks if an email address is allowed based on the SIGNUP_ALLOWLIST_EMAILS env variable. @@ -27,7 +34,7 @@ defmodule BasicSignupAllowlist do """ def mail_allowlisted(email) do - env_value = System.get_env("SIGNUP_ALLOWLIST_EMAILS") + env_value = System.get_env(@signup_allowlist_emails) mail_allowlisted_fun(env_value, email) end end diff --git a/test/basic_signup_allowlist_test.exs b/test/basic_signup_allowlist_test.exs index ec1e344..38fa6e2 100644 --- a/test/basic_signup_allowlist_test.exs +++ b/test/basic_signup_allowlist_test.exs @@ -3,21 +3,21 @@ defmodule BasicSignupAllowlistTest do doctest BasicSignupAllowlist defp allow_signups_for(allowlist) do - System.put_env("SIGNUP_ALLOWLIST_EMAILS", allowlist) + System.put_env(BasicSignupAllowlist.signup_allowlist_emails(), allowlist) end describe "setup in describe block" do setup do on_exit(fn -> # resetting values did not work, so 'just' set it to the effect without this module configured. - System.put_env("SIGNUP_ALLOWLIST_EMAILS", "*") + System.put_env(BasicSignupAllowlist.signup_allowlist_emails(), "*") end) :ok end test "When not set, not allowlisted" do - System.delete_env("SIGNUP_ALLOWLIST_EMAILS") + System.delete_env(BasicSignupAllowlist.signup_allowlist_emails()) refute BasicSignupAllowlist.mail_allowlisted("joe@example.com") end