|
2 | 2 |
|
3 | 3 | module Pricing |
4 | 4 | class SimpleOfferTest < Test |
5 | | - cover "Pricing*" |
| 5 | + cover "Pricing::Offer*" |
| 6 | + |
| 7 | + def test_adding |
| 8 | + product_id = SecureRandom.uuid |
| 9 | + set_price(product_id, 20) |
| 10 | + order_id = SecureRandom.uuid |
| 11 | + stream = "Pricing::Offer$#{order_id}" |
| 12 | + assert_events( |
| 13 | + stream, |
| 14 | + PriceItemAdded.new( |
| 15 | + data: { |
| 16 | + order_id: order_id, |
| 17 | + product_id: product_id, |
| 18 | + base_price: 20, |
| 19 | + price: 20, |
| 20 | + base_total_value: 20, |
| 21 | + total_value: 20, |
| 22 | + } |
| 23 | + ), |
| 24 | + OrderTotalValueCalculated.new( |
| 25 | + data: { |
| 26 | + order_id: order_id, |
| 27 | + discounted_amount: 20, |
| 28 | + total_amount: 20 |
| 29 | + } |
| 30 | + ), |
| 31 | + PriceItemValueCalculated.new( |
| 32 | + data: { |
| 33 | + order_id: order_id, |
| 34 | + product_id: product_id, |
| 35 | + quantity: 1, |
| 36 | + amount: 20, |
| 37 | + discounted_amount: 20, |
| 38 | + } |
| 39 | + ) |
| 40 | + ) { add_item(order_id, product_id) } |
| 41 | + |
| 42 | + assert_events( |
| 43 | + stream, |
| 44 | + PriceItemAdded.new( |
| 45 | + data: { |
| 46 | + order_id: order_id, |
| 47 | + product_id: product_id, |
| 48 | + base_price: 20, |
| 49 | + price: 20, |
| 50 | + base_total_value: 40, |
| 51 | + total_value: 40, |
| 52 | + } |
| 53 | + ), |
| 54 | + OrderTotalValueCalculated.new( |
| 55 | + data: { |
| 56 | + order_id: order_id, |
| 57 | + discounted_amount: 40, |
| 58 | + total_amount: 40 |
| 59 | + } |
| 60 | + ), |
| 61 | + PriceItemValueCalculated.new( |
| 62 | + data: { |
| 63 | + order_id: order_id, |
| 64 | + product_id: product_id, |
| 65 | + quantity: 2, |
| 66 | + amount: 40, |
| 67 | + discounted_amount: 40, |
| 68 | + } |
| 69 | + ) |
| 70 | + ) { add_item(order_id, product_id) } |
| 71 | + |
| 72 | + end |
6 | 73 |
|
7 | 74 | def test_removing |
8 | | - product_1_id = SecureRandom.uuid |
9 | | - set_price(product_1_id, 20) |
| 75 | + product_id = SecureRandom.uuid |
| 76 | + set_price(product_id, 20) |
10 | 77 | order_id = SecureRandom.uuid |
11 | | - add_item(order_id, product_1_id) |
| 78 | + add_item(order_id, product_id) |
| 79 | + add_item(order_id, product_id) |
12 | 80 | stream = "Pricing::Offer$#{order_id}" |
| 81 | + |
13 | 82 | assert_events( |
14 | 83 | stream, |
| 84 | + PriceItemRemoved.new( |
| 85 | + data: { |
| 86 | + order_id: order_id, |
| 87 | + product_id: product_id, |
| 88 | + base_price: 20, |
| 89 | + price: 20, |
| 90 | + base_total_value: 20, |
| 91 | + total_value: 20, |
| 92 | + } |
| 93 | + ), |
15 | 94 | OrderTotalValueCalculated.new( |
16 | 95 | data: { |
17 | 96 | order_id: order_id, |
18 | 97 | discounted_amount: 20, |
19 | 98 | total_amount: 20 |
20 | 99 | } |
| 100 | + ), |
| 101 | + PriceItemValueCalculated.new( |
| 102 | + data: { |
| 103 | + order_id: order_id, |
| 104 | + product_id: product_id, |
| 105 | + quantity: 1, |
| 106 | + amount: 20, |
| 107 | + discounted_amount: 20, |
| 108 | + } |
21 | 109 | ) |
22 | | - ) { calculate_total_value(order_id) } |
23 | | - remove_item(order_id, product_1_id) |
| 110 | + ) { remove_item(order_id, product_id) } |
| 111 | + |
24 | 112 | assert_events( |
25 | 113 | stream, |
| 114 | + PriceItemRemoved.new( |
| 115 | + data: { |
| 116 | + order_id: order_id, |
| 117 | + product_id: product_id, |
| 118 | + base_price: 20, |
| 119 | + price: 20, |
| 120 | + base_total_value: 0, |
| 121 | + total_value: 0, |
| 122 | + } |
| 123 | + ), |
26 | 124 | OrderTotalValueCalculated.new( |
27 | 125 | data: { |
28 | 126 | order_id: order_id, |
29 | 127 | discounted_amount: 0, |
30 | 128 | total_amount: 0 |
31 | 129 | } |
32 | 130 | ) |
33 | | - ) { calculate_total_value(order_id) } |
| 131 | + ) { remove_item(order_id, product_id) } |
34 | 132 | end |
35 | 133 | end |
36 | 134 | end |
0 commit comments