-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support limit & offset to invitations List (#316)
- Loading branch information
1 parent
a81a965
commit d2786f4
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/clerk/clerk-sdk-go/v2" | ||
|
@@ -35,6 +36,46 @@ func TestInvitationList(t *testing.T) { | |
require.Equal(t, "[email protected]", list.Invitations[0].EmailAddress) | ||
} | ||
|
||
func TestInvitationListWithParams(t *testing.T) { | ||
limit := int64(10) | ||
offset := int64(20) | ||
clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{ | ||
HTTPClient: &http.Client{ | ||
Transport: &clerktest.RoundTripper{ | ||
T: t, | ||
Out: json.RawMessage(`{ | ||
"data": [ | ||
{"id":"inv_123","email_address":"[email protected]"}, | ||
{"id":"inv_124","email_address":"[email protected]"} | ||
], | ||
"total_count": 2 | ||
}`), | ||
Path: "/v1/invitations", | ||
Method: http.MethodGet, | ||
Query: &url.Values{ | ||
"limit": []string{fmt.Sprintf("%d", limit)}, | ||
"offset": []string{fmt.Sprintf("%d", offset)}, | ||
"paginated": []string{"true"}, | ||
}, | ||
}, | ||
}, | ||
})) | ||
|
||
list, err := List(context.Background(), &ListParams{ | ||
ListParams: clerk.ListParams{ | ||
Limit: &limit, | ||
Offset: &offset, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, int64(2), list.TotalCount) | ||
require.Equal(t, 2, len(list.Invitations)) | ||
require.Equal(t, "inv_123", list.Invitations[0].ID) | ||
require.Equal(t, "[email protected]", list.Invitations[0].EmailAddress) | ||
require.Equal(t, "inv_124", list.Invitations[1].ID) | ||
require.Equal(t, "[email protected]", list.Invitations[1].EmailAddress) | ||
} | ||
|
||
func TestInvitationCreate(t *testing.T) { | ||
emailAddress := "[email protected]" | ||
id := "inv_123" | ||
|