Skip to content

Commit

Permalink
Merge pull request #364 from xlgmokha/xlgmokha/team-sso-id
Browse files Browse the repository at this point in the history
Add SSOTeamID to Team structs
  • Loading branch information
xlgmokha committed Mar 24, 2022
2 parents 3174fa6 + 7521ee2 commit c1df079
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
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"`

// 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)

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)
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

0 comments on commit c1df079

Please sign in to comment.