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:
		
							parent
							
								
									464b96b656
								
							
						
					
					
						commit
						09aeb31cb3
					
				
							
								
								
									
										19
									
								
								lib/fun_core/basic_signup_whitelist.ex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								lib/fun_core/basic_signup_whitelist.ex
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@ -1,23 +1,6 @@
 | 
				
			|||||||
defmodule FunCore.BasicSignupWhitelistTest do
 | 
					defmodule FunCore.BasicSignupWhitelistTest do
 | 
				
			||||||
  use ExUnit.Case
 | 
					  use ExUnit.Case
 | 
				
			||||||
 | 
					  import FunCore.BasicSignupWhitelist
 | 
				
			||||||
  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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  test "addresses_as_list" do
 | 
					  test "addresses_as_list" do
 | 
				
			||||||
    assert addresses_as_list("joe@example.com, jane@example.com") == [
 | 
					    assert addresses_as_list("joe@example.com, jane@example.com") == [
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user