Skip to content

Commit

Permalink
tests: getInvoices
Browse files Browse the repository at this point in the history
  • Loading branch information
xabg2 committed Jan 31, 2025
1 parent d25335e commit 06af397
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion test/drive/payments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sinon from 'sinon';
import { ApiSecurity, AppDetails } from '../../../src/shared';
import { headersWithToken } from '../../../src/shared/headers';
import { Payments } from '../../../src/drive';
import { CreatePaymentSessionPayload, StripeSessionMode } from '../../../src/drive/payments/types';
import { CreatePaymentSessionPayload, StripeSessionMode, UserType } from '../../../src/drive/payments/types';
import { HttpClient } from '../../../src/shared/http/client';

const httpClient = HttpClient.create('');
Expand Down Expand Up @@ -35,6 +35,61 @@ describe('payments service', () => {
});
});

describe('getInvoices', () => {
afterEach(() => {
sinon.restore();
});

it('should call with right params & return data', async () => {
const callStub = sinon.stub(httpClient, 'get').resolves([
{ id: 'invoice_123', amount: 1000 },
{ id: 'invoice_456', amount: 2000 },
]);

const { client, headers } = clientAndHeadersWithToken();

const params = {
subscriptionId: 'sub_789',
startingAfter: 'invoice_123',
userType: UserType.Individual,
limit: 10,
};

const invoices = await client.getInvoices(params);

const expectedQuery = new URLSearchParams({
subscription: 'sub_789',
starting_after: 'invoice_123',
userType: UserType.Individual,
limit: '10',
}).toString();

expect(callStub.firstCall.args).toEqual([`/invoices?${expectedQuery}`, headers]);

expect(invoices).toEqual([
{ id: 'invoice_123', amount: 1000 },
{ id: 'invoice_456', amount: 2000 },
]);
});

it('should handle missing optional parameters correctly', async () => {
const callStub = sinon.stub(httpClient, 'get').resolves([]);

const { client, headers } = clientAndHeadersWithToken();

const params = {};

const expectedQuery = new URLSearchParams({
userType: UserType.Individual,
}).toString();

const invoices = await client.getInvoices(params as any);

expect(callStub.firstCall.args).toEqual([`/invoices?${expectedQuery}`, headers]);
expect(invoices).toEqual([]);
});
});

describe('check if product is available', () => {
it('should call with right params & return data', async () => {
const callStub = sinon.stub(httpClient, 'get').resolves({
Expand Down

0 comments on commit 06af397

Please sign in to comment.