@@ -12,6 +12,7 @@ import {
12
12
NotInitializedErrorType ,
13
13
OrderFinalizationNotRequiredError ,
14
14
OrderRequestBody ,
15
+ PaymentIntegrationSelectors ,
15
16
PaymentIntegrationService ,
16
17
PaymentMethod ,
17
18
PaymentMethodCancelledError ,
@@ -193,7 +194,7 @@ describe('KlarnaV2PaymentStrategy', () => {
193
194
it ( 'loads payments widget' , ( ) => {
194
195
expect ( klarnaPayments . init ) . toHaveBeenCalledWith ( { client_token : 'foo' } ) ;
195
196
expect ( klarnaPayments . load ) . toHaveBeenCalledWith (
196
- { container : '#container' , payment_method_category : paymentMethod . id } ,
197
+ { container : '#container' , payment_method_category : paymentMethod . gateway } ,
197
198
expect . any ( Function ) ,
198
199
) ;
199
200
expect ( klarnaPayments . load ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -202,6 +203,35 @@ describe('KlarnaV2PaymentStrategy', () => {
202
203
it ( 'triggers callback with response' , ( ) => {
203
204
expect ( onLoad ) . toHaveBeenCalledWith ( { show_form : true } ) ;
204
205
} ) ;
206
+
207
+ it ( 'calls loadPaymentsWidget when subscription is triggered and isPaymentMethodInitialized is true' , async ( ) => {
208
+ const loadPaymentsWidgetMock = jest
209
+ . spyOn (
210
+ strategy as unknown as { loadPaymentsWidget : jest . Mock } ,
211
+ 'loadPaymentsWidget' ,
212
+ )
213
+ . mockImplementation ( jest . fn ( ) ) ;
214
+
215
+ const subscribeMock = jest . spyOn ( paymentIntegrationService , 'subscribe' ) ;
216
+
217
+ await strategy . initialize ( {
218
+ methodId : paymentMethod . id ,
219
+ gatewayId : paymentMethod . gateway ,
220
+ klarnav2 : { container : '#container' } ,
221
+ } ) ;
222
+
223
+ const subscriber = subscribeMock . mock . calls [ 0 ] [ 0 ] ;
224
+
225
+ subscriber ( {
226
+ isPaymentMethodInitialized : ( ) => true ,
227
+ } as unknown as PaymentIntegrationSelectors ) ;
228
+
229
+ expect ( loadPaymentsWidgetMock ) . toHaveBeenCalledWith ( {
230
+ methodId : paymentMethod . id ,
231
+ gatewayId : paymentMethod . gateway ,
232
+ klarnav2 : { container : '#container' } ,
233
+ } ) ;
234
+ } ) ;
205
235
} ) ;
206
236
207
237
describe ( '#execute()' , ( ) => {
@@ -221,7 +251,7 @@ describe('KlarnaV2PaymentStrategy', () => {
221
251
await strategy . execute ( payload ) ;
222
252
223
253
expect ( klarnaPayments . authorize ) . toHaveBeenCalledWith (
224
- { payment_method_category : paymentMethod . id } ,
254
+ { payment_method_category : paymentMethod . gateway } ,
225
255
getKlarnaV2UpdateSessionParamsPhone ( ) ,
226
256
expect . any ( Function ) ,
227
257
) ;
@@ -292,7 +322,7 @@ describe('KlarnaV2PaymentStrategy', () => {
292
322
await strategy . execute ( payload ) ;
293
323
294
324
expect ( klarnaPayments . authorize ) . toHaveBeenCalledWith (
295
- { payment_method_category : paymentMethod . id } ,
325
+ { payment_method_category : paymentMethod . gateway } ,
296
326
getKlarnaV2UpdateSessionParamsPhone ( ) ,
297
327
expect . any ( Function ) ,
298
328
) ;
@@ -328,7 +358,7 @@ describe('KlarnaV2PaymentStrategy', () => {
328
358
await strategy . execute ( payload ) ;
329
359
330
360
expect ( klarnaPayments . authorize ) . toHaveBeenCalledWith (
331
- { payment_method_category : paymentMethod . id } ,
361
+ { payment_method_category : paymentMethod . gateway } ,
332
362
getKlarnaV2UpdateSessionParamsForOC ( ) ,
333
363
expect . any ( Function ) ,
334
364
) ;
@@ -370,7 +400,7 @@ describe('KlarnaV2PaymentStrategy', () => {
370
400
await strategy . execute ( payload ) ;
371
401
372
402
expect ( klarnaPayments . authorize ) . toHaveBeenCalledWith (
373
- { payment_method_category : paymentMethod . id } ,
403
+ { payment_method_category : paymentMethod . gateway } ,
374
404
getKlarnaV2UpdateSessionParams ( ) ,
375
405
expect . any ( Function ) ,
376
406
) ;
@@ -422,7 +452,7 @@ describe('KlarnaV2PaymentStrategy', () => {
422
452
await strategy . execute ( payload ) ;
423
453
424
454
expect ( klarnaPayments . authorize ) . toHaveBeenCalledWith (
425
- { payment_method_category : paymentMethod . id } ,
455
+ { payment_method_category : paymentMethod . gateway } ,
426
456
{ } ,
427
457
expect . any ( Function ) ,
428
458
) ;
0 commit comments