Skip to content

Commit e5f75dc

Browse files
committed
fix tests
mostly by using Pricing or Fulfillment commands and eventst instead of using Ordering ones
1 parent be148b7 commit e5f75dc

File tree

10 files changed

+19
-26
lines changed

10 files changed

+19
-26
lines changed

ecommerce/pricing/test/apply_time_promotion_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative "test_helper"
2+
require "timecop"
23

34
module Pricing
45
class ApplyTimePromotionTest < Test
@@ -60,7 +61,9 @@ def item_added_to_basket_event(order_id, product_id)
6061
Pricing::PriceItemAdded.new(
6162
data: {
6263
product_id: product_id,
63-
order_id: order_id
64+
order_id: order_id,
65+
price: 100,
66+
catalog_price: 100
6467
}
6568
)
6669
end

rails_application/app/controllers/client/orders_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def create
1515
rescue Orders::OrderHasUnavailableProducts => e
1616
unavailable_products = e.unavailable_products.join(", ")
1717
redirect_to edit_client_order_path(params[:order_id]), alert: "Order can not be submitted! #{unavailable_products} not available in requested quantity!"
18-
rescue Ordering::Order::IsEmpty
18+
rescue Pricing::CantAcceptEmptyOffer
1919
redirect_to edit_client_order_path(params[:order_id]), alert: "You can't submit an empty order"
2020
else
2121
redirect_to client_order_path(params[:order_id]), notice: "Your order is being submitted"

rails_application/app/controllers/orders_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def create
8181
rescue Orders::OrderHasUnavailableProducts => e
8282
unavailable_products = e.unavailable_products.join(", ")
8383
redirect_to edit_order_path(params[:order_id]), alert: "Order can not be submitted! #{unavailable_products} not available in requested quantity!"
84-
rescue Ordering::Order::IsEmpty
84+
rescue Pricing::CantAcceptEmptyOffer
8585
redirect_to edit_order_path(params[:order_id]), alert: "You can't submit an empty order"
8686
rescue Crm::Customer::NotExists
8787
redirect_to order_path(params[:order_id]), alert: "Order can not be submitted! Customer does not exist."

rails_application/test/client_orders/order_cancelled_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_order_confirmed
1919
))
2020

2121
create_product(product_id, "Async Remote", 30)
22-
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))
22+
run_command(Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id))
2323
run_command(Ordering::SubmitOrder.new(order_id: order_id, order_number: order_number))
2424

2525
event_store.publish(

rails_application/test/client_orders/order_paid_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_order_confirmed
1313

1414
run_command(Crm::RegisterCustomer.new(customer_id: customer_id, name: "John Doe"))
1515
create_product(product_id, "Async Remote", 30)
16-
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))
16+
run_command(Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id))
1717

1818
event_store.publish(
1919
Pricing::OrderTotalValueCalculated.new(

rails_application/test/client_orders/update_paid_orders_summary_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def set_price_to_product(product_id, price)
5454
end
5555

5656
def add_item_to_basket(order_id, product_id)
57-
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))
57+
run_command(Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id))
5858
end
5959

6060
def confirm_order(customer_id, order_id, total_amount)

rails_application/test/customers/update_paid_orders_summary_test.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_update_orders_summary
2626
add_item_to_basket(order_id, product_id)
2727
confirm_order(customer_id, order_id, 6)
2828

29-
customer = Customer.find(customer_id)
29+
customer.reload
3030
assert_equal 9.to_d, customer.paid_orders_summary
3131
end
3232

@@ -49,20 +49,11 @@ def set_price_to_product(product_id, price)
4949
end
5050

5151
def add_item_to_basket(order_id, product_id)
52-
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))
52+
run_command(Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id))
5353
end
5454

5555
def confirm_order(customer_id, order_id, total_amount)
5656
order_number = Ordering::FakeNumberGenerator::FAKE_NUMBER
57-
event_store.publish(
58-
Pricing::OrderTotalValueCalculated.new(
59-
data: {
60-
order_id: order_id,
61-
discounted_amount: total_amount,
62-
total_amount: total_amount
63-
}
64-
)
65-
)
6657
run_command(
6758
Crm::AssignCustomerToOrder.new(customer_id: customer_id, order_id: order_id)
6859
)

rails_application/test/orders/order_cancelled_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_cancel_confirmed_order
88
event_store = Rails.configuration.event_store
99
customer_id = SecureRandom.uuid
1010
order_id = SecureRandom.uuid
11-
order_number = Ordering::FakeNumberGenerator::FAKE_NUMBER
11+
order_number = Fulfillment::FakeNumberGenerator::FAKE_NUMBER
1212
product_id = SecureRandom.uuid
1313

1414
event_store.publish(Crm::CustomerRegistered.new(
@@ -19,8 +19,8 @@ def test_cancel_confirmed_order
1919
))
2020

2121
create_product(product_id, "Async Remote", 30)
22-
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))
23-
run_command(Ordering::SubmitOrder.new(order_id: order_id, order_number: order_number))
22+
run_command(Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id))
23+
run_command(Pricing::AcceptOffer.new(order_id: order_id))
2424

2525
order_cancelled = Fulfillment::OrderCancelled.new(
2626
data: {

rails_application/test/orders/order_paid_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def test_order_confirmed
88
event_store = Rails.configuration.event_store
99
customer_id = SecureRandom.uuid
1010
order_id = SecureRandom.uuid
11-
order_number = Ordering::FakeNumberGenerator::FAKE_NUMBER
11+
order_number = Fulfillment::FakeNumberGenerator::FAKE_NUMBER
1212
product_id = SecureRandom.uuid
1313

1414
create_product(product_id, "Async Remote", 10)
1515
run_command(Crm::RegisterCustomer.new(customer_id: customer_id, name: "John Doe"))
16-
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))
17-
run_command(Ordering::SubmitOrder.new(order_id: order_id, order_number: order_number))
16+
run_command(Pricing::AddPriceItem.new(order_id: order_id, product_id: product_id))
17+
run_command(Pricing::AcceptOffer.new(order_id: order_id))
1818
run_command(
1919
Crm::AssignCustomerToOrder.new(customer_id: customer_id, order_id: order_id)
2020
)

rails_application/test/orders/order_placed_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_create_when_not_exists
2222
)
2323
run_command(Pricing::SetPrice.new(product_id: product_id, price: 20))
2424
order_id = SecureRandom.uuid
25-
order_number = Ordering::FakeNumberGenerator::FAKE_NUMBER
25+
order_number = Fulfillment::FakeNumberGenerator::FAKE_NUMBER
2626

2727
event_store.publish(
2828
Pricing::PriceItemAdded.new(
@@ -34,11 +34,10 @@ def test_create_when_not_exists
3434
}
3535
)
3636
)
37-
order_placed = Ordering::OrderPlaced.new(
37+
order_placed = Fulfillment::OrderRegistered.new(
3838
data: {
3939
order_id: order_id,
4040
order_number: order_number,
41-
order_lines: { product_id => 1 }
4241
}
4342
)
4443
event_store.publish(order_placed)

0 commit comments

Comments
 (0)