1
1
import nock , { Interceptor } from "nock" ;
2
2
import Client from "../client" ;
3
3
import { createClient } from "../__mocks__/base" ;
4
- import { BinLookupAPI } from "../services" ;
4
+ import { BinLookupAPI , CheckoutAPI } from "../services" ;
5
5
import ApiException from "../services/exception/apiException" ;
6
6
import HttpClientException from "../httpClient/httpClientException" ;
7
7
import { binlookup } from "../typings" ;
8
8
import { ApiConstants } from "../constants/apiConstants" ;
9
+ import { paymentMethodsSuccess } from "../__mocks__/checkout/paymentMethodsSuccess" ;
10
+
9
11
10
12
beforeEach ( ( ) : void => {
11
13
nock . cleanAll ( ) ;
@@ -98,6 +100,81 @@ describe("HTTP Client", function (): void {
98
100
const requestOptions = { headers : { foo : "bar" } } ;
99
101
const response = await binLookupService . get3dsAvailability ( threeDSAvailabilityRequest , requestOptions ) ;
100
102
expect ( response ) . toEqual < binlookup . ThreeDSAvailabilityResponse > ( threeDSAvailabilitySuccessResponse ) ;
103
+
104
+ console . log ( "requestOptions" , requestOptions ) ;
101
105
} ) ;
102
106
107
+ test ( "should add default applicationInfo to the headers" , async ( ) : Promise < void > => {
108
+ const client = createClient ( ) ;
109
+ const checkout = new CheckoutAPI ( client ) ;
110
+
111
+ const expectedUserAgent = `adyen-node-api-library/26.1.0` ;
112
+ const expectedLibraryName = `adyen-node-api-library` ;
113
+ const expectedLibraryVersion = `26.1.0` ;
114
+
115
+ const scope = nock ( "https://checkout-test.adyen.com/v71" , {
116
+ reqheaders : {
117
+ 'adyen-library-name' : ( headerValue ) => {
118
+ expect ( headerValue ) . toBeTruthy ( ) ;
119
+ expect ( headerValue ) . toEqual ( expectedLibraryName ) ;
120
+ return true ;
121
+ } ,
122
+ 'adyen-library-version' : ( headerValue ) => {
123
+ expect ( headerValue ) . toBeTruthy ( ) ;
124
+ expect ( headerValue ) . toEqual ( expectedLibraryVersion ) ;
125
+ expect
126
+ return true ;
127
+ } ,
128
+ 'user-agent' : ( headerValue ) => {
129
+ expect ( headerValue ) . toBeTruthy ( ) ;
130
+ expect ( headerValue ) . toEqual ( expectedUserAgent ) ;
131
+ expect
132
+ return true ;
133
+ }
134
+ }
135
+ } ) ;
136
+
137
+ scope . post ( "/paymentMethods" ) . reply ( 200 , paymentMethodsSuccess ) ;
138
+ const response = await checkout . PaymentsApi . paymentMethods ( { "merchantAccount" : "testMerchantAccount" } ) ;
139
+
140
+ expect ( response . paymentMethods ) . toBeTruthy ( ) ;
141
+ } ) ;
142
+
143
+ test ( "should add custom applicationInfo to the headers" , async ( ) : Promise < void > => {
144
+ const client = createClient ( ) ;
145
+ client . config . applicationName = "testApp" ;
146
+ const checkout = new CheckoutAPI ( client ) ;
147
+
148
+ const expectedUserAgent = `testApp adyen-node-api-library/26.1.0` ; // include applicationName too
149
+ const expectedLibraryName = `adyen-node-api-library` ;
150
+ const expectedLibraryVersion = `26.1.0` ;
151
+
152
+ const scope = nock ( "https://checkout-test.adyen.com/v71" , {
153
+ reqheaders : {
154
+ 'adyen-library-name' : ( headerValue ) => {
155
+ expect ( headerValue ) . toBeTruthy ( ) ;
156
+ expect ( headerValue ) . toEqual ( expectedLibraryName ) ;
157
+ return true ;
158
+ } ,
159
+ 'adyen-library-version' : ( headerValue ) => {
160
+ expect ( headerValue ) . toBeTruthy ( ) ;
161
+ expect ( headerValue ) . toEqual ( expectedLibraryVersion ) ;
162
+ expect
163
+ return true ;
164
+ } ,
165
+ 'user-agent' : ( headerValue ) => {
166
+ expect ( headerValue ) . toBeTruthy ( ) ;
167
+ expect ( headerValue ) . toEqual ( expectedUserAgent ) ;
168
+ expect
169
+ return true ;
170
+ }
171
+ }
172
+ } ) ;
173
+
174
+ scope . post ( "/paymentMethods" ) . reply ( 200 , paymentMethodsSuccess ) ;
175
+ const response = await checkout . PaymentsApi . paymentMethods ( { "merchantAccount" : "testMerchantAccount" } ) ;
176
+
177
+ expect ( response . paymentMethods ) . toBeTruthy ( ) ;
178
+ } ) ;
179
+
103
180
} ) ;
0 commit comments