-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Result pattern to exceptions #395
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,7 @@ def test_successful_order_submission | |
prepare_product(product_id, "Async Remote", 49) | ||
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id)) | ||
|
||
result = Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call | ||
|
||
assert_equal result.status, :success | ||
assert_equal true, Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try to test some actual effect of running this service object (read model value?) instead of testing it's return value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thank you for your comments! :) |
||
end | ||
|
||
def test_order_submission_with_unavailable_products | ||
|
@@ -32,32 +30,11 @@ def test_order_submission_with_unavailable_products | |
prepare_product(another_product_id, "Fearless Refactoring", 49) | ||
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: another_product_id)) | ||
|
||
result = Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call | ||
|
||
assert_equal result.status, :products_out_of_stock | ||
assert_equal result.args, [["Async Remote"]] | ||
end | ||
|
||
def test_order_submission_with_empty_order | ||
order_id = SecureRandom.uuid | ||
customer_id = SecureRandom.uuid | ||
|
||
result = Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call | ||
|
||
assert_equal result.status, :order_is_empty | ||
end | ||
|
||
def test_order_submission_with_non_existing_customer | ||
order_id = SecureRandom.uuid | ||
customer_id = SecureRandom.uuid | ||
product_id = SecureRandom.uuid | ||
|
||
prepare_product(product_id, "Async Remote", 49) | ||
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id)) | ||
|
||
result = Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call | ||
error = assert_raises(Orders::OrderHasUnavailableProducts) do | ||
Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call | ||
end | ||
|
||
assert_equal result.status, :customer_not_exists | ||
assert_equal ["Async Remote"], error.unavailable_products | ||
end | ||
|
||
private | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service objects ideally should have "void" type, we shouldn't rely on the return value - it either raises exception or its success.