Skip to content

Commit a35c145

Browse files
committed
add more Pricing::Offer tests to extend coverage and kill mutants
1 parent 14bb5b8 commit a35c145

File tree

1 file changed

+105
-7
lines changed

1 file changed

+105
-7
lines changed

ecommerce/pricing/test/simple_offer_test.rb

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,133 @@
22

33
module Pricing
44
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
673

774
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)
1077
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)
1280
stream = "Pricing::Offer$#{order_id}"
81+
1382
assert_events(
1483
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+
),
1594
OrderTotalValueCalculated.new(
1695
data: {
1796
order_id: order_id,
1897
discounted_amount: 20,
1998
total_amount: 20
2099
}
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+
}
21109
)
22-
) { calculate_total_value(order_id) }
23-
remove_item(order_id, product_1_id)
110+
) { remove_item(order_id, product_id) }
111+
24112
assert_events(
25113
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+
),
26124
OrderTotalValueCalculated.new(
27125
data: {
28126
order_id: order_id,
29127
discounted_amount: 0,
30128
total_amount: 0
31129
}
32130
)
33-
) { calculate_total_value(order_id) }
131+
) { remove_item(order_id, product_id) }
34132
end
35133
end
36134
end

0 commit comments

Comments
 (0)