Skip to content

Commit

Permalink
feat: Support query, order_by and status for invitations List (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikospapcom authored Sep 4, 2024
1 parent 240f3a5 commit 84b590a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion invitation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,24 @@ func NewClient(config *clerk.ClientConfig) *Client {
type ListParams struct {
clerk.APIParams
clerk.ListParams
OrderBy *string `json:"order_by,omitempty"`
Query *string `json:"query,omitempty"`
Status *string `json:"status,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)
}
if params.Status != nil {
q.Set("status", *params.Status)
}
return q
}

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

clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{
HTTPClient: &http.Client{
Transport: &clerktest.RoundTripper{
Expand All @@ -55,6 +59,9 @@ 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},
"status": []string{status},
"paginated": []string{"true"},
},
},
Expand All @@ -66,6 +73,9 @@ func TestInvitationListWithParams(t *testing.T) {
Limit: &limit,
Offset: &offset,
},
OrderBy: &orderBy,
Query: &query,
Status: &status,
})
require.NoError(t, err)
require.Equal(t, int64(2), list.TotalCount)
Expand Down

0 comments on commit 84b590a

Please sign in to comment.