@@ -329,9 +329,75 @@ describe('CloudPaymentsWebhooks', () => {
329329 isCardLinkOperation : false ,
330330 } ) ;
331331 } ) ;
332+
333+ it ( 'should restore subscription renewal data by SubscriptionId without promo' , async ( ) => {
334+ const webhooks = new CloudPaymentsWebhooks ( ) as any ;
335+ const workspaceId = new ObjectId ( ) . toString ( ) ;
336+ const userId = new ObjectId ( ) . toString ( ) ;
337+ const plan = createPlan ( 1000 ) ;
338+ const { context, workspace } = createWebhookContext ( {
339+ workspaceId,
340+ userId,
341+ plan,
342+ subscriptionId : 'subscription-id' ,
343+ } ) ;
344+
345+ context . factories . workspacesFactory . findBySubscriptionId = jest . fn ( ) . mockResolvedValue ( workspace ) ;
346+
347+ const data = await webhooks . getDataFromRequest ( {
348+ context,
349+ body : {
350+ SubscriptionId : 'subscription-id' ,
351+ AccountId : userId ,
352+ } ,
353+ } ) ;
354+
355+ expect ( context . factories . workspacesFactory . findBySubscriptionId ) . toHaveBeenCalledWith ( 'subscription-id' ) ;
356+ expect ( data ) . toMatchObject ( {
357+ workspaceId,
358+ userId,
359+ tariffPlanId : plan . _id . toString ( ) ,
360+ shouldSaveCard : false ,
361+ isCardLinkOperation : false ,
362+ } ) ;
363+ expect ( data . promo ) . toBeUndefined ( ) ;
364+ } ) ;
332365 } ) ;
333366
334367 describe ( 'check()' , ( ) => {
368+ it ( 'should accept card-link validation amount without changing plan' , async ( ) => {
369+ const webhooks = new CloudPaymentsWebhooks ( ) as any ;
370+ const workspaceId = new ObjectId ( ) . toString ( ) ;
371+ const userId = new ObjectId ( ) . toString ( ) ;
372+ const plan = createPlan ( 1000 ) ;
373+ const { context, createBusinessOperation } = createWebhookContext ( {
374+ workspaceId,
375+ userId,
376+ plan,
377+ } ) ;
378+ const res = createMockResponse ( ) ;
379+ const Data = await buildCardLinkChecksumPayload ( {
380+ workspaceId,
381+ userId,
382+ cloudPayments : {
383+ recurrent : {
384+ interval : 'Month' ,
385+ period : 1 ,
386+ amount : 1000 ,
387+ startDate : new Date ( ) . toISOString ( ) ,
388+ } ,
389+ } ,
390+ } ) ;
391+
392+ await webhooks . check ( { context, body : createCheckBody ( 1000 , '1' , Data ) } , res ) ;
393+
394+ expect ( createBusinessOperation ) . toHaveBeenCalledWith ( expect . objectContaining ( {
395+ type : BusinessOperationType . CardLinkCharge ,
396+ status : BusinessOperationStatus . Pending ,
397+ } ) ) ;
398+ expect ( res . json ) . toHaveBeenCalledWith ( { code : CheckCodes . SUCCESS } ) ;
399+ } ) ;
400+
335401 it ( 'should reject wrong amount when promo id is in checksum' , async ( ) => {
336402 const webhooks = new CloudPaymentsWebhooks ( ) as any ;
337403 const workspaceId = new ObjectId ( ) . toString ( ) ;
@@ -622,6 +688,36 @@ describe('CloudPaymentsWebhooks', () => {
622688 expect ( res . json ) . toHaveBeenCalledWith ( { code : CheckCodes . SUCCESS } ) ;
623689 } ) ;
624690
691+ it ( 'should reject wrong amount on subscription renewal check without Data' , async ( ) => {
692+ const webhooks = new CloudPaymentsWebhooks ( ) as any ;
693+ const workspaceId = new ObjectId ( ) . toString ( ) ;
694+ const userId = new ObjectId ( ) . toString ( ) ;
695+ const plan = createPlan ( 1000 ) ;
696+ const { context, workspace } = createWebhookContext ( {
697+ workspaceId,
698+ userId,
699+ plan,
700+ subscriptionId : 'subscription-id' ,
701+ } ) ;
702+
703+ context . factories . workspacesFactory . findBySubscriptionId = jest . fn ( ) . mockResolvedValue ( workspace ) ;
704+
705+ const res = createMockResponse ( ) ;
706+
707+ await webhooks . check ( {
708+ context,
709+ body : {
710+ ...createCheckBody ( 1011 , '999' , '' ) ,
711+ SubscriptionId : 'subscription-id' ,
712+ AccountId : userId ,
713+ Data : undefined ,
714+ } ,
715+ } , res ) ;
716+
717+ expect ( context . factories . workspacesFactory . findBySubscriptionId ) . toHaveBeenCalledWith ( 'subscription-id' ) ;
718+ expect ( res . json ) . toHaveBeenCalledWith ( { code : CheckCodes . WRONG_AMOUNT } ) ;
719+ } ) ;
720+
625721 it ( 'should reject wrong amount when promo is not applied' , async ( ) => {
626722 const webhooks = new CloudPaymentsWebhooks ( ) as any ;
627723 const workspaceId = new ObjectId ( ) . toString ( ) ;
0 commit comments