-
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.
Merge pull request #378 from marlena-b/be-validation-for-supply-product
BE validation for supply product
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
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
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,67 @@ | ||
require "test_helper" | ||
|
||
class SuppliesTest < InMemoryRESIntegrationTestCase | ||
def test_happy_path | ||
product_id = register_product("Async Remote", 100, 10) | ||
|
||
get "/products/#{product_id}/supplies/new" | ||
assert_select "h1", "Supply" | ||
post "/products/#{product_id}/supplies", | ||
params: { | ||
"authenticity_token" => "[FILTERED]", | ||
"product_id" => product_id, | ||
"quantity" => "1" | ||
} | ||
follow_redirect! | ||
|
||
assert_select "#notice", "Stock level changed" | ||
end | ||
|
||
def test_renders_validation_error_when_quantity_is_not_present | ||
product_id = register_product("Async Remote", 100, 10) | ||
|
||
get "/products/#{product_id}/supplies/new" | ||
assert_select "h1", "Supply" | ||
post "/products/#{product_id}/supplies", | ||
params: { | ||
"authenticity_token" => "[FILTERED]", | ||
"product_id" => product_id, | ||
"quantity" => "" | ||
} | ||
|
||
assert_response :unprocessable_entity | ||
assert_select "span", "Quantity can't be blank" | ||
end | ||
|
||
def test_renders_validation_error_when_quantity_is_not_a_number | ||
product_id = register_product("Async Remote", 100, 10) | ||
|
||
get "/products/#{product_id}/supplies/new" | ||
assert_select "h1", "Supply" | ||
post "/products/#{product_id}/supplies", | ||
params: { | ||
"authenticity_token" => "[FILTERED]", | ||
"product_id" => product_id, | ||
"quantity" => "not a number" | ||
} | ||
|
||
assert_response :unprocessable_entity | ||
assert_select "span", "Quantity is not a number" | ||
end | ||
|
||
def test_renders_validation_error_when_quantity_is_zero | ||
product_id = register_product("Async Remote", 100, 10) | ||
|
||
get "/products/#{product_id}/supplies/new" | ||
assert_select "h1", "Supply" | ||
post "/products/#{product_id}/supplies", | ||
params: { | ||
"authenticity_token" => "[FILTERED]", | ||
"product_id" => product_id, | ||
"quantity" => "0" | ||
} | ||
|
||
assert_response :unprocessable_entity | ||
assert_select "span", "Quantity must be greater than 0" | ||
end | ||
end |