@@ -11,9 +11,11 @@ import {
1111 getBraintree ,
1212 getDataCollectorMock ,
1313 getDeviceDataMock ,
14+ getPaymentSuccessPayload ,
1415 getVisaCheckoutMock ,
1516 getVisaCheckoutSDKMock ,
1617 VisaCheckoutHostWindow ,
18+ VisaCheckoutPaymentSuccessPayload ,
1719 VisaCheckoutSDK ,
1820} from '@bigcommerce/checkout-sdk/braintree-utils' ;
1921import {
@@ -41,6 +43,7 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
4143 let braintreeVisaCheckoutButtonElement : HTMLDivElement ;
4244 let dataCollector : BraintreeDataCollector ;
4345 let braintreeSDKVersionManager : BraintreeSDKVersionManager ;
46+ let visaPayload : VisaCheckoutPaymentSuccessPayload ;
4447
4548 const defaultContainerId = 'braintree-visa-checkout-button-mock-id' ;
4649
@@ -54,6 +57,8 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
5457 } ;
5558
5659 beforeEach ( ( ) => {
60+ visaPayload = getPaymentSuccessPayload ( ) ;
61+
5762 mockWindow = { } as VisaCheckoutHostWindow & BraintreeHostWindow ;
5863
5964 dataCollector = getDataCollectorMock ( ) ;
@@ -91,29 +96,19 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
9196 jest . spyOn ( paymentIntegrationService . getState ( ) , 'getPaymentMethodOrThrow' ) . mockReturnValue (
9297 paymentMethodMock ,
9398 ) ;
94- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
95- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
96- // @ts -ignore
97- jest . spyOn ( paymentIntegrationService , 'loadCheckout' ) . mockReturnValue ( true ) ;
99+ jest . spyOn ( paymentIntegrationService , 'loadCheckout' ) ;
98100
99101 jest . spyOn ( braintreeSdk , 'initialize' ) ;
100102 jest . spyOn ( braintreeSdk , 'deinitialize' ) ;
101- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
102- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
103- // @ts -ignore
104- jest . spyOn ( braintreeSdk , 'getBraintreeVisaCheckout' ) . mockReturnValue ( braintreeVisaCheckout ) ;
105- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
106- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
107- // @ts -ignore
108- jest . spyOn ( braintreeSdk , 'getDataCollectorOrThrow' ) . mockReturnValue ( dataCollector ) ;
109-
110- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
111- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
112- // @ts -ignore
103+ jest . spyOn ( braintreeSdk , 'getBraintreeVisaCheckout' ) . mockResolvedValue (
104+ braintreeVisaCheckout ,
105+ ) ;
106+ jest . spyOn ( braintreeSdk , 'getDataCollectorOrThrow' ) . mockResolvedValue ( dataCollector ) ;
107+
113108 jest . spyOn ( braintreeSdk , 'getVisaCheckoutSdk' ) . mockImplementation ( ( ) => {
114109 mockWindow . V = visaCheckoutSDKMock ;
115110
116- return mockWindow . V ;
111+ return Promise . resolve ( mockWindow . V ) ;
117112 } ) ;
118113
119114 jest . spyOn ( formPoster , 'postForm' ) . mockImplementation ( ( ) => { } ) ;
@@ -135,7 +130,6 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
135130 try {
136131 await strategy . initialize ( {
137132 ...initializationOptions ,
138- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
139133 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
140134 // @ts -ignore
141135 braintreevisacheckout : { } ,
@@ -163,14 +157,7 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
163157
164158 it ( 'throws error if methodId is missing' , async ( ) => {
165159 try {
166- await strategy . initialize ( {
167- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
168- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
169- // @ts -ignore
170- braintreevisacheckout : {
171- ...initializationOptions . braintreevisacheckout ,
172- } ,
173- } ) ;
160+ await strategy . initialize ( { } ) ;
174161 } catch ( error ) {
175162 expect ( error ) . toBeInstanceOf ( InvalidArgumentError ) ;
176163 }
@@ -209,13 +196,8 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
209196 } ) ;
210197
211198 it ( 'visa Checkout tokenization' , async ( ) => {
212- // TODO: remove rule and update test with related type (PAYPAL-4383)
213- // eslint-disable-next-line @typescript-eslint/no-misused-promises
214- visaCheckoutSDKMock . on = jest . fn ( ( type , callback ) => {
215- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
216- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
217- // @ts -ignore
218- return type === 'payment.success' ? callback ( 'data' ) : undefined ;
199+ jest . spyOn ( visaCheckoutSDKMock , 'on' ) . mockImplementation ( ( _ , callback ) => {
200+ callback ( visaPayload , new Error ( ) ) ;
219201 } ) ;
220202
221203 await strategy . initialize ( initializationOptions ) ;
@@ -225,13 +207,8 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
225207 } ) ;
226208
227209 it ( 'registers the error and success callbacks' , async ( ) => {
228- // TODO: remove rule and update test with related type (PAYPAL-4383)
229-
230- visaCheckoutSDKMock . on = jest . fn ( ( _ , callback ) => {
231- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
232- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
233- // @ts -ignore
234- callback ( ) ;
210+ jest . spyOn ( visaCheckoutSDKMock , 'on' ) . mockImplementation ( ( _ , callback ) => {
211+ callback ( visaPayload , new Error ( ) ) ;
235212 } ) ;
236213 await strategy . initialize ( initializationOptions ) ;
237214
@@ -247,13 +224,8 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
247224
248225 describe ( 'when payment.success' , ( ) => {
249226 beforeEach ( ( ) => {
250- // TODO: remove rule and update test with related type (PAYPAL-4383)
251- // eslint-disable-next-line @typescript-eslint/no-misused-promises
252- visaCheckoutSDKMock . on = jest . fn ( ( type , callback ) => {
253- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
254- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
255- // @ts -ignore
256- return type === 'payment.success' ? callback ( 'data' ) : undefined ;
227+ jest . spyOn ( visaCheckoutSDKMock , 'on' ) . mockImplementation ( ( _ , callback ) => {
228+ callback ( visaPayload , new Error ( ) ) ;
257229 } ) ;
258230 } ) ;
259231
@@ -301,14 +273,9 @@ describe('BraintreeVisaCheckoutCustomerStrategy', () => {
301273 it ( 'payment error triggers onError from the options' , async ( ) => {
302274 const errorMock = new Error ( ) ;
303275
304- // TODO: remove rule and update test with related type (PAYPAL-4383)
305- // eslint-disable-next-line @typescript-eslint/no-misused-promises
306- visaCheckoutSDKMock . on = jest . fn ( ( type , callback ) =>
307- // TODO: remove ts-ignore and update test with related type (PAYPAL-4383)
308- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
309- // @ts -ignore
310- type === 'payment.error' ? callback ( 'data' , errorMock ) : undefined ,
311- ) ;
276+ jest . spyOn ( visaCheckoutSDKMock , 'on' ) . mockImplementation ( ( _ , callback ) => {
277+ callback ( visaPayload , errorMock ) ;
278+ } ) ;
312279
313280 await strategy . initialize ( initializationOptions ) ;
314281
0 commit comments