Skip to content

Commit

Permalink
Applied namespaces changes to zeitwerk/mutant/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejkrzywda committed Sep 27, 2024
1 parent fcc771d commit 52b05a7
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 324 deletions.
12 changes: 6 additions & 6 deletions rails_application/.mutant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ matcher:
- ClientOrders::Configuration#subscribe_and_link_to_stream
- ClientOrders::Configuration#link_to_stream
- ClientOrders::Configuration#with_order
- ClientOrders::OrdersList*
- ClientOrders::Rendering::OrdersList*
- ClientOrders::RemoveItemFromOrder*
- ClientOrders::AddItemToOrder*
- ClientOrders::ChangeProductName*
- ClientOrders::ChangeProductPrice*
- ClientOrders::RegisterProduct*
- ClientOrders::ShowOrder*
- ClientOrders::EditOrder*
- ClientOrders::ProductHandlers::ChangeProductName*
- ClientOrders::ProductHandlers::ChangeProductPrice*
- ClientOrders::ProductHandlers::RegisterProduct*
- ClientOrders::Rendering::ShowOrder*
- ClientOrders::Rendering::EditOrder*
- Orders::Broadcaster*
- Orders::AddItemToOrder*
- Orders::RemoveItemFromOrder*
Expand Down
6 changes: 3 additions & 3 deletions rails_application/app/controllers/client/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Client
class OrdersController < BaseController

def index
render html: ClientOrders::OrdersList.build(view_context, cookies[:client_id]), layout: true
render html: ClientOrders::Rendering::OrdersList.build(view_context, cookies[:client_id]), layout: true
end

def new
Expand All @@ -22,12 +22,12 @@ def create
end

def show
render html: ClientOrders::ShowOrder.build(view_context, params[:id]), layout: true
render html: ClientOrders::Rendering::ShowOrder.build(view_context, params[:id]), layout: true
end

def edit
order_id = params[:id]
render html: ClientOrders::EditOrder.build(view_context, order_id), layout: true
render html: ClientOrders::Rendering::EditOrder.build(view_context, order_id), layout: true
end

def add_item
Expand Down
26 changes: 13 additions & 13 deletions rails_application/app/read_models/client_orders/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ class Product < ApplicationRecord

class Configuration
def call(event_store)
event_store.subscribe(ExpireOrder, to: [Ordering::OrderExpired])
event_store.subscribe(CancelOrder, to: [Fulfillment::OrderCancelled])
event_store.subscribe(SubmitOrder, to: [Ordering::OrderPlaced])
event_store.subscribe(ConfirmOrder, to: [Fulfillment::OrderConfirmed])
event_store.subscribe(OrderHandlers::ExpireOrder, to: [Ordering::OrderExpired])
event_store.subscribe(OrderHandlers::CancelOrder, to: [Fulfillment::OrderCancelled])
event_store.subscribe(OrderHandlers::SubmitOrder, to: [Ordering::OrderPlaced])
event_store.subscribe(OrderHandlers::ConfirmOrder, to: [Fulfillment::OrderConfirmed])
event_store.subscribe(AddItemToOrder, to: [Ordering::ItemAddedToBasket])
event_store.subscribe(RemoveItemFromOrder, to: [Ordering::ItemRemovedFromBasket])

event_store.subscribe(CreateCustomer.new, to: [Crm::CustomerRegistered])
event_store.subscribe(AssignCustomerToOrder, to: [Crm::CustomerAssignedToOrder])
event_store.subscribe(OrderHandlers::AssignCustomerToOrder, to: [Crm::CustomerAssignedToOrder])

event_store.subscribe(ChangeProductName, to: [ProductCatalog::ProductNamed])
event_store.subscribe(ChangeProductPrice, to: [Pricing::PriceSet])
event_store.subscribe(RegisterProduct, to: [ProductCatalog::ProductRegistered])
event_store.subscribe(UpdateProductAvailability, to: [Inventory::AvailabilityChanged])
event_store.subscribe(UpdateDiscount, to: [Pricing::PercentageDiscountSet, Pricing::PercentageDiscountChanged])
event_store.subscribe(ResetDiscount, to: [Pricing::PercentageDiscountReset])
event_store.subscribe(UpdateOrderTotalValue, to: [Pricing::OrderTotalValueCalculated])
event_store.subscribe(UpdatePaidOrdersSummary, to: [Fulfillment::OrderConfirmed])
event_store.subscribe(ProductHandlers::ChangeProductName, to: [ProductCatalog::ProductNamed])
event_store.subscribe(ProductHandlers::ChangeProductPrice, to: [Pricing::PriceSet])
event_store.subscribe(ProductHandlers::RegisterProduct, to: [ProductCatalog::ProductRegistered])
event_store.subscribe(ProductHandlers::UpdateProductAvailability, to: [Inventory::AvailabilityChanged])
event_store.subscribe(OrderHandlers::UpdateDiscount, to: [Pricing::PercentageDiscountSet, Pricing::PercentageDiscountChanged])
event_store.subscribe(OrderHandlers::ResetDiscount, to: [Pricing::PercentageDiscountReset])
event_store.subscribe(OrderHandlers::UpdateOrderTotalValue, to: [Pricing::OrderTotalValueCalculated])
event_store.subscribe(OrderHandlers::UpdatePaidOrdersSummary, to: [Fulfillment::OrderConfirmed])
end
end
end
121 changes: 61 additions & 60 deletions rails_application/app/read_models/client_orders/order_handlers.rb
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
module ClientOrders

