11import Client from "../client" ;
2- import Config , { RegionEnum } from "../config" ;
2+ import Config , { EnvironmentEnum , RegionEnum } from "../config" ;
33
44describe ( "API Client" , function ( ) : void {
55 test ( "should be able to make a request using basic auth" , async function ( ) : Promise < void > {
66 new Client ( {
77 username : process . env . ADYEN_USER ! ,
88 password : process . env . ADYEN_PASSWORD ! ,
9- environment : " TEST"
9+ environment : EnvironmentEnum . TEST
1010 } ) ;
1111 } ) ;
1212
1313 test ( "should create client with API key" , ( ) => {
1414 const client = new Client ( {
1515 apiKey : "ADYEN_API_KEY" ,
16- environment : " TEST"
16+ environment : EnvironmentEnum . TEST
1717 } ) ;
1818
1919 expect ( client . config . apiKey ) . toBe ( "ADYEN_API_KEY" ) ;
20+ expect ( client . config . environment ) . toBe ( EnvironmentEnum . TEST ) ;
2021 expect ( client . config . environment ) . toBe ( "TEST" ) ;
2122 expect ( client . config . marketPayEndpoint ) . toBe ( Client . MARKETPAY_ENDPOINT_TEST ) ;
2223 } ) ;
@@ -25,18 +26,18 @@ describe("API Client", function (): void {
2526 const client = new Client ( {
2627 username : "username" ,
2728 password : "password" ,
28- environment : " TEST"
29+ environment : EnvironmentEnum . TEST
2930 } ) ;
3031
3132 expect ( client . config . username ) . toBe ( "username" ) ;
3233 expect ( client . config . password ) . toBe ( "password" ) ;
33- expect ( client . config . environment ) . toBe ( " TEST" ) ;
34+ expect ( client . config . environment ) . toBe ( EnvironmentEnum . TEST ) ;
3435 } ) ;
3536
3637 test ( "should set application name" , ( ) => {
3738 const client = new Client ( {
3839 apiKey : "ADYEN_API_KEY" ,
39- environment : " TEST" ,
40+ environment : EnvironmentEnum . TEST ,
4041 applicationName : "my_application_name"
4142 } ) ;
4243
@@ -46,7 +47,7 @@ describe("API Client", function (): void {
4647 test ( "should define timeout in Config" , ( ) => {
4748 const client = new Client ( {
4849 apiKey : "ADYEN_API_KEY" ,
49- environment : " TEST" ,
50+ environment : EnvironmentEnum . TEST ,
5051 connectionTimeoutMillis : 30000
5152 } ) ;
5253
@@ -56,7 +57,7 @@ describe("API Client", function (): void {
5657 test ( "should set timeout" , ( ) => {
5758 const client = new Client ( {
5859 apiKey : "ADYEN_API_KEY" ,
59- environment : " TEST"
60+ environment : EnvironmentEnum . TEST
6061 } ) ;
6162
6263 client . setTimeouts ( 30000 ) ;
@@ -72,7 +73,7 @@ describe("API Client", function (): void {
7273 test ( "should throw error if environment is LIVE and region is invalid" , ( ) => {
7374 const config = new Config ( {
7475 apiKey : "ADYEN_API_KEY" ,
75- environment : " LIVE" ,
76+ environment : EnvironmentEnum . LIVE ,
7677 region : "INVALID" as RegionEnum ,
7778 liveEndpointUrlPrefix : "prefix"
7879 } ) ;
@@ -84,7 +85,7 @@ describe("API Client", function (): void {
8485 test ( "should set terminalApiCloudEndpoint for TEST region" , ( ) => {
8586 const config = new Config ( {
8687 apiKey : "ADYEN_API_KEY" ,
87- environment : " TEST"
88+ environment : EnvironmentEnum . TEST
8889 } ) ;
8990 const client = new Client ( config ) ;
9091 expect ( client . config . terminalApiCloudEndpoint ) . toBeDefined ( ) ;
@@ -94,7 +95,7 @@ describe("API Client", function (): void {
9495 test ( "should set terminalApiCloudEndpoint for LIVE region" , ( ) => {
9596 const config = new Config ( {
9697 apiKey : "ADYEN_API_KEY" ,
97- environment : " LIVE" ,
98+ environment : EnvironmentEnum . LIVE ,
9899 region : RegionEnum . US ,
99100 liveEndpointUrlPrefix : "prefix"
100101 } ) ;
@@ -106,7 +107,7 @@ describe("API Client", function (): void {
106107 test ( "should set and get custom http client" , ( ) => {
107108 const config = new Config ( {
108109 apiKey : "ADYEN_API_KEY" ,
109- environment : " TEST"
110+ environment : EnvironmentEnum . TEST
110111 } ) ;
111112 const client = new Client ( config ) ;
112113 const mockHttpClient = { request : jest . fn ( ) } ;
@@ -117,10 +118,42 @@ describe("API Client", function (): void {
117118 test ( "should set application name via setApplicationName" , ( ) => {
118119 const config = new Config ( {
119120 apiKey : "ADYEN_API_KEY" ,
120- environment : " TEST"
121+ environment : EnvironmentEnum . TEST
121122 } ) ;
122123 const client = new Client ( config ) ;
123124 client . setApplicationName ( "test_app" ) ;
124125 expect ( client . config . applicationName ) . toBe ( "test_app" ) ;
125126 } ) ;
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+
126158} ) ;
159+
0 commit comments