Skip to content

Commit

Permalink
tests: check if product is available
Browse files Browse the repository at this point in the history
  • Loading branch information
xabg2 committed Jan 31, 2025
1 parent a700a7f commit d25335e
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions test/drive/payments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { HttpClient } from '../../../src/shared/http/client';
const httpClient = HttpClient.create('');

describe('payments service', () => {

beforeEach(() => {
sinon.stub(HttpClient, 'create').returns(httpClient);
});
Expand All @@ -18,35 +17,49 @@ describe('payments service', () => {
});

describe('get products', () => {

it('should call with right params & return data', async () => {
// Arrange
const callStub = sinon.stub(httpClient, 'get').resolves({
content: 'true'
content: 'true',
});
const { client, headers } = clientAndHeadersWithToken();

// Act
const body = await client.getProducts();

// Assert
expect(callStub.firstCall.args).toEqual([
'/v3/stripe/products',
headers
]);
expect(callStub.firstCall.args).toEqual(['/v3/stripe/products', headers]);
expect(body).toEqual({
content: 'true'
content: 'true',
});
});
});

describe('check if product is available', () => {
it('should call with right params & return data', async () => {
const callStub = sinon.stub(httpClient, 'get').resolves({
featuresPerService: {
antivirus: false,
},
});
const { client, headers } = clientAndHeadersWithToken();

const body = await client.checkProductsUserAvailable();

expect(callStub.firstCall.args).toEqual(['/products', headers]);
expect(body).toEqual({
featuresPerService: {
antivirus: false,
},
});
});
});

describe('create payment session', () => {

it('should call with right params & return data', async () => {
// Arrange
const callStub = sinon.stub(httpClient, 'post').resolves({
id: 'ident'
id: 'ident',
});
const { client, headers } = clientAndHeadersWithToken();
const payload: CreatePaymentSessionPayload = {
Expand All @@ -55,7 +68,7 @@ describe('payments service', () => {
mode: StripeSessionMode.Payment,
priceId: '',
successUrl: '',
test: false
test: false,
};

// Act
Expand All @@ -72,26 +85,23 @@ describe('payments service', () => {
successUrl: payload.successUrl,
canceledUrl: payload.canceledUrl,
},
headers
headers,
]);
expect(body).toEqual({
id: 'ident'
id: 'ident',
});
});

});

});


function clientAndHeadersWithToken(
apiUrl = '',
clientName = 'c-name',
clientVersion = '0.1',
token = 'token'
token = 'token',
): {
client: Payments,
headers: object
client: Payments;
headers: object;
} {
const appDetails: AppDetails = {
clientName: clientName,
Expand Down

0 comments on commit d25335e

Please sign in to comment.