Skip to content

Commit

Permalink
Fix org membership delete, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexyans committed Feb 22, 2017
1 parent 82761ef commit a2b158c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions zendesk/org_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func (c *client) ListOrganizationMembershipsByUserID(id int64) ([]OrganizationMe
// DeleteOrganizationMembership removes an organization membership
//
// Zendesk Core API docs: https://developer.zendesk.com/rest_api/docs/core/organization_memberships#delete-membership
func (c *client) DeleteOrganizationMembership(userId, orgId int64) error {
out := new(APIPayload)
err := c.delete(fmt.Sprintf("/api/v2/users/%d/organization_memberships/%d.json", userId, orgId), out)
return err
func (c *client) DeleteOrganizationMembershipByID(id int64) error {
return c.delete(fmt.Sprintf("/api/v2/organization_memberships/%d.json", id), nil)
}
7 changes: 7 additions & 0 deletions zendesk/org_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func TestOrganizationMembershipCRUD(t *testing.T) {
require.Equal(t, found1, true)
found2 := isExistingMembership(*created2.UserID, *created2.OrganizationID, found)
require.Equal(t, found2, true)

// it should delete an organization membership
err = client.DeleteOrganizationMembershipByID(*created1.ID)
require.NoError(t, err)
found, err = client.ListOrganizationMembershipsByUserID(*user.ID)
require.NoError(t, err)
require.Len(t, found, 1)
}

func isExistingMembership(userId, orgId int64, memberships []OrganizationMembership) bool {
Expand Down
1 change: 1 addition & 0 deletions zendesk/zendesk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Client interface {
DeleteOrganization(int64) error
DeleteTicket(int64) error
DeleteUser(int64) (*User, error)
DeleteOrganizationMembershipByID(int64) error
ListLocales() ([]Locale, error)
ListOrganizationMembershipsByUserID(id int64) ([]OrganizationMembership, error)
ListOrganizations(*ListOptions) ([]Organization, error)
Expand Down

0 comments on commit a2b158c

Please sign in to comment.