Skip to content

Commit

Permalink
feat(api): external connections made optional when updating items (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Jun 24, 2024
1 parent b1a55ea commit 3a94cfc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 90
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb-d08c3c586f46f155358104a907afa8300ce44a25814c1574c0f4344935c1b838.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb-aebc7faa75113d98ef7b57673cf7fce499c87b96afabe6c2ddc5e22badc3ef33.yml
15 changes: 13 additions & 2 deletions src/resources/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ export class Items extends APIResource {
/**
* This endpoint can be used to update properties on the Item.
*/
update(itemId: string, body: ItemUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Item> {
update(itemId: string, body?: ItemUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Item>;
update(itemId: string, options?: Core.RequestOptions): Core.APIPromise<Item>;
update(
itemId: string,
body: ItemUpdateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<Item> {
if (isRequestOptions(body)) {
return this.update(itemId, {}, body);
}
return this._client.put(`/items/${itemId}`, { body, ...options });
}

Expand Down Expand Up @@ -85,7 +94,9 @@ export interface ItemCreateParams {
}

export interface ItemUpdateParams {
external_connections: Array<ItemUpdateParams.ExternalConnection> | null;
external_connections?: Array<ItemUpdateParams.ExternalConnection> | null;

name?: string | null;
}

export namespace ItemUpdateParams {
Expand Down
18 changes: 7 additions & 11 deletions src/resources/plans/external-plan-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ import * as PlansAPI from './plans';

export class ExternalPlanID extends APIResource {
/**
* This endpoint is used to fetch [plan](../guides/concepts##plan-and-price)
* details given an external_plan_id identifier. It returns information about the
* prices included in the plan and their configuration, as well as the product that
* the plan is attached to.
*
* ## Serialized prices
* This endpoint can be used to update the `external_plan_id`, and `metadata` of an
* existing plan.
*
* Orb supports a few different pricing models out of the box. Each of these models
* is serialized differently in a given [Price](../guides/concepts#plan-and-price)
* object. The `model_type` field determines the key for the configuration object
* that is present. A detailed explanation of price types can be found in the
* [Price schema](../guides/concepts#plan-and-price).
* Other fields on a customer are currently immutable.
*/
update(
otherExternalPlanId: string,
Expand All @@ -44,6 +36,10 @@ export class ExternalPlanID extends APIResource {
* prices included in the plan and their configuration, as well as the product that
* the plan is attached to.
*
* If multiple plans are found to contain the specified external_plan_id, the
* active plans will take priority over archived ones, and among those, the
* endpoint will return the most recently created plan.
*
* ## Serialized prices
*
* Orb supports a few different pricing models out of the box. Each of these models
Expand Down
41 changes: 25 additions & 16 deletions tests/api-resources/items.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ describe('resource items', () => {
const response = await orb.items.create({ name: 'API requests' });
});

test('update: only required params', async () => {
const responsePromise = orb.items.update('string', {
external_connections: [
{ external_connection_name: 'stripe', external_entity_id: 'string' },
{ external_connection_name: 'stripe', external_entity_id: 'string' },
{ external_connection_name: 'stripe', external_entity_id: 'string' },
],
});
test('update', async () => {
const responsePromise = orb.items.update('string');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
Expand All @@ -41,14 +35,29 @@ describe('resource items', () => {
expect(dataAndResponse.response).toBe(rawResponse);
});

test('update: required and optional params', async () => {
const response = await orb.items.update('string', {
external_connections: [
{ external_connection_name: 'stripe', external_entity_id: 'string' },
{ external_connection_name: 'stripe', external_entity_id: 'string' },
{ external_connection_name: 'stripe', external_entity_id: 'string' },
],
});
test('update: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(orb.items.update('string', { path: '/_stainless_unknown_path' })).rejects.toThrow(
Orb.NotFoundError,
);
});

test('update: request options and params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
orb.items.update(
'string',
{
external_connections: [
{ external_connection_name: 'stripe', external_entity_id: 'string' },
{ external_connection_name: 'stripe', external_entity_id: 'string' },
{ external_connection_name: 'stripe', external_entity_id: 'string' },
],
name: 'string',
},
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(Orb.NotFoundError);
});

test('list', async () => {
Expand Down

0 comments on commit 3a94cfc

Please sign in to comment.