File tree Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Expand file tree Collapse file tree 3 files changed +37
-4
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import HttpClientException from "../httpClient/httpClientException";
7
7
import { binlookup } from "../typings" ;
8
8
import { ApiConstants } from "../constants/apiConstants" ;
9
9
import { paymentMethodsSuccess } from "../__mocks__/checkout/paymentMethodsSuccess" ;
10
-
10
+ import Config from "../config" ;
11
11
12
12
beforeEach ( ( ) : void => {
13
13
nock . cleanAll ( ) ;
@@ -177,4 +177,26 @@ describe("HTTP Client", function (): void {
177
177
expect ( response . paymentMethods ) . toBeTruthy ( ) ;
178
178
} ) ;
179
179
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 {
11
11
terminalApiLocalEndpoint ?: string ;
12
12
}
13
13
14
+ const DEFAULT_TIMEOUT = 30000 ; // Default timeout value (30 sec)
15
+
14
16
class Config {
15
17
public username ?: string ;
16
18
public password ?: string ;
@@ -31,7 +33,8 @@ class Config {
31
33
if ( options . marketPayEndpoint ) this . marketPayEndpoint = options . marketPayEndpoint ;
32
34
if ( options . applicationName ) this . applicationName = options . applicationName ;
33
35
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 ;
35
38
if ( options . certificatePath ) this . certificatePath = options . certificatePath ;
36
39
if ( options . terminalApiCloudEndpoint ) this . terminalApiCloudEndpoint = options . terminalApiCloudEndpoint ;
37
40
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 {
118
118
requestOptions . headers [ ApiConstants . ADYEN_LIBRARY_NAME ] = LibraryConstants . LIB_NAME ;
119
119
requestOptions . headers [ ApiConstants . ADYEN_LIBRARY_VERSION ] = LibraryConstants . LIB_VERSION ;
120
120
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 ;
122
130
}
123
131
124
132
private getQuery ( params : [ string , string ] [ ] ) : string {
You can’t perform that action at this time.
0 commit comments