@@ -619,4 +619,87 @@ describe('TemplateUpdateBuilder', () => {
619619 } ) ;
620620 } ) ;
621621 } ) ;
622+
623+ describe ( 'expectTemplateStatusByType' , ( ) => {
624+ test ( 'adds conditions for single type-status mapping' , ( ) => {
625+ const builder = new TemplateUpdateBuilder (
626+ mockTableName ,
627+ mockOwner ,
628+ mockId
629+ ) ;
630+
631+ const res = builder
632+ . expectStatusByType ( [ 'SMS' , 'NOT_YET_SUBMITTED' ] )
633+ . build ( ) ;
634+
635+ expect ( res ) . toMatchObject ( {
636+ ExpressionAttributeNames : {
637+ '#templateType' : 'templateType' ,
638+ '#templateStatus' : 'templateStatus' ,
639+ } ,
640+ ExpressionAttributeValues : {
641+ ':condition_1_1_1_templateType' : 'SMS' ,
642+ ':condition_1_1_2_templateStatus' : 'NOT_YET_SUBMITTED' ,
643+ } ,
644+ ConditionExpression :
645+ '((#templateType = :condition_1_1_1_templateType AND #templateStatus = :condition_1_1_2_templateStatus))' ,
646+ } ) ;
647+ } ) ;
648+
649+ test ( 'adds conditions for multiple type-status mappings' , ( ) => {
650+ const builder = new TemplateUpdateBuilder (
651+ mockTableName ,
652+ mockOwner ,
653+ mockId
654+ ) ;
655+
656+ const res = builder
657+ . expectStatusByType (
658+ [ 'SMS' , 'NOT_YET_SUBMITTED' ] ,
659+ [ 'EMAIL' , 'PENDING_VALIDATION' ]
660+ )
661+ . build ( ) ;
662+
663+ expect ( res ) . toMatchObject ( {
664+ ExpressionAttributeNames : {
665+ '#templateType' : 'templateType' ,
666+ '#templateStatus' : 'templateStatus' ,
667+ } ,
668+ ExpressionAttributeValues : {
669+ ':condition_1_1_1_templateType' : 'SMS' ,
670+ ':condition_1_1_2_templateStatus' : 'NOT_YET_SUBMITTED' ,
671+ ':condition_1_2_1_templateType' : 'EMAIL' ,
672+ ':condition_1_2_2_templateStatus' : 'PENDING_VALIDATION' ,
673+ } ,
674+ ConditionExpression :
675+ '((#templateType = :condition_1_1_1_templateType AND #templateStatus = :condition_1_1_2_templateStatus) OR (#templateType = :condition_1_2_1_templateType AND #templateStatus = :condition_1_2_2_templateStatus))' ,
676+ } ) ;
677+ } ) ;
678+
679+ test ( 'handles array of statuses' , ( ) => {
680+ const builder = new TemplateUpdateBuilder (
681+ mockTableName ,
682+ mockOwner ,
683+ mockId
684+ ) ;
685+
686+ const res = builder
687+ . expectStatusByType ( [ 'EMAIL' , [ 'PENDING_VALIDATION' , 'DELETED' ] ] )
688+ . build ( ) ;
689+
690+ expect ( res ) . toMatchObject ( {
691+ ExpressionAttributeNames : {
692+ '#templateType' : 'templateType' ,
693+ '#templateStatus' : 'templateStatus' ,
694+ } ,
695+ ExpressionAttributeValues : {
696+ ':condition_1_1_1_templateType' : 'EMAIL' ,
697+ ':condition_1_1_2_1_templateStatus' : 'PENDING_VALIDATION' ,
698+ ':condition_1_1_2_2_templateStatus' : 'DELETED' ,
699+ } ,
700+ ConditionExpression :
701+ '((#templateType = :condition_1_1_1_templateType AND #templateStatus IN (:condition_1_1_2_1_templateStatus, :condition_1_1_2_2_templateStatus)))' ,
702+ } ) ;
703+ } ) ;
704+ } ) ;
622705} ) ;
0 commit comments