class ConfirmOrder
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.state = "Paid"
order.save!
module OrderHandlers
class ConfirmOrder
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.state = "Paid"
order.save!
end
end
end

class SubmitOrder
def call(event)
order = Order.find_or_create_by(order_uid: event.data.fetch(:order_id))
order.number = event.data.fetch(:order_number)
order.state = "Submitted"
order.save!
class SubmitOrder
def call(event)
order = Order.find_or_create_by(order_uid: event.data.fetch(:order_id))
order.number = event.data.fetch(:order_number)
order.state = "Submitted"
order.save!
end
end
end

class UpdateDiscount
def call(event)
order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id))
order.percentage_discount = event.data.fetch(:amount)
order.save!
class UpdateDiscount
def call(event)
order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id))
order.percentage_discount = event.data.fetch(:amount)
order.save!
end
end
end

class UpdateOrderTotalValue
def call(event)
order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id)) { |order| order.state = "Draft" }
order.discounted_value = event.data.fetch(:discounted_amount)
order.total_value = event.data.fetch(:total_amount)
order.save!
class UpdateOrderTotalValue
def call(event)
order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id)) { |order| order.state = "Draft" }
order.discounted_value = event.data.fetch(:discounted_amount)
order.total_value = event.data.fetch(:total_amount)
order.save!
end
end
end

class UpdatePaidOrdersSummary
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
client = Client.where(uid: order.client_uid).first
client.update(paid_orders_summary: client.paid_orders_summary + order.discounted_value)
class UpdatePaidOrdersSummary
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
client = Client.where(uid: order.client_uid).first
client.update(paid_orders_summary: client.paid_orders_summary + order.discounted_value)
end
end
end

class ExpireOrder
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.state = "Expired"
order.save!
class ExpireOrder
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.state = "Expired"
order.save!
end
end
end

class CancelOrder
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.state = "Cancelled"
order.save!
class CancelOrder
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.state = "Cancelled"
order.save!
end
end
end

class AssignCustomerToOrder
def call(event)
order_uid = event.data.fetch(:order_id)
order = Order.find_by(order_uid: order_uid)
class AssignCustomerToOrder
def call(event)
order_uid = event.data.fetch(:order_id)
order = Order.find_by(order_uid: order_uid)

if order.nil?
order = Order.create!(order_uid: order_uid, state: "Draft")
end
if order.nil?
order = Order.create!(order_uid: order_uid, state: "Draft")
end

order.client_uid = event.data.fetch(:customer_id)
order.save!
order.client_uid = event.data.fetch(:customer_id)
order.save!
end
end
end

class ResetDiscount
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.percentage_discount = nil
order.save!
class ResetDiscount
def call(event)
order = Order.find_by(order_uid: event.data.fetch(:order_id))
order.percentage_discount = nil
order.save!
end
end
end
end
40 changes: 21 additions & 19 deletions rails_application/app/read_models/client_orders/product_handlers.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
module ClientOrders
class RegisterProduct
def call(event)
Product.find_or_create_by(uid: event.data.fetch(:product_id))
module ProductHandlers
class RegisterProduct
def call(event)
Product.find_or_create_by(uid: event.data.fetch(:product_id))
end
end
end

class ChangeProductName
def call(event)
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(
name: event.data.fetch(:name)
)
class ChangeProductName
def call(event)
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(
name: event.data.fetch(:name)
)
end
end
end

class ChangeProductPrice
def call(event)
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(price: event.data.fetch(:price))
class ChangeProductPrice
def call(event)
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(price: event.data.fetch(:price))
end
end
end

class UpdateProductAvailability
def call(event)
product = Product.find_by(uid: event.data.fetch(:product_id))
available = event.data.fetch(:available)
class UpdateProductAvailability
def call(event)
product = Product.find_by(uid: event.data.fetch(:product_id))
available = event.data.fetch(:available)

product.update(available: available.positive?)
product.update(available: available.positive?)
end
end
end
end
Loading

0 comments on commit 52b05a7

Please sign in to comment.