Skip to content

Commit

Permalink
fix(Employee): Use official's email address if names are blank (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathcolo authored Sep 20, 2024
1 parent cd7e6de commit 961c9ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/orbit/employee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ defmodule Orbit.Employee do

@spec display_name(t()) :: String.t()
def display_name(employee) do
"#{employee.preferred_first || employee.first_name} #{employee.last_name}"
case String.trim("#{employee.preferred_first || employee.first_name} #{employee.last_name}") do
"" -> employee.email
name -> name
end
end

@spec get_by_badge_serial(String.t()) :: t() | nil
Expand Down
12 changes: 12 additions & 0 deletions test/orbit/employee_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ defmodule Orbit.EmployeeTest do

assert Employee.display_name(employee) == "First Name"
end

test "uses email if names are all blank" do
employee =
build(:employee, %{
preferred_first: nil,
first_name: "",
last_name: "",
email: "[email protected]"
})

assert Employee.display_name(employee) == "[email protected]"
end
end

describe "get_by_badge_serial/1" do
Expand Down

0 comments on commit 961c9ad

Please sign in to comment.