-
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.
Display out of stock badge for products on order creation page
- Loading branch information
Showing
15 changed files
with
180 additions
and
6 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 was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
rails_application/app/read_models/client_orders/update_product_availability.rb
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,7 @@ | ||
module ClientOrders | ||
class UpdateProductAvailability | ||
def call(event) | ||
Product.find_by(uid: event.data.fetch(:product_id)).update(available: event.data.fetch(:available)) | ||
end | ||
end | ||
end |
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
5 changes: 5 additions & 0 deletions
5
rails_application/db/migrate/20240826132237_add_available_to_products.rb
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,5 @@ | ||
class AddAvailableToProducts < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :products, :available, :integer | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
rails_application/db/migrate/20240827090619_add_available_to_client_order_products.rb
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,5 @@ | ||
class AddAvailableToClientOrderProducts < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :client_order_products, :available, :integer | ||
end | ||
end |
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,21 @@ | ||
require "test_helper" | ||
|
||
module ClientOrders | ||
class ProductTest < InMemoryTestCase | ||
cover "ClientOrders*" | ||
|
||
def test_unavailable | ||
product = Product.new(available: nil) | ||
refute product.unavailable? | ||
|
||
product = Product.new(available: 0) | ||
assert product.unavailable? | ||
|
||
product = Product.new(available: 1) | ||
refute product.unavailable? | ||
|
||
product = Product.new(available: -1) | ||
assert product.unavailable? | ||
end | ||
end | ||
end |
41 changes: 41 additions & 0 deletions
41
rails_application/test/client_orders/update_product_availability_test.rb
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,41 @@ | ||
require "test_helper" | ||
|
||
module ClientOrders | ||
class UpdateProductAvailabilityTest < InMemoryTestCase | ||
cover "ClientOrders*" | ||
|
||
def test_reflects_change | ||
product_id = prepare_product | ||
other_product_id = prepare_product | ||
|
||
supply_product(product_id, 5) | ||
|
||
assert_equal 5, Product.find_by_uid(product_id).available | ||
assert_nil Product.find_by_uid(other_product_id).available | ||
end | ||
|
||
private | ||
|
||
def prepare_product | ||
product_id = SecureRandom.uuid | ||
run_command( | ||
ProductCatalog::RegisterProduct.new( | ||
product_id: product_id, | ||
) | ||
) | ||
run_command( | ||
ProductCatalog::NameProduct.new( | ||
product_id: product_id, | ||
name: "test" | ||
) | ||
) | ||
run_command(Pricing::SetPrice.new(product_id: product_id, price: 50)) | ||
|
||
product_id | ||
end | ||
|
||
def supply_product(product_id, quantity) | ||
run_command(Inventory::Supply.new(product_id: product_id, quantity: quantity)) | ||
end | ||
end | ||
end |
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
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,21 @@ | ||
require "test_helper" | ||
|
||
module Products | ||
class ProductTest < InMemoryTestCase | ||
cover "Products*" | ||
|
||
def test_unavailable | ||
product = Product.new(available: nil) | ||
refute product.unavailable? | ||
|
||
product = Product.new(available: 0) | ||
assert product.unavailable? | ||
|
||
product = Product.new(available: 1) | ||
refute product.unavailable? | ||
|
||
product = Product.new(available: -1) | ||
assert product.unavailable? | ||
end | ||
end | ||
end |