Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DASH-360: implement method to delete user profile image #315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

12 changes: 12 additions & 0 deletions user/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ func (c *Client) UpdateProfileImage(ctx context.Context, id string, params *Upda
return resource, err
}

// DeleteProfileImage sets or replaces the user's profile image.
func (c *Client) DeleteProfileImage(ctx context.Context, id string) (*clerk.User, error) {
path, err := clerk.JoinPath(path, id, "/profile_image")
if err != nil {
return nil, err
}
req := clerk.NewAPIRequest(http.MethodDelete, path)
resource := &clerk.User{}
err = c.Backend.Call(ctx, req, resource)
return resource, err
}

type UpdateMetadataParams struct {
clerk.APIParams
PublicMetadata *json.RawMessage `json:"public_metadata,omitempty"`
Expand Down
18 changes: 18 additions & 0 deletions user/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ func TestUserClientUpdateProfileImage(t *testing.T) {
require.Equal(t, userID, user.ID)
}

func TestUserClientDeleteProfileImage(t *testing.T) {
t.Parallel()
userID := "user_123"
config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s"}`, userID)),
Method: http.MethodDelete,
Path: "/v1/users/" + userID + "/profile_image",
},
}
client := NewClient(config)
user, err := client.DeleteProfileImage(context.Background(), userID)
require.NoError(t, err)
require.Equal(t, userID, user.ID)
}

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