products.test.ts•5.39 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: 'My Bearer Token',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});
describe('resource products', () => {
test('create: only required params', async () => {
const responsePromise = client.products.create({
price: {
currency: 'AED',
discount: 0,
price: 0,
purchasing_power_parity: true,
type: 'one_time_price',
},
tax_category: 'digital_products',
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('create: required and optional params', async () => {
const response = await client.products.create({
price: {
currency: 'AED',
discount: 0,
price: 0,
purchasing_power_parity: true,
type: 'one_time_price',
pay_what_you_want: true,
suggested_price: 0,
tax_inclusive: true,
},
tax_category: 'digital_products',
addons: ['string'],
brand_id: 'brand_id',
description: 'description',
digital_product_delivery: { external_url: 'external_url', instructions: 'instructions' },
license_key_activation_message: 'license_key_activation_message',
license_key_activations_limit: 0,
license_key_duration: { count: 0, interval: 'Day' },
license_key_enabled: true,
metadata: { foo: 'string' },
name: 'name',
});
});
test('retrieve', async () => {
const responsePromise = client.products.retrieve('id');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('update', async () => {
const responsePromise = client.products.update('id', {});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('list', async () => {
const responsePromise = client.products.list();
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('list: 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(
client.products.list(
{ archived: true, brand_id: 'brand_id', page_number: 0, page_size: 0, recurring: true },
{ path: '/_stainless_unknown_path' },
),
).rejects.toThrow(DodoPayments.NotFoundError);
});
test('archive', async () => {
const responsePromise = client.products.archive('id');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('unarchive', async () => {
const responsePromise = client.products.unarchive('id');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('updateFiles: only required params', async () => {
const responsePromise = client.products.updateFiles('id', { file_name: 'file_name' });
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});
test('updateFiles: required and optional params', async () => {
const response = await client.products.updateFiles('id', { file_name: 'file_name' });
});
});