@@ -522,6 +522,122 @@ describe('SubscriptionUtils', () => {
522522 } ) ;
523523 } ) ;
524524
525+ describe ( 'shouldRestrictUserBillableActions - policy parameter' , ( ) => {
526+ afterEach ( async ( ) => {
527+ await Onyx . clear ( ) ;
528+ await Onyx . multiSet ( {
529+ [ ONYXKEYS . SESSION ] : null ,
530+ [ ONYXKEYS . COLLECTION . SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END ] : null ,
531+ [ ONYXKEYS . NVP_PRIVATE_AMOUNT_OWED ] : null ,
532+ [ ONYXKEYS . COLLECTION . POLICY ] : null ,
533+ } ) ;
534+ } ) ;
535+
536+ it ( 'should restrict when policy is passed directly and owner is past due' , async ( ) => {
537+ const accountID = 1 ;
538+ const policyID = '2001' ;
539+ const policy = {
540+ ...createRandomPolicy ( Number ( policyID ) ) ,
541+ ownerAccountID : accountID ,
542+ } ;
543+
544+ await Onyx . multiSet ( {
545+ [ ONYXKEYS . SESSION ] : { email : '' , accountID} ,
546+ [ ONYXKEYS . NVP_PRIVATE_AMOUNT_OWED ] : 8010 ,
547+ } ) ;
548+
549+ expect ( shouldRestrictUserBillableActions ( policyID , getUnixTime ( subDays ( new Date ( ) , 3 ) ) , undefined , undefined , policy ) ) . toBeTruthy ( ) ;
550+ } ) ;
551+
552+ it ( 'should not restrict when policy is passed directly but owner is not past due' , async ( ) => {
553+ const accountID = 1 ;
554+ const policyID = '2001' ;
555+ const policy = {
556+ ...createRandomPolicy ( Number ( policyID ) ) ,
557+ ownerAccountID : accountID ,
558+ } ;
559+
560+ await Onyx . multiSet ( {
561+ [ ONYXKEYS . SESSION ] : { email : '' , accountID} ,
562+ [ ONYXKEYS . NVP_PRIVATE_AMOUNT_OWED ] : 8010 ,
563+ } ) ;
564+
565+ expect ( shouldRestrictUserBillableActions ( policyID , getUnixTime ( addDays ( new Date ( ) , 3 ) ) , undefined , undefined , policy ) ) . toBeFalsy ( ) ;
566+ } ) ;
567+
568+ it ( 'should not restrict when policy is passed as undefined' , ( ) => {
569+ expect ( shouldRestrictUserBillableActions ( 'nonexistent' , getUnixTime ( subDays ( new Date ( ) , 3 ) ) , undefined , 500 , undefined ) ) . toBeFalsy ( ) ;
570+ } ) ;
571+
572+ it ( 'should restrict for non-owner when policy is passed directly and billing grace period is overdue' , async ( ) => {
573+ const policyID = '2001' ;
574+ const ownerAccountID = 2001 ;
575+ const policy = {
576+ ...createRandomPolicy ( Number ( policyID ) ) ,
577+ ownerAccountID,
578+ } ;
579+
580+ expect (
581+ shouldRestrictUserBillableActions (
582+ policyID ,
583+ undefined ,
584+ {
585+ [ `${ ONYXKEYS . COLLECTION . SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END } ${ ownerAccountID } ` as const ] : {
586+ ...billingGraceEndPeriod ,
587+ value : getUnixTime ( subDays ( new Date ( ) , 3 ) ) ,
588+ } ,
589+ } ,
590+ undefined ,
591+ policy ,
592+ ) ,
593+ ) . toBeTruthy ( ) ;
594+ } ) ;
595+
596+ it ( 'should not restrict for non-owner when policy is passed directly but billing grace period is not overdue' , async ( ) => {
597+ const policyID = '2001' ;
598+ const ownerAccountID = 2001 ;
599+ const policy = {
600+ ...createRandomPolicy ( Number ( policyID ) ) ,
601+ ownerAccountID,
602+ } ;
603+
604+ expect (
605+ shouldRestrictUserBillableActions (
606+ policyID ,
607+ undefined ,
608+ {
609+ [ `${ ONYXKEYS . COLLECTION . SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END } ${ ownerAccountID } ` as const ] : {
610+ ...billingGraceEndPeriod ,
611+ value : getUnixTime ( addDays ( new Date ( ) , 3 ) ) ,
612+ } ,
613+ } ,
614+ undefined ,
615+ policy ,
616+ ) ,
617+ ) . toBeFalsy ( ) ;
618+ } ) ;
619+
620+ it ( 'should use passed policy and ignore Onyx-stored policies' , async ( ) => {
621+ const accountID = 1 ;
622+ const policyID = '2001' ;
623+ const differentOwnerPolicy = {
624+ ...createRandomPolicy ( Number ( policyID ) ) ,
625+ ownerAccountID : 9999 ,
626+ } ;
627+
628+ await Onyx . multiSet ( {
629+ [ ONYXKEYS . SESSION ] : { email : '' , accountID} ,
630+ [ ONYXKEYS . NVP_PRIVATE_AMOUNT_OWED ] : 8010 ,
631+ [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` as const ] : {
632+ ...createRandomPolicy ( Number ( policyID ) ) ,
633+ ownerAccountID : accountID ,
634+ } ,
635+ } ) ;
636+
637+ expect ( shouldRestrictUserBillableActions ( policyID , getUnixTime ( subDays ( new Date ( ) , 3 ) ) , undefined , undefined , differentOwnerPolicy ) ) . toBeFalsy ( ) ;
638+ } ) ;
639+ } ) ;
640+
525641 describe ( 'getSubscriptionStatus' , ( ) => {
526642 afterEach ( async ( ) => {
527643 await Onyx . clear ( ) ;
0 commit comments