1
1
import Client from "../client" ;
2
- import Config , { RegionEnum } from "../config" ;
2
+ import Config , { EnvironmentEnum , RegionEnum } from "../config" ;
3
3
4
4
describe ( "API Client" , function ( ) : void {
5
5
test ( "should be able to make a request using basic auth" , async function ( ) : Promise < void > {
6
6
new Client ( {
7
7
username : process . env . ADYEN_USER ! ,
8
8
password : process . env . ADYEN_PASSWORD ! ,
9
- environment : " TEST"
9
+ environment : EnvironmentEnum . TEST
10
10
} ) ;
11
11
} ) ;
12
12
13
13
test ( "should create client with API key" , ( ) => {
14
14
const client = new Client ( {
15
15
apiKey : "ADYEN_API_KEY" ,
16
- environment : " TEST"
16
+ environment : EnvironmentEnum . TEST
17
17
} ) ;
18
18
19
19
expect ( client . config . apiKey ) . toBe ( "ADYEN_API_KEY" ) ;
20
+ expect ( client . config . environment ) . toBe ( EnvironmentEnum . TEST ) ;
20
21
expect ( client . config . environment ) . toBe ( "TEST" ) ;
21
22
expect ( client . config . marketPayEndpoint ) . toBe ( Client . MARKETPAY_ENDPOINT_TEST ) ;
22
23
} ) ;
@@ -25,18 +26,18 @@ describe("API Client", function (): void {
25
26
const client = new Client ( {
26
27
username : "username" ,
27
28
password : "password" ,
28
- environment : " TEST"
29
+ environment : EnvironmentEnum . TEST
29
30
} ) ;
30
31
31
32
expect ( client . config . username ) . toBe ( "username" ) ;
32
33
expect ( client . config . password ) . toBe ( "password" ) ;
33
- expect ( client . config . environment ) . toBe ( " TEST" ) ;
34
+ expect ( client . config . environment ) . toBe ( EnvironmentEnum . TEST ) ;
34
35
} ) ;
35
36
36
37
test ( "should set application name" , ( ) => {
37
38
const client = new Client ( {
38
39
apiKey : "ADYEN_API_KEY" ,
39
- environment : " TEST" ,
40
+ environment : EnvironmentEnum . TEST ,
40
41
applicationName : "my_application_name"
41
42
} ) ;
42
43
@@ -46,7 +47,7 @@ describe("API Client", function (): void {
46
47
test ( "should define timeout in Config" , ( ) => {
47
48
const client = new Client ( {
48
49
apiKey : "ADYEN_API_KEY" ,
49
- environment : " TEST" ,
50
+ environment : EnvironmentEnum . TEST ,
50
51
connectionTimeoutMillis : 30000
51
52
} ) ;
52
53
@@ -56,7 +57,7 @@ describe("API Client", function (): void {
56
57
test ( "should set timeout" , ( ) => {
57
58
const client = new Client ( {
58
59
apiKey : "ADYEN_API_KEY" ,
59
- environment : " TEST"
60
+ environment : EnvironmentEnum . TEST
60
61
} ) ;
61
62
62
63
client . setTimeouts ( 30000 ) ;
@@ -72,7 +73,7 @@ describe("API Client", function (): void {
72
73
test ( "should throw error if environment is LIVE and region is invalid" , ( ) => {
73
74
const config = new Config ( {
74
75
apiKey : "ADYEN_API_KEY" ,
75
- environment : " LIVE" ,
76
+ environment : EnvironmentEnum . LIVE ,
76
77
region : "INVALID" as RegionEnum ,
77
78
liveEndpointUrlPrefix : "prefix"
78
79
} ) ;
@@ -84,7 +85,7 @@ describe("API Client", function (): void {
84
85
test ( "should set terminalApiCloudEndpoint for TEST region" , ( ) => {
85
86
const config = new Config ( {
86
87
apiKey : "ADYEN_API_KEY" ,
87
- environment : " TEST"
88
+ environment : EnvironmentEnum . TEST
88
89
} ) ;
89
90
const client = new Client ( config ) ;
90
91
expect ( client . config . terminalApiCloudEndpoint ) . toBeDefined ( ) ;
@@ -94,7 +95,7 @@ describe("API Client", function (): void {
94
95
test ( "should set terminalApiCloudEndpoint for LIVE region" , ( ) => {
95
96
const config = new Config ( {
96
97
apiKey : "ADYEN_API_KEY" ,
97
- environment : " LIVE" ,
98
+ environment : EnvironmentEnum . LIVE ,
98
99
region : RegionEnum . US ,
99
100
liveEndpointUrlPrefix : "prefix"
100
101
} ) ;
@@ -106,7 +107,7 @@ describe("API Client", function (): void {
106
107
test ( "should set and get custom http client" , ( ) => {
107
108
const config = new Config ( {
108
109
apiKey : "ADYEN_API_KEY" ,
109
- environment : " TEST"
110
+ environment : EnvironmentEnum . TEST
110
111
} ) ;
111
112
const client = new Client ( config ) ;
112
113
const mockHttpClient = { request : jest . fn ( ) } ;
@@ -117,10 +118,42 @@ describe("API Client", function (): void {
117
118
test ( "should set application name via setApplicationName" , ( ) => {
118
119
const config = new Config ( {
119
120
apiKey : "ADYEN_API_KEY" ,
120
- environment : " TEST"
121
+ environment : EnvironmentEnum . TEST
121
122
} ) ;
122
123
const client = new Client ( config ) ;
123
124
client . setApplicationName ( "test_app" ) ;
124
125
expect ( client . config . applicationName ) . toBe ( "test_app" ) ;
125
126
} ) ;
127
+
128
+ test ( "should return true for valid environments" , ( ) => {
129
+ expect ( Config . isEnvironmentValid ( EnvironmentEnum . LIVE ) ) . toBe ( true ) ;
130
+ expect ( Config . isEnvironmentValid ( EnvironmentEnum . TEST ) ) . toBe ( true ) ;
131
+ } ) ;
132
+
133
+ test ( "should return false for invalid environments" , ( ) => {
134
+ // @ts -expect-error purposely passing invalid value
135
+ expect ( Config . isEnvironmentValid ( "INVALID" ) ) . toBe ( false ) ;
136
+ // @ts -expect-error purposely passing undefined
137
+ expect ( Config . isEnvironmentValid ( undefined ) ) . toBe ( false ) ;
138
+ // @ts -expect-error purposely passing null
139
+ expect ( Config . isEnvironmentValid ( null ) ) . toBe ( false ) ;
140
+ } ) ;
141
+
142
+ test ( "should return true for valid regions" , ( ) => {
143
+ expect ( Config . isRegionValid ( RegionEnum . EU ) ) . toBe ( true ) ;
144
+ expect ( Config . isRegionValid ( RegionEnum . AU ) ) . toBe ( true ) ;
145
+ expect ( Config . isRegionValid ( RegionEnum . US ) ) . toBe ( true ) ;
146
+ expect ( Config . isRegionValid ( RegionEnum . APSE ) ) . toBe ( true ) ;
147
+ } ) ;
148
+
149
+ test ( "should return false for invalid regions" , ( ) => {
150
+ // @ts -expect-error purposely passing invalid value
151
+ expect ( Config . isRegionValid ( "INVALID" ) ) . toBe ( false ) ;
152
+ // @ts -expect-error purposely passing undefined
153
+ expect ( Config . isRegionValid ( undefined ) ) . toBe ( false ) ;
154
+ // @ts -expect-error purposely passing null
155
+ expect ( Config . isRegionValid ( null ) ) . toBe ( false ) ;
156
+ } ) ;
157
+
126
158
} ) ;
159
+
0 commit comments