Skip to content

Commit

Permalink
Remove org Stripe customer ID setter/getter (#1160)
Browse files Browse the repository at this point in the history
## Description

The same thing can be accomplished with the
`organizations.updateOrganization` function.

## 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.
  • Loading branch information
dandorman authored Nov 8, 2024
1 parent d6e32e1 commit a7431f9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 101 deletions.
17 changes: 0 additions & 17 deletions src/organizations/fixtures/get-stripe-customer-id.json

This file was deleted.

This file was deleted.

82 changes: 15 additions & 67 deletions src/organizations/organizations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import clearStripeCustomerId from './fixtures/clear-stripe-customer-id.json';
import createOrganizationInvalid from './fixtures/create-organization-invalid.json';
import createOrganization from './fixtures/create-organization.json';
import getOrganization from './fixtures/get-organization.json';
import getStripeCustomerId from './fixtures/get-stripe-customer-id.json';
import listOrganizationsFixture from './fixtures/list-organizations.json';
import updateOrganization from './fixtures/update-organization.json';
import setStripeCustomerId from './fixtures/set-stripe-customer-id.json';
Expand Down Expand Up @@ -297,42 +296,8 @@ describe('Organizations', () => {
});
});
});
});

describe('setStripeCustomerId', () => {
describe('with a valid payload', () => {
it('updates the organization’s Stripe customer ID', async () => {
fetchOnce(setStripeCustomerId);

const subject = await workos.organizations.setStripeCustomerId({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
});

expect(fetchBody()).toEqual({
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
});

expect(subject).toBe('cus_MX8J9nfK4lP2Yw');
});

it('clears the organization’s Stripe customer ID with a `null` value', async () => {
fetchOnce(clearStripeCustomerId);

const subject = await workos.organizations.setStripeCustomerId({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
stripeCustomerId: null,
});

expect(fetchBody()).toEqual({
stripe_customer_id: null,
});

expect(subject).toBeUndefined();
});
});

describe('when set via `updateOrganization`', () => {
describe('when given `stripeCustomerId`', () => {
it('updates the organization’s Stripe customer ID', async () => {
fetchOnce(setStripeCustomerId);

Expand Down Expand Up @@ -362,42 +327,25 @@ describe('Organizations', () => {

expect(subject.stripeCustomerId).toBeUndefined();
});
});

describe('when the feature is not enabled', () => {
it('returns an error', async () => {
fetchOnce(setStripeCustomerIdDisabled, { status: 422 });
describe('when the feature is not enabled', () => {
it('returns an error', async () => {
fetchOnce(setStripeCustomerIdDisabled, { status: 422 });

await expect(
workos.organizations.setStripeCustomerId({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
}),
).rejects.toThrowError(
'stripe_customer_id is not enabled for this environment',
);
await expect(
workos.organizations.updateOrganization({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
stripeCustomerId: 'cus_MX8J9nfK4lP2Yw',
}),
).rejects.toThrowError(
'stripe_customer_id is not enabled for this environment',
);

expect(fetchBody()).toEqual({
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
expect(fetchBody()).toEqual({
stripe_customer_id: 'cus_MX8J9nfK4lP2Yw',
});
});
});
});
});

describe('getStripeCustomerId', () => {
it('returns the organization’s Stripe customer ID', async () => {
fetchOnce(getStripeCustomerId);

const subject = await workos.organizations.setStripeCustomerId({
organization: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
stripeCustomerId: null,
});

expect(fetchURL()).toContain(
'/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T',
);

expect(subject).toEqual('cus_MX8J9nfK4lP2Yw');
});
});
});
13 changes: 0 additions & 13 deletions src/organizations/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from './serializers';

import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize';
import { SetStripeCustomerIdOptions } from './interfaces/set-stripe-customer-id-options.interface';

export class Organizations {
constructor(private readonly workos: WorkOS) {}
Expand Down Expand Up @@ -78,16 +77,4 @@ export class Organizations {

return deserializeOrganization(data);
}

async setStripeCustomerId(
options: SetStripeCustomerIdOptions,
): Promise<string | undefined> {
const updatedOrganization = await this.updateOrganization(options);
return updatedOrganization.stripeCustomerId;
}

async getStripeCustomerId(id: string): Promise<string | undefined> {
const organization = await this.getOrganization(id);
return organization.stripeCustomerId;
}
}

0 comments on commit a7431f9

Please sign in to comment.