Skip to content

Commit

Permalink
rename subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
jac committed Oct 31, 2024
1 parent ef04898 commit 9b96280
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
12 changes: 10 additions & 2 deletions roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"

"github.com/sourcegraph/sourcegraph-accounts-sdk-go/services"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// Role is always the full qualified role name, e.g. "dotcom::site_admin".
Expand Down Expand Up @@ -47,7 +49,7 @@ const (
// Service type is a special type used for service level roles.
Service ResourceType = "service"
// Subscription resources for Enterprise Portal.
Subscription ResourceType = "subscription"
EnterpriseSubscription ResourceType = "enterprise_subscription"
)

// IsService returns true if the resource type is a service.
Expand All @@ -56,6 +58,12 @@ func (r ResourceType) IsService() bool {
return r == Service
}

// Display returns the display name of the resource type.
func (r ResourceType) Display() string {
s := strings.ReplaceAll(string(r), "_", " ")
return cases.Title(language.English).String(s)
}

// roleInfo is the sdk internal representation of a role.
type roleInfo struct {
// id is the fully qualified role name. e.g. "dotcom::site_admin"
Expand Down Expand Up @@ -103,7 +111,7 @@ var (
{
id: RoleEnterprisePortalCustomerAdmin,
service: services.EnterprisePortal,
resourceType: Subscription,
resourceType: EnterpriseSubscription,
},
}
)
Expand Down
29 changes: 27 additions & 2 deletions roles/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func TestRolesByResourceType(t *testing.T) {
}),
},
{
name: "subscription",
resource: Subscription,
name: "enterprise_subscription",
resource: EnterpriseSubscription,
expected: autogold.Expect([]Role{
Role("enterprise_portal::customer_admin"),
}),
Expand Down Expand Up @@ -124,3 +124,28 @@ func TestToService(t *testing.T) {
})
}
}

func TestDisplay(t *testing.T) {
tests := []struct {
name string
resource ResourceType
want string
}{
{
name: "service",
resource: Service,
want: "Service",
},
{
name: "enterprise_subscription",
resource: EnterpriseSubscription,
want: "Enterprise Subscription",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := test.resource.Display()
assert.Equal(t, test.want, got)
})
}
}

0 comments on commit 9b96280

Please sign in to comment.