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

Add Query and Status query param fields to OrganizationMembershipListOptions #550

Merged
merged 2 commits into from Oct 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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