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 domains_data to Organization API and deprecate domains #327

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/organizations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ type ListOrganizationsResponse struct {
ListMetadata common.ListMetadata `json:"listMetadata"`
}

type OrganizationDomainDataState string

const (
Verified OrganizationDomainDataState = "verified"
Pending OrganizationDomainDataState = "pending"
)

// OrganizationDomainData contains data used to create an OrganizationDomain.
type OrganizationDomainData struct {
// The domain's value.
Domain string `json:"domain"`

// The domain's state.
State OrganizationDomainDataState `json:"state"`
}

// CreateOrganizationOpts contains the options to create an Organization.
type CreateOrganizationOpts struct {
// Name of the Organization.
Expand All @@ -135,8 +151,13 @@ type CreateOrganizationOpts struct {
AllowProfilesOutsideOrganization bool `json:"allow_profiles_outside_organization"`

// Domains of the Organization.
//
// Deprecated: Use DomainData instead.
Domains []string `json:"domains"`

// Domains of the Organization.
DomainData []OrganizationDomainData `json:"domain_data"`

// Optional unique identifier to ensure idempotency
IdempotencyKey string `json:"idempotency_iey,omitempty"`
}
Expand All @@ -154,7 +175,12 @@ type UpdateOrganizationOpts struct {
AllowProfilesOutsideOrganization bool

// Domains of the Organization.
//
// Deprecated: Use DomainData instead.
Domains []string

// Domains of the Organization.
DomainData []OrganizationDomainData `json:"domain_data"`
}

// GetOrganization gets an Organization.
Expand Down
65 changes: 63 additions & 2 deletions pkg/organizations/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestCreateOrganization(t *testing.T) {
err: true,
},
{
scenario: "Request returns Organization",
scenario: "Request returns Organization with Domains",
client: &Client{
APIKey: "test",
},
Expand All @@ -236,6 +236,32 @@ func TestCreateOrganization(t *testing.T) {
},
},
},
{
scenario: "Request returns Organization with DomainData",
client: &Client{
APIKey: "test",
},
options: CreateOrganizationOpts{
Name: "Foo Corp",
DomainData: []OrganizationDomainData{
OrganizationDomainData{
Domain: "foo-corp.com",
State: "verified",
},
},
},
expected: Organization{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
},
},
},
},
{
scenario: "Request with duplicate Organization Domain returns error",
client: &Client{
Expand Down Expand Up @@ -350,7 +376,7 @@ func TestUpdateOrganization(t *testing.T) {
err: true,
},
{
scenario: "Request returns Organization",
scenario: "Request returns Organization with Domains",
client: &Client{
APIKey: "test",
},
Expand All @@ -375,6 +401,41 @@ func TestUpdateOrganization(t *testing.T) {
},
},
},
{
scenario: "Request returns Organization with DomainData",
client: &Client{
APIKey: "test",
},
options: UpdateOrganizationOpts{
Organization: "organization_id",
Name: "Foo Corp",
DomainData: []OrganizationDomainData{
OrganizationDomainData{
Domain: "foo-corp.com",
State: "verified",
},
OrganizationDomainData{
Domain: "foo-corp.io",
State: "verified",
},
},
},
expected: Organization{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
},
},
},
},
{
scenario: "Request with duplicate Organization Domain returns error",
client: &Client{
Expand Down
Loading