@@ -337,6 +337,26 @@ describe('Pay webhook', () => {
337337 expect ( updatedWorkspace ?. billingPeriodEventsCount ) . toBe ( 0 ) ;
338338 } ) ;
339339
340+ test ( 'Should not reset events counter in workspace if it is a card linking operation' , async ( ) => {
341+ const apiResponse = await apiInstance . post ( '/billing/pay' , {
342+ ...validPayRequestData ,
343+ Data : JSON . stringify ( {
344+ checksum : await checksumService . generateChecksum ( {
345+ ...paymentSuccessPayload ,
346+ isCardLinkOperation : true ,
347+ nextPaymentDate : new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 ) . toString ( ) , // next day
348+ } ) ,
349+ } ) ,
350+ } ) ;
351+
352+ const notUpdatedWorkspace = await workspacesCollection . findOne ( {
353+ _id : workspace . _id ,
354+ } ) ;
355+
356+ expect ( apiResponse . data . code ) . toBe ( PayCodes . SUCCESS ) ;
357+ expect ( notUpdatedWorkspace ?. billingPeriodEventsCount ) . not . toBe ( 0 ) ;
358+ } ) ;
359+
340360 test ( 'Should reset last charge date in workspace' , async ( ) => {
341361 const apiResponse = await apiInstance . post ( '/billing/pay' , validPayRequestData ) ;
342362
@@ -375,6 +395,26 @@ describe('Pay webhook', () => {
375395 expect ( apiResponse . data . code ) . toBe ( PayCodes . SUCCESS ) ;
376396 } ) ;
377397
398+ test ( 'Should not send task to limiter worker if it is a card linking operation' , async ( ) => {
399+ const apiResponse = await apiInstance . post ( '/billing/pay' , {
400+ ...validPayRequestData ,
401+ Data : JSON . stringify ( {
402+ checksum : await checksumService . generateChecksum ( {
403+ ...paymentSuccessPayload ,
404+ isCardLinkOperation : true ,
405+ nextPaymentDate : new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 ) . toString ( ) , // next day
406+ } ) ,
407+ } ) ,
408+ } ) ;
409+
410+ const message = await global . rabbitChannel . get ( 'cron-tasks/limiter' , {
411+ noAck : true ,
412+ } ) ;
413+
414+ expect ( message ) . toBeFalsy ( ) ;
415+ expect ( apiResponse . data . code ) . toBe ( PayCodes . SUCCESS ) ;
416+ } ) ;
417+
378418 // test('Should associate an account with a workspace if the workspace did not have one', async () => {
379419 // /**
380420 // * Remove accountId from existed workspace
@@ -479,6 +519,8 @@ describe('Pay webhook', () => {
479519 expect ( updatedUser ?. bankCards ?. shift ( ) ) . toMatchObject ( expectedCard ) ;
480520 expect ( apiResponse . data . code ) . toBe ( PayCodes . SUCCESS ) ;
481521 } ) ;
522+
523+
482524 } ) ;
483525
484526 describe ( 'With invalid request' , ( ) => {
0 commit comments