1
+ import Service from "../service" ;
2
+ import Client from "../client" ;
3
+ import Config from "../config" ;
4
+
5
+ class TestService extends Service {
6
+ public constructor ( client : Client ) {
7
+ super ( client ) ;
8
+ }
9
+ public testCreateBaseUrl ( url : string ) : string {
10
+ return this . createBaseUrl ( url ) ;
11
+ }
12
+ }
13
+
14
+ describe ( "Service" , ( ) => {
15
+ let client : Client ;
16
+
17
+ beforeEach ( ( ) => {
18
+ // Default config for each test
19
+ client = new Client ( new Config ( {
20
+ apiKey : "test_key" ,
21
+ environment : "TEST"
22
+ } ) ) ;
23
+ } ) ;
24
+
25
+ it ( "should replace -live with -test for non-LIVE environments" , ( ) => {
26
+ const service = new TestService ( client ) ;
27
+ const url = "https://pal-live.adyen.com/pal/servlet/" ;
28
+ expect ( service . testCreateBaseUrl ( url ) ) . toBe ( "https://pal-test.adyen.com/pal/servlet/" ) ;
29
+ } ) ;
30
+
31
+ it ( "should throw error if liveEndpointUrlPrefix is undefined in LIVE environment" , ( ) => {
32
+ // create Client for TEST environment without liveEndpointUrlPrefix
33
+ const config = new Config ( {
34
+ apiKey : "test_key" ,
35
+ environment : "TEST"
36
+ } ) ;
37
+ client = new Client ( config ) ;
38
+ // change to LIVE
39
+ client . config . environment = "LIVE" ;
40
+
41
+ const service = new TestService ( client ) ;
42
+ expect ( ( ) => service . testCreateBaseUrl ( "https://pal-live.adyen.com/pal/servlet/" ) )
43
+ . toThrow ( "Live endpoint URL prefix must be provided for LIVE environment." ) ;
44
+ } ) ;
45
+
46
+ it ( "should throw error if liveEndpointUrlPrefix is empty for pal- URLs" , ( ) => {
47
+ // create Client for TEST environment without liveEndpointUrlPrefix
48
+ const config = new Config ( {
49
+ apiKey : "test_key" ,
50
+ environment : "TEST" ,
51
+ liveEndpointUrlPrefix : ""
52
+ } ) ;
53
+ client = new Client ( config ) ;
54
+ // change to LIVE
55
+ client . config . environment = "LIVE" ;
56
+
57
+ const service = new TestService ( client ) ;
58
+ expect ( ( ) => service . testCreateBaseUrl ( "https://pal-live.adyen.com/pal/servlet/" ) )
59
+ . toThrow ( "Live endpoint URL prefix must be provided for LIVE environment." ) ;
60
+ } ) ;
61
+
62
+ it ( "should replace pal-test with pal-live using liveEndpointUrlPrefix" , ( ) => {
63
+ const config = new Config ( {
64
+ apiKey : "test_key" ,
65
+ environment : "LIVE" ,
66
+ liveEndpointUrlPrefix : "mycompany"
67
+ } ) ;
68
+ client = new Client ( config ) ;
69
+
70
+ const service = new TestService ( client ) ;
71
+ const url = "https://pal-test.adyen.com/pal/servlet/" ;
72
+ expect ( service . testCreateBaseUrl ( url ) ) . toBe (
73
+ "https://mycompany-pal-live.adyenpayments.com/pal/servlet/"
74
+ ) ;
75
+ } ) ;
76
+
77
+ it ( "should throw error if liveEndpointUrlPrefix is empty for checkout- URLs" , ( ) => {
78
+ // create Client for TEST environment without liveEndpointUrlPrefix
79
+ const config = new Config ( {
80
+ apiKey : "test_key" ,
81
+ environment : "TEST" ,
82
+ liveEndpointUrlPrefix : ""
83
+ } ) ;
84
+ client = new Client ( config ) ;
85
+ // change to LIVE
86
+ client . config . environment = "LIVE" ;
87
+
88
+ const service = new TestService ( client ) ;
89
+ expect ( ( ) => service . testCreateBaseUrl ( "https://checkout-test.adyen.com/" ) )
90
+ . toThrow ( "Live endpoint URL prefix must be provided for LIVE environment." ) ;
91
+ } ) ;
92
+
93
+ it ( "should replace checkout-test with checkout-live using liveEndpointUrlPrefix" , ( ) => {
94
+ const config = new Config ( {
95
+ apiKey : "test_key" ,
96
+ environment : "LIVE" ,
97
+ liveEndpointUrlPrefix : "mycompany"
98
+ } ) ;
99
+ client = new Client ( config ) ;
100
+
101
+ const service = new TestService ( client ) ;
102
+ const url = "https://checkout-test.adyen.com/" ;
103
+ expect ( service . testCreateBaseUrl ( url ) ) . toBe (
104
+ "https://mycompany-checkout-live.adyenpayments.com/checkout/"
105
+ ) ;
106
+ } ) ;
107
+
108
+ it ( "should replace checkout-test with checkout-live for possdk/v68 using liveEndpointUrlPrefix" , ( ) => {
109
+ const config = new Config ( {
110
+ apiKey : "test_key" ,
111
+ environment : "LIVE" ,
112
+ liveEndpointUrlPrefix : "mycompany"
113
+ } ) ;
114
+ client = new Client ( config ) ;
115
+
116
+ const service = new TestService ( client ) ;
117
+ const url = "https://checkout-test.adyen.com/possdk/v68" ;
118
+ expect ( service . testCreateBaseUrl ( url ) ) . toBe (
119
+ "https://mycompany-checkout-live.adyenpayments.com/possdk/v68"
120
+ ) ;
121
+ } ) ;
122
+
123
+ it ( "should replace -test with -live for other URLs" , ( ) => {
124
+ const config = new Config ( {
125
+ apiKey : "test_key" ,
126
+ environment : "LIVE" ,
127
+ liveEndpointUrlPrefix : "mycompany"
128
+ } ) ;
129
+ client = new Client ( config ) ;
130
+
131
+ const service = new TestService ( client ) ;
132
+ const url = "https://some-test.adyen.com/api/" ;
133
+ expect ( service . testCreateBaseUrl ( url ) ) . toBe ( "https://some-live.adyen.com/api/" ) ;
134
+ } ) ;
135
+ } ) ;
0 commit comments