diff --git a/internal/prepare/prepare_gender.go b/internal/prepare/prepare_gender.go new file mode 100644 index 00000000..f67e2927 --- /dev/null +++ b/internal/prepare/prepare_gender.go @@ -0,0 +1,21 @@ +package prepare + +import ( + "strings" + + "github.com/moov-io/watchman/pkg/search" +) + +func NormalizeGender(input string) search.Gender { + v := strings.ToLower(strings.TrimSpace(input)) + + switch v { + case "m", "male", "man", "guy": + return search.GenderMale + + case "f", "female", "woman", "gal", "girl": + return search.GenderFemale + } + + return search.GenderUnknown +} diff --git a/internal/prepare/prepare_gender_test.go b/internal/prepare/prepare_gender_test.go new file mode 100644 index 00000000..8a060659 --- /dev/null +++ b/internal/prepare/prepare_gender_test.go @@ -0,0 +1,29 @@ +package prepare + +import ( + "testing" + + "github.com/moov-io/watchman/pkg/search" + + "github.com/stretchr/testify/require" +) + +func TestPrepare_NormalizeGender(t *testing.T) { + cases := []struct { + input string + expected search.Gender + }{ + {"M", search.GenderMale}, + {"Male", search.GenderMale}, + {"guy", search.GenderMale}, + {"F", search.GenderFemale}, + {"FEMALE", search.GenderFemale}, + {"Girl", search.GenderFemale}, + } + for _, tc := range cases { + t.Run(tc.input, func(t *testing.T) { + got := NormalizeGender(tc.input) + require.Equal(t, tc.expected, got) + }) + } +} diff --git a/internal/search/api_search.go b/internal/search/api_search.go index b70f65e5..91d4ecc4 100644 --- a/internal/search/api_search.go +++ b/internal/search/api_search.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/moov-io/watchman/internal/prepare" "github.com/moov-io/watchman/pkg/address" "github.com/moov-io/watchman/pkg/search" @@ -139,7 +140,7 @@ func readSearchRequest(r *http.Request) (search.Entity[search.Value], error) { req.Person = &search.Person{ Name: req.Name, AltNames: q["altNames"], - Gender: search.Gender(strings.TrimSpace(q.Get("gender"))), + Gender: prepare.NormalizeGender(q.Get("gender")), BirthDate: readDate(q.Get("birthDate")), DeathDate: readDate(q.Get("deathDate")), Titles: q["titles"],