@@ -603,7 +603,7 @@ describe('DistanceRate', () => {
603603 it ( 'should keep a disabled fuel band disabled for every later rate of its series in the same request' , async ( ) => {
604604 // Given an eligible GBP workspace whose earlier petrol band an admin disabled, and whose earlier diesel band an
605605 // admin edited to their own amount and disabled
606- const editedDieselRateID = 'EDITEDDIESEL1 ' ;
606+ const editedDieselRateID = '5A1D3C8E9F0B2 ' ;
607607 const policy = buildUKPolicy ( true , true , {
608608 [ existingRateID ] : {
609609 customUnitRateID : existingRateID ,
@@ -644,6 +644,59 @@ describe('DistanceRate', () => {
644644 // so its disabled state doesn't opt the workspace out of the government rate
645645 expect ( getRateBySourceID ( rates , dieselBand . sourceRateID ) ?. enabled ) . toBe ( true ) ;
646646 } ) ;
647+
648+ it ( 'should enable a copied fuel band when its latest previous rate was edited, even if an older one was disabled' , async ( ) => {
649+ // Given an eligible GBP workspace whose March diesel band is unmodified and disabled, and whose June diesel band an
650+ // admin edited to their own amount
651+ const marchDieselRateID = '3B7E0A9C4D1F6' ;
652+ const juneDieselRateID = '8C2F5E1A7B3D0' ;
653+ const policy = buildUKPolicy ( true , true , {
654+ [ marchDieselRateID ] : {
655+ customUnitRateID : marchDieselRateID ,
656+ name : 'Cars & Vans (Diesel) - Up to 1600cc' ,
657+ rate : 45 ,
658+ currency : 'GBP' ,
659+ enabled : false ,
660+ startDate : '2026-03-01' ,
661+ endDate : '2026-05-31' ,
662+ attributes : {
663+ taxClaimablePercentage : 11 / 45 ,
664+ governmentRate : { sourceRateID : 'GB_DIESEL_UP_TO_1600_2026-03-01' , rate : 45 , startDate : '2026-03-01' , endDate : '2026-05-31' , taxClaimablePercentage : 11 / 45 } ,
665+ } ,
666+ } ,
667+ [ juneDieselRateID ] : {
668+ customUnitRateID : juneDieselRateID ,
669+ name : 'Cars & Vans (Diesel) - Up to 1600cc' ,
670+ rate : 50 ,
671+ currency : 'GBP' ,
672+ enabled : true ,
673+ startDate : '2026-06-01' ,
674+ endDate : '2026-08-31' ,
675+ attributes : {
676+ taxClaimablePercentage : 11 / 45 ,
677+ governmentRate : { sourceRateID : 'GB_DIESEL_UP_TO_1600_2026-06-01' , rate : 45 , startDate : '2026-06-01' , endDate : '2026-08-31' , taxClaimablePercentage : 11 / 45 } ,
678+ } ,
679+ } ,
680+ } ) ;
681+
682+ // When auto-update copies the September diesel band
683+ const rates = await enableAutoUpdate ( policy , [ dieselBand ] ) ;
684+
685+ // Then the September band is enabled, because only the latest previous rate counts and the admin edited it, so the
686+ // disabled March rate further back doesn't opt the workspace out
687+ expect ( getRateBySourceID ( rates , dieselBand . sourceRateID ) ?. enabled ) . toBe ( true ) ;
688+ } ) ;
689+
690+ it ( 'should copy a reference rate listed twice only once' , async ( ) => {
691+ // Given an eligible GBP workspace and a reference list that contains the same fuel band twice
692+ const policy = buildUKPolicy ( true , true ) ;
693+
694+ // When auto-update is turned on
695+ const rates = await enableAutoUpdate ( policy , [ dieselBand , dieselBand ] ) ;
696+
697+ // Then the band is copied once, since the server de-dupes by sourceRateID and would leave a second copy orphaned
698+ expect ( rates . filter ( ( rate ) => rate . attributes ?. governmentRate ?. sourceRateID === dieselBand . sourceRateID ) ) . toHaveLength ( 1 ) ;
699+ } ) ;
647700 } ) ;
648701 } ) ;
649702
0 commit comments