Skip to content

Commit

Permalink
Add new organization domain fields (#376)
Browse files Browse the repository at this point in the history
* Add new organization domain fields

* fix state consts

* add organization ID

* update tests

* update more tests
  • Loading branch information
amygdalama authored Nov 11, 2024
1 parent e5c33c2 commit 82c0590
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 60 deletions.
28 changes: 28 additions & 0 deletions pkg/organizations/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,41 @@ func (c *Client) init() {
}
}

type OrganizationDomainState string

const (
OrganizationDomainPending OrganizationDomainState = "pending"
OrganizationDomainVerified OrganizationDomainState = "verified"
OrganizationDomainFailed OrganizationDomainState = "failed"
OrganizationDomainLegacyVerified OrganizationDomainState = "legacy_verified"
)

type OrganizationDomainVerificationStrategy string

const (
Dns OrganizationDomainVerificationStrategy = "dns"
Manual OrganizationDomainVerificationStrategy = "manual"
)

// OrganizationDomain contains data about an Organization's Domains.
type OrganizationDomain struct {
// The Organization Domain's unique identifier.
ID string `json:"id"`

// The domain value
Domain string `json:"domain"`

// The Organization's unique identifier.
OrganizationID string `json:"organization_id"`

// Verification state of the domain.
State OrganizationDomainState `json:"state"`

// Strategy used to verify the domain.
VerificationStrategy OrganizationDomainVerificationStrategy `json:"verification_strategy,omitempty"`

// Token used for DNS verification.
VerificationToken string `json:"verification_token,omitempty"`
}

// Organization contains data about a WorkOS Organization.
Expand Down
114 changes: 70 additions & 44 deletions pkg/organizations/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ func TestGetOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -79,9 +81,11 @@ func getOrganizationTestHandler(w http.ResponseWriter, r *http.Request) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
})
Expand Down Expand Up @@ -118,14 +122,16 @@ func TestListOrganizations(t *testing.T) {

expected: ListOrganizationsResponse{
Data: []Organization{
Organization{
{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -175,14 +181,16 @@ func listOrganizationsTestHandler(w http.ResponseWriter, r *http.Request) {
}{
ListOrganizationsResponse: ListOrganizationsResponse{
Data: []Organization{
Organization{
{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -229,9 +237,11 @@ func TestCreateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand All @@ -244,7 +254,7 @@ func TestCreateOrganization(t *testing.T) {
options: CreateOrganizationOpts{
Name: "Foo Corp",
DomainData: []OrganizationDomainData{
OrganizationDomainData{
{
Domain: "foo-corp.com",
State: "verified",
},
Expand All @@ -255,9 +265,11 @@ func TestCreateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -346,9 +358,11 @@ func createOrganizationTestHandler(w http.ResponseWriter, r *http.Request) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
})
Expand Down Expand Up @@ -390,13 +404,17 @@ func TestUpdateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand All @@ -410,11 +428,11 @@ func TestUpdateOrganization(t *testing.T) {
Organization: "organization_id",
Name: "Foo Corp",
DomainData: []OrganizationDomainData{
OrganizationDomainData{
{
Domain: "foo-corp.com",
State: "verified",
},
OrganizationDomainData{
{
Domain: "foo-corp.io",
State: "verified",
},
Expand All @@ -425,13 +443,17 @@ func TestUpdateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -497,13 +519,17 @@ func updateOrganizationTestHandler(w http.ResponseWriter, r *http.Request) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
})
Expand Down
42 changes: 26 additions & 16 deletions pkg/organizations/organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ func TestOrganizationsGetOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
}
Expand All @@ -51,14 +53,16 @@ func TestOrganizationsListOrganizations(t *testing.T) {

expectedResponse := ListOrganizationsResponse{
Data: []Organization{
Organization{
{
ID: "organization_id",
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
},
Expand Down Expand Up @@ -93,9 +97,11 @@ func TestOrganizationsCreateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
},
}
Expand Down Expand Up @@ -126,13 +132,17 @@ func TestOrganizationsUpdateOrganization(t *testing.T) {
Name: "Foo Corp",
AllowProfilesOutsideOrganization: false,
Domains: []OrganizationDomain{
OrganizationDomain{
ID: "organization_domain_id",
Domain: "foo-corp.com",
{
ID: "organization_domain_id",
Domain: "foo-corp.com",
OrganizationID: "organization_id",
State: "verified",
},
OrganizationDomain{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
{
ID: "organization_domain_id_2",
Domain: "foo-corp.io",
OrganizationID: "organization_id",
State: "verified",
},
},
}
Expand Down

0 comments on commit 82c0590

Please sign in to comment.