Skip to content

Commit

Permalink
test: update option test
Browse files Browse the repository at this point in the history
  • Loading branch information
gasspper committed Jul 9, 2024
1 parent fd304d1 commit 35d7606
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/common/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import axios from 'axios';
import RequestService from '../../lib/transbank/common/request_service';
import { CreateRequest } from '../../lib/transbank/webpay/webpay_plus/requests';
import { Options, Environment } from '../../lib';

test('creates Options object', () => {
let options = new Options('123456', 'asdfg', Environment.Integration);
expect(options.commerceCode).toBe('123456');
expect(options.apiKey).toBe('asdfg');
expect(options.environment).toBe(Environment.Integration);
});

test('creates Options object with default timeout', () => {
let options = new Options('123456', 'asdfg', Environment.Integration);
expect(options.timeout).toBe(600000);
});

test('the timeout parameter is set successfully', async () => {
const request = new CreateRequest(
'ordenCompra12345678',
'sesion1234557545',
10000,
'https://return.url'
);
const options = new Options(
'597055555532',
'579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C',
Environment.Integration,
20
);

const handleTimeout = (
resolve: (value?: unknown) => void,
reject: (reason?: any) => void
): void => {
setTimeout(() => {
reject({ code: 'ECONNABORTED', message: 'timeout of 20ms exceeded' });
}, 2000);
};

jest.spyOn(axios, 'request').mockImplementation(() => {
return new Promise(handleTimeout);
});

await expect(RequestService.perform(request, options)).rejects.toThrow(
'AxiosError: timeout of 20ms exceeded'
);

(axios.request as jest.Mock).mockRestore();
});

0 comments on commit 35d7606

Please sign in to comment.