-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before changing this part of the code it is good to know that we are not going to break anything. In order to make testing easier I decided to add `id` of product to each table row
- Loading branch information
1 parent
00c65f2
commit 8121adf
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "test_helper" | ||
|
||
class SuppliesTest < InMemoryRESIntegrationTestCase | ||
def setup | ||
super | ||
end | ||
|
||
def test_supply_new_product | ||
create_product | ||
product = Product.find_by(sku:) | ||
increase_stock_level_by_10(product.id) | ||
|
||
follow_redirect! | ||
|
||
assert_select "tr#product_#{product.id}" do | ||
assert_select "td", "10" | ||
end | ||
assert_equal(10, product.reload.stock_level) | ||
end | ||
|
||
def test_supply_product_with_existing_stock | ||
create_product | ||
product = Product.find_by(sku:) | ||
increase_stock_level_by_10(product.id) | ||
|
||
assert_changes -> { Product.find(product.id).stock_level }, from: 10, to: 20 do | ||
increase_stock_level_by_10(product.id) | ||
end | ||
|
||
follow_redirect! | ||
|
||
assert_select "tr#product_#{product.id}" do | ||
assert_select "td", "20" | ||
end | ||
end | ||
|
||
private | ||
|
||
def increase_stock_level_by_10(product_id) | ||
post "/products/#{product_id}/supplies", params: { product_id: product_id, quantity: 10 } | ||
end | ||
|
||
def create_product | ||
post "/products", params: { product: { name: "Stanley Cup", price: 100, vat_rate: 23, sku: } } | ||
end | ||
|
||
def sku | ||
"SKU-ST4NL3Y" | ||
end | ||
end |