Skip to content

Commit

Permalink
Merge pull request #550 from hashicorp/add-search-to-orgmembers
Browse files Browse the repository at this point in the history
Add `Query` and `Status` query param fields to `OrganizationMembershipListOptions`
  • Loading branch information
sebasslash committed Oct 17, 2022
2 parents c05ad35 + 739497b commit 27c5ea1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
# (Unreleased)

## Enhancements
* Adds `Query` and `Status` fields to `OrganizationMembershipListOptions` to allow filtering memberships by status or username by @sebasslash [#550](https://github.com/hashicorp/go-tfe/pull/550)

# v1.10.0

## Enhancements
Expand Down
7 changes: 7 additions & 0 deletions organization_membership.go
Expand Up @@ -80,6 +80,13 @@ type OrganizationMembershipListOptions struct {

// Optional: A list of organization member emails to filter by.
Emails []string `url:"filter[email],omitempty"`

// Optional: If specified, restricts results to those matching status value.
Status OrganizationMembershipStatus `url:"filter[status],omitempty"`

// Optional: A query string to search organization memberships by user name
// and email.
Query string `url:"q,omitempty"`
}

// OrganizationMembershipCreateOptions represents the options for creating an organization membership.
Expand Down
40 changes: 40 additions & 0 deletions organization_membership_integration_test.go
Expand Up @@ -103,6 +103,46 @@ func TestOrganizationMembershipsList(t *testing.T) {
})
})

t.Run("with status filter option", func(t *testing.T) {
_, memTest1Cleanup := createOrganizationMembership(t, client, orgTest)
t.Cleanup(memTest1Cleanup)
_, memTest2Cleanup := createOrganizationMembership(t, client, orgTest)
t.Cleanup(memTest2Cleanup)

ml, err := client.OrganizationMemberships.List(ctx, orgTest.Name, &OrganizationMembershipListOptions{
Status: OrganizationMembershipInvited,
})
require.NoError(t, err)

require.Len(t, ml.Items, 2)
for _, member := range ml.Items {
assert.Equal(t, member.Status, OrganizationMembershipInvited)
}
})

t.Run("with search query string", func(t *testing.T) {
memTest1, memTest1Cleanup := createOrganizationMembership(t, client, orgTest)
t.Cleanup(memTest1Cleanup)
_, memTest2Cleanup := createOrganizationMembership(t, client, orgTest)
t.Cleanup(memTest2Cleanup)
_, memTest3Cleanup := createOrganizationMembership(t, client, orgTest)
t.Cleanup(memTest3Cleanup)

t.Run("using an email", func(t *testing.T) {
ml, err := client.OrganizationMemberships.List(ctx, orgTest.Name, &OrganizationMembershipListOptions{
Query: memTest1.Email,
})
require.NoError(t, err)

require.Len(t, ml.Items, 1)
assert.Equal(t, ml.Items[0].Email, memTest1.Email)
})

t.Run("using a user name", func(t *testing.T) {
t.Skip("Skipping, missing Account API support in order to set usernames")
})
})

t.Run("without a valid organization", func(t *testing.T) {
ml, err := client.OrganizationMemberships.List(ctx, badIdentifier, nil)
assert.Nil(t, ml)
Expand Down

0 comments on commit 27c5ea1

Please sign in to comment.