File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import HttpClientException from "../httpClient/httpClientException";
77import { binlookup } from "../typings" ;
88import { ApiConstants } from "../constants/apiConstants" ;
99import { paymentMethodsSuccess } from "../__mocks__/checkout/paymentMethodsSuccess" ;
10-
10+ import Config from "../config" ;
1111
1212beforeEach ( ( ) : void => {
1313 nock . cleanAll ( ) ;
@@ -177,4 +177,26 @@ describe("HTTP Client", function (): void {
177177 expect ( response . paymentMethods ) . toBeTruthy ( ) ;
178178 } ) ;
179179
180- } ) ;
180+ } ) ;
181+
182+ describe ( 'Config class' , ( ) => {
183+ const DEFAULT_TIMEOUT = 30000 ; // Define the default timeout value
184+
185+ test ( 'should set default timeout when no timeout is provided' , ( ) => {
186+ // Instantiate the Config class without passing a timeout
187+ const config = new Config ( ) ;
188+
189+ // Expect that the timeout is set to the default value (30000)
190+ expect ( config . connectionTimeoutMillis ) . toBe ( DEFAULT_TIMEOUT ) ;
191+ } ) ;
192+
193+ test ( 'should set custom timeout when provided' , ( ) => {
194+ // Instantiate the Config class with a custom timeout
195+ const customTimeout = 50000 ;
196+ const config = new Config ( { connectionTimeoutMillis : customTimeout } ) ;
197+
198+ // Expect that the timeout is set to the custom value (50000)
199+ expect ( config . connectionTimeoutMillis ) . toBe ( customTimeout ) ;
200+ } ) ;
201+ } ) ;
202+
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ interface ConfigConstructor {
1111 terminalApiLocalEndpoint ?: string ;
1212}
1313
14+ const DEFAULT_TIMEOUT = 30000 ; // Default timeout value (30 sec)
15+
1416class Config {
1517 public username ?: string ;
1618 public password ?: string ;
@@ -31,7 +33,8 @@ class Config {
3133 if ( options . marketPayEndpoint ) this . marketPayEndpoint = options . marketPayEndpoint ;
3234 if ( options . applicationName ) this . applicationName = options . applicationName ;
3335 if ( options . apiKey ) this . apiKey = options . apiKey ;
34- if ( options . connectionTimeoutMillis ) this . connectionTimeoutMillis = options . connectionTimeoutMillis || 30000 ;
36+ // Set the timeout to DEFAULT_TIMEOUT if not provided
37+ this . connectionTimeoutMillis = options . connectionTimeoutMillis ?? DEFAULT_TIMEOUT ;
3538 if ( options . certificatePath ) this . certificatePath = options . certificatePath ;
3639 if ( options . terminalApiCloudEndpoint ) this . terminalApiCloudEndpoint = options . terminalApiCloudEndpoint ;
3740 if ( options . terminalApiLocalEndpoint ) this . terminalApiLocalEndpoint = options . terminalApiLocalEndpoint ;
Original file line number Diff line number Diff line change @@ -118,7 +118,15 @@ class HttpURLConnectionClient implements ClientInterface {
118118 requestOptions . headers [ ApiConstants . ADYEN_LIBRARY_NAME ] = LibraryConstants . LIB_NAME ;
119119 requestOptions . headers [ ApiConstants . ADYEN_LIBRARY_VERSION ] = LibraryConstants . LIB_VERSION ;
120120
121- return httpsRequest ( requestOptions ) ;
121+ // create a new ClientRequest object
122+ const req = httpsRequest ( requestOptions ) ;
123+
124+ // set the timeout on the ClientRequest instance
125+ if ( requestOptions . timeout ) {
126+ req . setTimeout ( requestOptions . timeout ) ;
127+ }
128+
129+ return req ;
122130 }
123131
124132 private getQuery ( params : [ string , string ] [ ] ) : string {
You can’t perform that action at this time.
0 commit comments