@@ -483,7 +483,8 @@ describe("supplier-config service", () => {
483483
484484 expect ( result ) . toEqual ( [ "spec1" ] ) ;
485485 } ) ;
486- it ( "throws when no eligible packs found for letter" , async ( ) => {
486+
487+ it ( "throws when no eligible packs found for letter based on sheets" , async ( ) => {
487488 const deps = makeDeps ( ) ;
488489 deps . supplierConfigRepo . getPackSpecification = jest
489490 . fn ( )
@@ -505,11 +506,18 @@ describe("supplier-config service", () => {
505506 "No eligible pack specifications found for letter variant id undefined and pack specification ids spec1" ,
506507 ) ;
507508 expect ( deps . logger . info ) . toHaveBeenCalledWith ( {
508- description : "Pack specification filtered out based on constraints" ,
509+ description :
510+ "Pack specification filtered out based on pageCount constraints" ,
509511 packSpecId : "spec1" ,
510512 pageCount : 3 ,
511- constraintValue : 2 ,
512- constraintOperator : "LESS_THAN" ,
513+ violatedConstraints : expect . arrayContaining ( [
514+ expect . objectContaining ( {
515+ actualValue : 3 ,
516+ constraint : "sheets" ,
517+ constraintValue : 2 ,
518+ operator : "LESS_THAN" ,
519+ } ) ,
520+ ] ) ,
513521 } ) ;
514522 expect ( deps . logger . error ) . toHaveBeenCalledWith (
515523 expect . objectContaining ( {
@@ -519,6 +527,160 @@ describe("supplier-config service", () => {
519527 } ) ,
520528 ) ;
521529 } ) ;
530+
531+ it ( "does not filter pack specification when duplex reduces sheets and constraint is LESS_THAN_OR_EQUAL" , async ( ) => {
532+ const deps = makeDeps ( ) ;
533+ deps . supplierConfigRepo . getPackSpecification = jest
534+ . fn ( )
535+ . mockResolvedValue ( {
536+ id : "spec1" ,
537+ assembly : { duplex : true } ,
538+ constraints : {
539+ sheets : { operator : "LESS_THAN_OR_EQUAL" , value : 2 } ,
540+ } ,
541+ } as any ) ;
542+
543+ const letterEvent = {
544+ data : {
545+ pageCount : 3 ,
546+ letterVariantId : "variant-1" ,
547+ } ,
548+ } as any ;
549+
550+ const result = await filterPacksForLetter ( letterEvent , [ "spec1" ] , deps ) ;
551+
552+ expect ( result ) . toEqual ( [ "spec1" ] ) ;
553+ expect ( deps . logger . info ) . not . toHaveBeenCalled ( ) ;
554+ } ) ;
555+
556+ it ( "filters pack specification when sides fail LESS_THAN_OR_EQUAL" , async ( ) => {
557+ const deps = makeDeps ( ) ;
558+ deps . supplierConfigRepo . getPackSpecification = jest
559+ . fn ( )
560+ . mockResolvedValue ( {
561+ id : "spec1" ,
562+ constraints : {
563+ sides : { operator : "LESS_THAN_OR_EQUAL" , value : 2 } ,
564+ } ,
565+ } as any ) ;
566+
567+ const letterEvent = {
568+ data : {
569+ pageCount : 3 ,
570+ letterVariantId : "variant-1" ,
571+ } ,
572+ } as any ;
573+
574+ await expect (
575+ filterPacksForLetter ( letterEvent , [ "spec1" ] , deps ) ,
576+ ) . rejects . toThrow ( / N o e l i g i b l e p a c k s p e c i f i c a t i o n s f o u n d / ) ;
577+
578+ expect ( deps . logger . info ) . toHaveBeenCalledWith ( {
579+ description :
580+ "Pack specification filtered out based on pageCount constraints" ,
581+ packSpecId : "spec1" ,
582+ pageCount : 3 ,
583+ violatedConstraints : expect . arrayContaining ( [
584+ expect . objectContaining ( {
585+ constraint : "sides" ,
586+ actualValue : 3 ,
587+ constraintValue : 2 ,
588+ operator : "LESS_THAN_OR_EQUAL" ,
589+ } ) ,
590+ ] ) ,
591+ } ) ;
592+ } ) ;
593+
594+ it ( "filters by sides using page count even when duplex is enabled" , async ( ) => {
595+ const deps = makeDeps ( ) ;
596+ deps . supplierConfigRepo . getPackSpecification = jest
597+ . fn ( )
598+ . mockResolvedValue ( {
599+ id : "spec1" ,
600+ assembly : { duplex : true } ,
601+ constraints : {
602+ sheets : { operator : "LESS_THAN_OR_EQUAL" , value : 2 } ,
603+ sides : { operator : "LESS_THAN_OR_EQUAL" , value : 2 } ,
604+ } ,
605+ } as any ) ;
606+
607+ const letterEvent = {
608+ data : {
609+ pageCount : 3 ,
610+ letterVariantId : "variant-1" ,
611+ } ,
612+ } as any ;
613+
614+ await expect (
615+ filterPacksForLetter ( letterEvent , [ "spec1" ] , deps ) ,
616+ ) . rejects . toThrow ( / N o e l i g i b l e p a c k s p e c i f i c a t i o n s f o u n d / ) ;
617+
618+ expect ( deps . logger . info ) . toHaveBeenCalledWith ( {
619+ description :
620+ "Pack specification filtered out based on pageCount constraints" ,
621+ packSpecId : "spec1" ,
622+ pageCount : 3 ,
623+ violatedConstraints : expect . arrayContaining ( [
624+ expect . objectContaining ( {
625+ constraint : "sides" ,
626+ actualValue : 3 ,
627+ constraintValue : 2 ,
628+ operator : "LESS_THAN_OR_EQUAL" ,
629+ } ) ,
630+ ] ) ,
631+ } ) ;
632+ } ) ;
633+
634+ it ( "does not filter pack specification when sides is valid" , async ( ) => {
635+ const deps = makeDeps ( ) ;
636+ deps . supplierConfigRepo . getPackSpecification = jest
637+ . fn ( )
638+ . mockResolvedValue ( {
639+ id : "spec1" ,
640+ assembly : { duplex : true } ,
641+ constraints : {
642+ sheets : { operator : "LESS_THAN_OR_EQUAL" , value : 4 } ,
643+ } ,
644+ } as any ) ;
645+
646+ const letterEvent = {
647+ data : {
648+ pageCount : 3 ,
649+ letterVariantId : "variant-1" ,
650+ } ,
651+ } as any ;
652+
653+ const result = await filterPacksForLetter ( letterEvent , [ "spec1" ] , deps ) ;
654+
655+ expect ( result ) . toEqual ( [ "spec1" ] ) ;
656+ expect ( deps . logger . info ) . not . toHaveBeenCalled ( ) ;
657+ } ) ;
658+
659+ it ( "keeps pack specification when sides constraint passes" , async ( ) => {
660+ const deps = makeDeps ( ) ;
661+ deps . supplierConfigRepo . getPackSpecification = jest
662+ . fn ( )
663+ . mockResolvedValue ( {
664+ id : "spec1" ,
665+ constraints : {
666+ sides : { operator : "LESS_THAN_OR_EQUAL" , value : 3 } ,
667+ } ,
668+ } as any ) ;
669+
670+ const letterEvent = {
671+ data : {
672+ pageCount : 3 ,
673+ letterVariantId : "variant-1" ,
674+ } ,
675+ } as any ;
676+
677+ const result = await filterPacksForLetter ( letterEvent , [ "spec1" ] , deps ) ;
678+
679+ expect ( result ) . toEqual ( [ "spec1" ] ) ;
680+ expect ( deps . logger . info ) . not . toHaveBeenCalled ( ) ;
681+ expect ( deps . logger . error ) . not . toHaveBeenCalled ( ) ;
682+ } ) ;
683+
522684 it ( "returns eligible packs for all constraint types" , async ( ) => {
523685 const deps = makeDeps ( ) ;
524686 const constraints : { operator : string ; value : number } [ ] = [
0 commit comments