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 SSOTeamID to Team structs #364

Merged
merged 1 commit into from Mar 24, 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
7 changes: 7 additions & 0 deletions team.go
Expand Up @@ -49,6 +49,7 @@ type Team struct {
Visibility string `jsonapi:"attr,visibility"`
Permissions *TeamPermissions `jsonapi:"attr,permissions"`
UserCount int `jsonapi:"attr,users-count"`
SSOTeamID *string `jsonapi:"attr,sso-team-id"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose *string instead of string because SSOTeamID can be nil.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice!


// Relations
Users []*User `jsonapi:"relation,users"`
Expand Down Expand Up @@ -99,6 +100,9 @@ type TeamCreateOptions struct {
// Name of the team.
Name *string `jsonapi:"attr,name"`

// Optional: Unique Identifier to control team membership via SAML
SSOTeamID *string `jsonapi:"attr,sso-team-id,omitempty"`

// The team's organization access
OrganizationAccess *OrganizationAccessOptions `jsonapi:"attr,organization-access,omitempty"`

Expand All @@ -117,6 +121,9 @@ type TeamUpdateOptions struct {
// Optional: New name for the team
Name *string `jsonapi:"attr,name,omitempty"`

// Optional: Unique Identifier to control team membership via SAML
SSOTeamID *string `jsonapi:"attr,sso-team-id,omitempty"`

// Optional: The team's organization access
OrganizationAccess *OrganizationAccessOptions `jsonapi:"attr,organization-access,omitempty"`

Expand Down
31 changes: 28 additions & 3 deletions team_integration_test.go
Expand Up @@ -93,6 +93,22 @@ func TestTeamsCreate(t *testing.T) {
}
})

t.Run("with sso-team-id", func(t *testing.T) {
skipIfBeta(t)
xlgmokha marked this conversation as resolved.
Show resolved Hide resolved

options := TeamCreateOptions{
Name: String("rockettes"),
SSOTeamID: String("7dddb675-73e0-4858-a8ad-0e597064301b"),
}
team, err := client.Teams.Create(ctx, orgTest.Name, options)

assert.Nil(t, err)
assert.Equal(t, *options.Name, team.Name)

assert.NotNil(t, options.SSOTeamID, team.SSOTeamID)
assert.Equal(t, *options.SSOTeamID, *team.SSOTeamID)
})

t.Run("when options is missing name", func(t *testing.T) {
tm, err := client.Teams.Create(ctx, "foo", TeamCreateOptions{})
assert.Nil(t, tm)
Expand Down Expand Up @@ -121,15 +137,16 @@ func TestTeamsRead(t *testing.T) {
defer tmTestCleanup()

opts := TeamCreateOptions{
Name: String(randomString(t)),
Name: String(randomString(t)),
SSOTeamID: String(randomString(t)),
OrganizationAccess: &OrganizationAccessOptions{
ManagePolicies: Bool(true),
},
}
tm, err := client.Teams.Create(ctx, orgTest.Name, opts)
ssoTeam, err := client.Teams.Create(ctx, orgTest.Name, opts)
xlgmokha marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
defer func() {
err := client.Teams.Delete(ctx, tm.ID)
err := client.Teams.Delete(ctx, ssoTeam.ID)
require.NoError(t, err)
}()

Expand All @@ -149,6 +166,13 @@ func TestTeamsRead(t *testing.T) {
t.Run("organization access is properly decoded", func(t *testing.T) {
assert.Equal(t, tm.OrganizationAccess.ManagePolicies, *opts.OrganizationAccess.ManagePolicies)
})

t.Run("SSO team id is returned", func(t *testing.T) {
skipIfBeta(t)

assert.NotNil(t, ssoTeam.SSOTeamID)
assert.Equal(t, *opts.SSOTeamID, *ssoTeam.SSOTeamID)
})
})

t.Run("when the team does not exist", func(t *testing.T) {
Expand Down Expand Up @@ -298,6 +322,7 @@ func TestTeam_Unmarshal(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, team.ID, "1")
assert.Equal(t, team.Name, "team hashi")
assert.Nil(t, team.SSOTeamID)
assert.Equal(t, team.OrganizationAccess.ManageWorkspaces, true)
assert.Equal(t, team.OrganizationAccess.ManageVCSSettings, true)
assert.Equal(t, team.OrganizationAccess.ManagePolicies, true)
Expand Down