@@ -401,6 +401,109 @@ medusaIntegrationTestRunner({
401401 } )
402402 )
403403 } )
404+
405+ it ( "should recompute shipping promotion adjustments after shipping price changes due to item update" , async ( ) => {
406+ // Create an automatic promotion targeting shipping_methods
407+ // 100% off shipping (percentage) when applied
408+ await api . post (
409+ `/admin/promotions` ,
410+ {
411+ code : "FREE_SHIPPING" ,
412+ type : "standard" ,
413+ status : "active" ,
414+ is_automatic : true ,
415+ application_method : {
416+ type : "percentage" ,
417+ target_type : "shipping_methods" ,
418+ allocation : "each" ,
419+ value : 100 ,
420+ max_quantity : 1 ,
421+ currency_code : "usd" ,
422+ } ,
423+ } ,
424+ adminHeaders
425+ )
426+
427+ cart = (
428+ await api . post (
429+ `/store/carts` ,
430+ {
431+ region_id : region . id ,
432+ sales_channel_id : salesChannel . id ,
433+ currency_code : "usd" ,
434+ 435+ items : [
436+ {
437+ variant_id : product . variants [ 0 ] . id ,
438+ quantity : 2 ,
439+ } ,
440+ ] ,
441+ } ,
442+ storeHeaders
443+ )
444+ ) . data . cart
445+
446+ // Add calculated shipping method to cart
447+ // With 2 items (quantity 2), price = 2 * 1.5 = 3
448+ let response = await api . post (
449+ `/store/carts/${ cart . id } /shipping-methods` ,
450+ {
451+ option_id : shippingOptionCalculated . id ,
452+ data : { pin_id : "test" } ,
453+ } ,
454+ storeHeaders
455+ )
456+
457+ expect ( response . data . cart ) . toEqual (
458+ expect . objectContaining ( {
459+ id : cart . id ,
460+ shipping_methods : expect . arrayContaining ( [
461+ expect . objectContaining ( {
462+ shipping_option_id : shippingOptionCalculated . id ,
463+ amount : 3 ,
464+ adjustments : expect . arrayContaining ( [
465+ expect . objectContaining ( {
466+ code : "FREE_SHIPPING" ,
467+ amount : 3 ,
468+ } ) ,
469+ ] ) ,
470+ } ) ,
471+ ] ) ,
472+ shipping_total : 0 ,
473+ } )
474+ )
475+
476+ // Now add more items to the cart, which changes item quantity to 3
477+ // New shipping price should be 3 * 1.5 = 4.5
478+ // The promotion should adjust to 4.5 (100% off the NEW shipping amount)
479+ response = await api . post (
480+ `/store/carts/${ cart . id } /line-items` ,
481+ {
482+ variant_id : product . variants [ 0 ] . id ,
483+ quantity : 1 ,
484+ } ,
485+ storeHeaders
486+ )
487+
488+ expect ( response . data . cart ) . toEqual (
489+ expect . objectContaining ( {
490+ id : cart . id ,
491+ shipping_methods : expect . arrayContaining ( [
492+ expect . objectContaining ( {
493+ shipping_option_id : shippingOptionCalculated . id ,
494+ amount : 4.5 ,
495+ adjustments : expect . arrayContaining ( [
496+ expect . objectContaining ( {
497+ code : "FREE_SHIPPING" ,
498+ amount : 4.5 , // Must match the NEW shipping amount, not the old one (3)
499+ } ) ,
500+ ] ) ,
501+ } ) ,
502+ ] ) ,
503+ shipping_total : 0 , // Still fully discounted
504+ } )
505+ )
506+ } )
404507 } )
405508 } )
406509 } ,
0 commit comments