Move implementation to own file

Prefactoring, from  TDDAYMI to imperative shell. In the next step we
need the implementation from the functional core in the imperative
shell, to pass in the environment variable.
This commit is contained in:
Willem van den Ende 2025-09-14 16:59:42 +01:00
parent 464b96b656
commit 09aeb31cb3
2 changed files with 20 additions and 18 deletions

View File

@ -0,0 +1,19 @@
defmodule FunCore.BasicSignupWhitelist do
def normalize(email) do
email |> String.trim() |> String.downcase()
end
def addresses_as_list(addresses_str) do
addresses_str
|> String.split(",")
|> Enum.map(&normalize/1)
end
def mail_whitelisted_fun(signups_allowed, email_received) do
case signups_allowed do
nil -> false
"*" -> true
list_str -> normalize(email_received) in addresses_as_list(list_str)
end
end
end

View File

@ -1,23 +1,6 @@
defmodule FunCore.BasicSignupWhitelistTest do
use ExUnit.Case
defp normalize(email) do
email |> String.trim() |> String.downcase()
end
defp addresses_as_list(addresses_str) do
addresses_str
|> String.split(",")
|> Enum.map(&normalize/1)
end
def mail_whitelisted_fun(signups_allowed, email_received) do
case signups_allowed do
nil -> false
"*" -> true
list_str -> normalize(email_received) in addresses_as_list(list_str)
end
end
import FunCore.BasicSignupWhitelist
test "addresses_as_list" do
assert addresses_as_list("joe@example.com, jane@example.com") == [