Skip to content

Commit

Permalink
search: start on readSearchRequest testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 15, 2025
1 parent 99cec9a commit c73367b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/search/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
}
Expand Down
43 changes: 43 additions & 0 deletions internal/search/api_search_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}

0 comments on commit c73367b

Please sign in to comment.