diff --git a/internal/search/api_search.go b/internal/search/api_search.go index 91d4ecc4..16757fba 100644 --- a/internal/search/api_search.go +++ b/internal/search/api_search.go @@ -237,7 +237,7 @@ func readCryptoCurrencyAddresses(inputs []string) []search.CryptoAddress { parts := strings.Split(input, ":") if len(parts) == 2 { out = append(out, search.CryptoAddress{ - Currency: parts[0], + Currency: strings.ToUpper(parts[0]), Address: parts[1], }) } diff --git a/internal/search/api_search_test.go b/internal/search/api_search_test.go new file mode 100644 index 00000000..270b83a8 --- /dev/null +++ b/internal/search/api_search_test.go @@ -0,0 +1,43 @@ +package search + +import ( + "net/http/httptest" + "testing" + "time" + + "github.com/moov-io/watchman/pkg/search" + + "github.com/stretchr/testify/require" +) + +func TestAPI_readSearchRequest(t *testing.T) { + t.Run("basic", func(t *testing.T) { + req := httptest.NewRequest("GET", "/v2/search?name=adam&type=person&birthDate=2025-01-02", nil) + + query, err := readSearchRequest(req) + require.NoError(t, err) + + require.Equal(t, "adam", query.Name) + require.Equal(t, search.EntityPerson, query.Type) + + require.NotNil(t, query.Person) + require.Equal(t, "2025-01-02T00:00:00Z", query.Person.BirthDate.Format(time.RFC3339)) + + }) + + t.Run("crypto addresses", func(t *testing.T) { + req := httptest.NewRequest("GET", "/v2/search?type=person&cryptoAddress=xbt:12345&cryptoAddress=eth:54321", nil) + + query, err := readSearchRequest(req) + require.NoError(t, err) + require.Empty(t, query.Name) + + require.Len(t, query.CryptoAddresses, 2) + + expected := []search.CryptoAddress{ + {Currency: "XBT", Address: "12345"}, + {Currency: "ETH", Address: "54321"}, + } + require.ElementsMatch(t, expected, query.CryptoAddresses) + }) +}