Skip to content

Commit

Permalink
feat(user): implement ListOrganizationInvitations (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasLopes7 authored Oct 3, 2024
1 parent a795c59 commit 9674114
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions user/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions user/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,37 @@ func (c *Client) ListOrganizationMemberships(ctx context.Context, id string, par
return list, err
}

type ListOrganizationInvitationsParams struct {
clerk.APIParams
clerk.ListParams
UserID string `json:"-"`
Statuses *[]string `json:"statuses,omitempty"`
}

// ToQuery returns url.Values from the params.
func (params *ListOrganizationInvitationsParams) ToQuery() url.Values {
query := params.ListParams.ToQuery()

if params.Statuses != nil {
query["status"] = *params.Statuses
}

return query
}

// ListOrganizationInvitations lists all the user's organization invitations.
func (c *Client) ListOrganizationInvitations(ctx context.Context, params *ListOrganizationInvitationsParams) (*clerk.OrganizationInvitationList, error) {
path, err := clerk.JoinPath(path, params.UserID, "/organization_invitations")
if err != nil {
return nil, err
}
req := clerk.NewAPIRequest(http.MethodGet, path)
req.SetParams(params)
list := &clerk.OrganizationInvitationList{}
err = c.Backend.Call(ctx, req, list)
return list, err
}

// DeletePasskey deletes a passkey by its identification ID.
func (c *Client) DeletePasskey(ctx context.Context, userID, identificationID string) (*clerk.DeletedResource, error) {
path, err := clerk.JoinPath(path, userID, "/passkeys", identificationID)
Expand Down
39 changes: 39 additions & 0 deletions user/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,45 @@ func TestUserClientListOrganizationMemberships(t *testing.T) {
require.Equal(t, userID, list.OrganizationMemberships[0].PublicUserData.UserID)
}

func TestUserClientListOrganizationInvitations(t *testing.T) {
t.Parallel()
invitationID := "orginv_123"
organizationID := "org_123"
userID := "user_123"
config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
Out: json.RawMessage(fmt.Sprintf(`{
"data": [{
"id":"%s",
"organization_id":"%s"
}],
"total_count": 1
}`,
invitationID, organizationID)),
Method: http.MethodGet,
Path: "/v1/users/" + userID + "/organization_invitations",
Query: &url.Values{
"limit": []string{"1"},
"offset": []string{"2"},
"status": []string{"accepted"},
},
},
}
client := NewClient(config)
params := &ListOrganizationInvitationsParams{
Statuses: &[]string{"accepted"},
UserID: userID,
}
params.Limit = clerk.Int64(1)
params.Offset = clerk.Int64(2)
list, err := client.ListOrganizationInvitations(context.Background(), params)
require.NoError(t, err)
require.Equal(t, invitationID, list.OrganizationInvitations[0].ID)
require.Equal(t, organizationID, list.OrganizationInvitations[0].OrganizationID)
}

func TestUserClientDeletePasskey(t *testing.T) {
t.Parallel()
userID := "user_123"
Expand Down

0 comments on commit 9674114

Please sign in to comment.