Skip to content

Commit

Permalink
Add domain_data to Organization API and deprecate domains (#1025)
Browse files Browse the repository at this point in the history
## Description

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.

---------

Co-authored-by: Michael Hadley <[email protected]>
  • Loading branch information
oliverzheng and mthadley authored Apr 29, 2024
1 parent f3ff594 commit 5443fbc
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { PostOptions } from '../../common/interfaces';
import { DomainData } from './domain-data.interface';

export interface CreateOrganizationOptions {
name: string;
allowProfilesOutsideOrganization?: boolean;
domainData?: DomainData[];
/**
* @deprecated Use `domain_data` instead.
*/
domains?: string[];
}

export interface SerializedCreateOrganizationOptions {
name: string;
allow_profiles_outside_organization?: boolean;
domain_data?: DomainData[];
/**
* @deprecated Use `domain_data` instead.
*/
domains?: string[];
}

Expand Down
10 changes: 10 additions & 0 deletions src/organizations/interfaces/domain-data.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// These are the only possible states to create an organization domain with
export enum DomainDataState {
Verified = 'verified',
Pending = 'pending',
}

export interface DomainData {
domain: string;
state: DomainDataState;
}
1 change: 1 addition & 0 deletions src/organizations/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './create-organization-options.interface';
export * from './domain-data.interface';
export * from './list-organizations-options.interface';
export * from './organization-domain.interface';
export * from './organization.interface';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { DomainData } from './domain-data.interface';

export interface UpdateOrganizationOptions {
organization: string;
name: string;
allowProfilesOutsideOrganization?: boolean;
domainData?: DomainData[];
/**
* @deprecated Use `domain_data` instead.
*/
domains?: string[];
}

export interface SerializedUpdateOrganizationOptions {
name: string;
allow_profiles_outside_organization?: boolean;
domain_data?: DomainData[];
/**
* @deprecated Use `domain_data` instead.
*/
domains?: string[];
}
94 changes: 71 additions & 23 deletions src/organizations/organizations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import createOrganization from './fixtures/create-organization.json';
import getOrganization from './fixtures/get-organization.json';
import listOrganizationsFixture from './fixtures/list-organizations.json';
import updateOrganization from './fixtures/update-organization.json';
import { DomainDataState } from './interfaces';

const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');

Expand Down Expand Up @@ -143,21 +144,44 @@ describe('Organizations', () => {
});

describe('with a valid payload', () => {
it('creates an organization', async () => {
fetchOnce(createOrganization, { status: 201 });
describe('with `domains`', () => {
it('creates an organization', async () => {
fetchOnce(createOrganization, { status: 201 });

const subject = await workos.organizations.createOrganization({
domains: ['example.com'],
name: 'Test Organization',
const subject = await workos.organizations.createOrganization({
domains: ['example.com'],
name: 'Test Organization',
});

expect(fetchBody()).toEqual({
domains: ['example.com'],
name: 'Test Organization',
});
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
expect(subject.name).toEqual('Test Organization');
expect(subject.domains).toHaveLength(1);
});
});

expect(fetchBody()).toEqual({
domains: ['example.com'],
name: 'Test Organization',
describe('with `domain_data`', () => {
it('creates an organization', async () => {
fetchOnce(createOrganization, { status: 201 });

const subject = await workos.organizations.createOrganization({
domainData: [
{ domain: 'example.com', state: DomainDataState.Verified },
],
name: 'Test Organization',
});

expect(fetchBody()).toEqual({
domain_data: [{ domain: 'example.com', state: 'verified' }],
name: 'Test Organization',
});
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
expect(subject.name).toEqual('Test Organization');
expect(subject.domains).toHaveLength(1);
});
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
expect(subject.name).toEqual('Test Organization');
expect(subject.domains).toHaveLength(1);
});
});

Expand Down Expand Up @@ -220,22 +244,46 @@ describe('Organizations', () => {

describe('updateOrganization', () => {
describe('with a valid payload', () => {
it('updates an organization', async () => {
fetchOnce(updateOrganization, { status: 201 });
describe('with `domains', () => {
it('updates an organization', async () => {
fetchOnce(updateOrganization, { status: 201 });

const subject = await workos.organizations.updateOrganization({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
domains: ['example.com'],
name: 'Test Organization 2',
const subject = await workos.organizations.updateOrganization({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
domains: ['example.com'],
name: 'Test Organization 2',
});

expect(fetchBody()).toEqual({
domains: ['example.com'],
name: 'Test Organization 2',
});
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
expect(subject.name).toEqual('Test Organization 2');
expect(subject.domains).toHaveLength(1);
});
});

expect(fetchBody()).toEqual({
domains: ['example.com'],
name: 'Test Organization 2',
describe('with `domain_data`', () => {
it('updates an organization', async () => {
fetchOnce(updateOrganization, { status: 201 });

const subject = await workos.organizations.updateOrganization({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
domainData: [
{ domain: 'example.com', state: DomainDataState.Verified },
],
name: 'Test Organization 2',
});

expect(fetchBody()).toEqual({
domain_data: [{ domain: 'example.com', state: 'verified' }],
name: 'Test Organization 2',
});
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
expect(subject.name).toEqual('Test Organization 2');
expect(subject.domains).toHaveLength(1);
});
expect(subject.id).toEqual('org_01EHT88Z8J8795GZNQ4ZP1J81T');
expect(subject.name).toEqual('Test Organization 2');
expect(subject.domains).toHaveLength(1);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const serializeCreateOrganizationOptions = (
): SerializedCreateOrganizationOptions => ({
name: options.name,
allow_profiles_outside_organization: options.allowProfilesOutsideOrganization,
domain_data: options.domainData,
domains: options.domains,
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const serializeUpdateOrganizationOptions = (
): SerializedUpdateOrganizationOptions => ({
name: options.name,
allow_profiles_outside_organization: options.allowProfilesOutsideOrganization,
domain_data: options.domainData,
domains: options.domains,
});

0 comments on commit 5443fbc

Please sign in to comment.