Skip to content

Commit

Permalink
feat: Support query & order_by for invitations List
Browse files Browse the repository at this point in the history
  • Loading branch information
nikospapcom committed Sep 2, 2024
1 parent d2786f4 commit 2389e47
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion invitation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ func NewClient(config *clerk.ClientConfig) *Client {
type ListParams struct {
clerk.APIParams
clerk.ListParams
OrderBy *string `json:"order_by,omitempty"`
Query *string `json:"query,omitempty"`
}

// ToQuery returns query string values from the params.
func (params *ListParams) ToQuery() url.Values {
return params.ListParams.ToQuery()
q := params.ListParams.ToQuery()
if params.OrderBy != nil {
q.Set("order_by", *params.OrderBy)
}
if params.Query != nil {
q.Set("query", *params.Query)
}
return q
}

// List returns all invitations.
Expand Down
7 changes: 7 additions & 0 deletions invitation/invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func TestInvitationList(t *testing.T) {
func TestInvitationListWithParams(t *testing.T) {
limit := int64(10)
offset := int64(20)
orderBy := "-created_at"
query := "[email protected]"

clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{
HTTPClient: &http.Client{
Transport: &clerktest.RoundTripper{
Expand All @@ -55,6 +58,8 @@ func TestInvitationListWithParams(t *testing.T) {
Query: &url.Values{
"limit": []string{fmt.Sprintf("%d", limit)},
"offset": []string{fmt.Sprintf("%d", offset)},
"order_by": []string{orderBy},
"query": []string{query},
"paginated": []string{"true"},
},
},
Expand All @@ -66,6 +71,8 @@ func TestInvitationListWithParams(t *testing.T) {
Limit: &limit,
Offset: &offset,
},
OrderBy: &orderBy,
Query: &query,
})
require.NoError(t, err)
require.Equal(t, int64(2), list.TotalCount)
Expand Down

0 comments on commit 2389e47

Please sign in to comment.