@@ -434,5 +434,141 @@ def test_given_three_plus_one_is_applied_when_item_is_removed_then_the_discount_
434434 )
435435 ) { remove_item ( order_id , product_id ) }
436436 end
437+
438+ def test_given_three_items_added_to_basket_and_no_three_plus_one_promotion_when_fourth_is_added_then_price_is_not_discounted
439+ product_id = SecureRandom . uuid
440+ set_price ( product_id , 20 )
441+ order_id = SecureRandom . uuid
442+ stream = "Pricing::Offer$#{ order_id } "
443+
444+ 3 . times { add_item ( order_id , product_id ) }
445+
446+ assert_events (
447+ stream ,
448+ PriceItemAdded . new (
449+ data : {
450+ order_id : order_id ,
451+ product_id : product_id ,
452+ base_price : 20 ,
453+ price : 20 ,
454+ base_total_value : 80 ,
455+ total_value : 80
456+ }
457+ ) ,
458+ OrderTotalValueCalculated . new (
459+ data : {
460+ order_id : order_id ,
461+ total_amount : 80 ,
462+ discounted_amount : 80
463+ }
464+ ) ,
465+ PriceItemValueCalculated . new (
466+ data : {
467+ order_id : order_id ,
468+ product_id : product_id ,
469+ quantity : 4 ,
470+ amount : 80 ,
471+ discounted_amount : 80 ,
472+ } ) ,
473+ ) { add_item ( order_id , product_id ) }
474+ end
475+
476+ def test_given_three_items_in_basket_when_different_one_is_added_then_price_is_not_discounted
477+ product_id = SecureRandom . uuid
478+ different_product_id = SecureRandom . uuid
479+ set_price ( product_id , 20 )
480+ set_price ( different_product_id , 50 )
481+ order_id = SecureRandom . uuid
482+ stream = "Pricing::Offer$#{ order_id } "
483+
484+ 3 . times { add_item ( order_id , product_id ) }
485+
486+ assert_events (
487+ stream ,
488+ PriceItemAdded . new (
489+ data : {
490+ order_id : order_id ,
491+ product_id : different_product_id ,
492+ base_price : 50 ,
493+ price : 50 ,
494+ base_total_value : 110 ,
495+ total_value : 110
496+ }
497+ ) ,
498+ OrderTotalValueCalculated . new (
499+ data : {
500+ order_id : order_id ,
501+ total_amount : 110 ,
502+ discounted_amount : 110
503+ }
504+ ) ,
505+ PriceItemValueCalculated . new (
506+ data : {
507+ order_id : order_id ,
508+ product_id : product_id ,
509+ quantity : 3 ,
510+ amount : 60 ,
511+ discounted_amount : 60 ,
512+ } ) ,
513+ PriceItemValueCalculated . new (
514+ data : {
515+ order_id : order_id ,
516+ product_id : different_product_id ,
517+ quantity : 1 ,
518+ amount : 50 ,
519+ discounted_amount : 50 ,
520+ } )
521+ ) { add_item ( order_id , different_product_id ) }
522+ end
523+
524+ def test_given_two_sets_of_three_items_in_basket_when_added_forth_item_then_price_is_discounted_for_that_item
525+ product_id = SecureRandom . uuid
526+ different_product_id = SecureRandom . uuid
527+ set_price ( product_id , 20 )
528+ set_price ( different_product_id , 50 )
529+ order_id = SecureRandom . uuid
530+ stream = "Pricing::Offer$#{ order_id } "
531+
532+ 3 . times { add_item ( order_id , product_id , promotion : true ) }
533+ 3 . times { add_item ( order_id , different_product_id , promotion : true ) }
534+
535+ assert_events (
536+ stream ,
537+ PriceItemAdded . new (
538+ data : {
539+ order_id : order_id ,
540+ product_id : different_product_id ,
541+ base_price : 50 ,
542+ price : 0 ,
543+ base_total_value : 260 ,
544+ total_value : 210 ,
545+ applied_promotion : Pricing ::Discounts ::ThreePlusOneGratis . to_s
546+ }
547+ ) ,
548+ OrderTotalValueCalculated . new (
549+ data : {
550+ order_id : order_id ,
551+ total_amount : 260 ,
552+ discounted_amount : 210
553+ }
554+ ) ,
555+ PriceItemValueCalculated . new (
556+ data : {
557+ order_id : order_id ,
558+ product_id : product_id ,
559+ quantity : 3 ,
560+ amount : 60 ,
561+ discounted_amount : 60 ,
562+ } ) ,
563+ PriceItemValueCalculated . new (
564+ data : {
565+ order_id : order_id ,
566+ product_id : different_product_id ,
567+ quantity : 4 ,
568+ amount : 200 ,
569+ discounted_amount : 150 ,
570+ } )
571+ ) { add_item ( order_id , different_product_id , promotion : true ) }
572+ end
437573 end
438574end
0 commit comments