Skip to content

Commit

Permalink
feat: Delete organization logo (#142)
Browse files Browse the repository at this point in the history
Added a new DeleteLogo() method on the organizations service. Accepts
the organization ID as a parameter and removes the logo from the
organization.
  • Loading branch information
gkats authored Jun 27, 2023
1 parent b1a423a commit cba9bc1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clerk/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ func (s *OrganizationsService) UpdateLogo(organizationID string, params UpdateOr
return &organization, err
}

func (s *OrganizationsService) DeleteLogo(organizationID string) (*Organization, error) {
req, _ := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s/logo", OrganizationsUrl, organizationID))
var organization Organization
_, err := s.client.Do(req, &organization)
return &organization, err
}

type UpdateOrganizationMetadataParams struct {
PublicMetadata json.RawMessage `json:"public_metadata,omitempty"`
PrivateMetadata json.RawMessage `json:"private_metadata,omitempty"`
Expand Down
21 changes: 21 additions & 0 deletions clerk/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ func TestOrganizationsService_UpdateLogo(t *testing.T) {
}
}

func TestOrganizationsService_DeleteLogo(t *testing.T) {
client, mux, _, teardown := setup("token")
defer teardown()

organizationID := "org_123"
mux.HandleFunc(
fmt.Sprintf("/organizations/%s/logo", organizationID),
func(w http.ResponseWriter, req *http.Request) {
testHttpMethod(t, req, http.MethodDelete)
testHeader(t, req, "Authorization", "Bearer token")
fmt.Fprint(w, fmt.Sprintf(`{"id":"%s"}`, organizationID))
},
)

// Trigger a request to delete the logo
_, err := client.Organizations().DeleteLogo(organizationID)
if err != nil {
t.Fatal(err)
}
}

const dummyOrganizationJson = `{
"object": "organization",
"id": "org_1mebQggrD3xO5JfuHk7clQ94ysA",
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ func TestOrganizations(t *testing.T) {
Filename: &filename,
UploaderUserID: users[0].ID,
})
assert.NoError(t, err)
assert.NotNil(t, updatedOrganization.LogoURL)

// Delete organization logo
updatedOrganization, err = client.Organizations().DeleteLogo(updatedOrganization.ID)
assert.NoError(t, err)
assert.Nil(t, updatedOrganization.LogoURL)

organizations, err := client.Organizations().ListAll(clerk.ListAllOrganizationsParams{
IncludeMembersCount: true,
})
Expand Down

0 comments on commit cba9bc1

Please sign in to comment.