diff --git a/rails_application/.mutant.yml b/rails_application/.mutant.yml index 2510e3ca..01ecf292 100644 --- a/rails_application/.mutant.yml +++ b/rails_application/.mutant.yml @@ -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* diff --git a/rails_application/app/controllers/client/orders_controller.rb b/rails_application/app/controllers/client/orders_controller.rb index 8cfd2dc5..5c42e5fa 100644 --- a/rails_application/app/controllers/client/orders_controller.rb +++ b/rails_application/app/controllers/client/orders_controller.rb @@ -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 @@ -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 diff --git a/rails_application/app/read_models/client_orders/configuration.rb b/rails_application/app/read_models/client_orders/configuration.rb index 735772e7..74f010be 100644 --- a/rails_application/app/read_models/client_orders/configuration.rb +++ b/rails_application/app/read_models/client_orders/configuration.rb @@ -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 diff --git a/rails_application/app/read_models/client_orders/order_handlers.rb b/rails_application/app/read_models/client_orders/order_handlers.rb index ae2dce03..517cad68 100644 --- a/rails_application/app/read_models/client_orders/order_handlers.rb +++ b/rails_application/app/read_models/client_orders/order_handlers.rb @@ -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 diff --git a/rails_application/app/read_models/client_orders/product_handlers.rb b/rails_application/app/read_models/client_orders/product_handlers.rb index 36df6717..17e4c8f7 100644 --- a/rails_application/app/read_models/client_orders/product_handlers.rb +++ b/rails_application/app/read_models/client_orders/product_handlers.rb @@ -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 diff --git a/rails_application/app/read_models/client_orders/rendering/edit_order.rb b/rails_application/app/read_models/client_orders/rendering/edit_order.rb index 503ab998..6428d0b5 100644 --- a/rails_application/app/read_models/client_orders/rendering/edit_order.rb +++ b/rails_application/app/read_models/client_orders/rendering/edit_order.rb @@ -1,93 +1,95 @@ module ClientOrders - class EditOrder < Arbre::Component - include Rails.application.routes.url_helpers - include ActionView::Helpers::FormTagHelper - include ActionView::Helpers::UrlHelper + module Rendering + class EditOrder < Arbre::Component + include Rails.application.routes.url_helpers + include ActionView::Helpers::FormTagHelper + include ActionView::Helpers::UrlHelper - def self.build(view_context, order_id) - order_lines = ClientOrders::OrderLine.where(order_uid: order_id) - products = ClientOrders::Product.all - new(Arbre::Context.new(nil, view_context)).build(order_id, order_lines, products) - end + def self.build(view_context, order_id) + order_lines = ClientOrders::OrderLine.where(order_uid: order_id) + products = ClientOrders::Product.all + new(Arbre::Context.new(nil, view_context)).build(order_id, order_lines, products) + end - def build(order_id, order_lines, products, attributes = {}) - super(attributes) - div do - products_table(order_id, products, order_lines) - coupon_form(order_id) - submit_form(order_id) + def build(order_id, order_lines, products, attributes = {}) + super(attributes) + div do + products_table(order_id, products, order_lines) + coupon_form(order_id) + submit_form(order_id) + end end - end - private + private - def products_table(order_id, products, order_lines) - table class: "w-full" do - headers_row - tbody do - text_node turbo_stream_from "client_orders_#{order_id}" - products.each do |product| - product_row(order_id, product, order_lines) + def products_table(order_id, products, order_lines) + table class: "w-full" do + headers_row + tbody do + text_node turbo_stream_from "client_orders_#{order_id}" + products.each do |product| + product_row(order_id, product, order_lines) + end end end end - end - def headers_row - thead do - tr do - th(class: "text-left py-2") { "Product" } - th(class: "text-left py-2") { "" } - th(class: "text-left py-2") { "Quantity" } - th(class: "text-left py-2") { "Price" } - th(class: "text-left py-2", colspan: 3) { "Value" } + def headers_row + thead do + tr do + th(class: "text-left py-2") { "Product" } + th(class: "text-left py-2") { "" } + th(class: "text-left py-2") { "Quantity" } + th(class: "text-left py-2") { "Price" } + th(class: "text-left py-2", colspan: 3) { "Value" } + end end end - end - def product_row(order_id, product, order_lines) - order_line = order_lines&.find { |order_line| order_line.product_id == product.uid } - tr class: "border-b" do - td(class: "py-2") { product.name } - td(class: "py-2") { out_of_stock_badge unless product.available? } - td(class: "py-2", id: "client_orders_#{product.uid}_product_quantity") { order_line.try(&:product_quantity) || 0 } - td(class: "py-2") { number_to_currency(product.price) } - td(class: "py-2", id: "client_orders_#{product.uid}_value") { number_to_currency(order_line.try(&:value)) } - td(class: "py-2 text-right") { add_item_button(order_id, product.uid) } - td(class: "py-2 text-right", id: "client_orders_#{product.uid}_remove_item_button") { remove_item_button(order_id, product.uid) if order_line } + def product_row(order_id, product, order_lines) + order_line = order_lines&.find { |order_line| order_line.product_id == product.uid } + tr class: "border-b" do + td(class: "py-2") { product.name } + td(class: "py-2") { out_of_stock_badge unless product.available? } + td(class: "py-2", id: "client_orders_#{product.uid}_product_quantity") { order_line.try(&:product_quantity) || 0 } + td(class: "py-2") { number_to_currency(product.price) } + td(class: "py-2", id: "client_orders_#{product.uid}_value") { number_to_currency(order_line.try(&:value)) } + td(class: "py-2 text-right") { add_item_button(order_id, product.uid) } + td(class: "py-2 text-right", id: "client_orders_#{product.uid}_remove_item_button") { remove_item_button(order_id, product.uid) if order_line } + end end - end - def out_of_stock_badge - span "out of stock", class: "rounded-lg bg-yellow-400 text-yellow-900 px-2 py-0.5" - end + def out_of_stock_badge + span "out of stock", class: "rounded-lg bg-yellow-400 text-yellow-900 px-2 py-0.5" + end - def add_item_button(order_id, product_id) - button_to "Add", add_item_client_order_path(id: order_id, product_id: product_id), class: "hover:underline text-blue-500" - end + def add_item_button(order_id, product_id) + button_to "Add", add_item_client_order_path(id: order_id, product_id: product_id), class: "hover:underline text-blue-500" + end - def remove_item_button(order_id, product_id) - button_to "Remove", remove_item_client_order_path(id: order_id, product_id: product_id), class: "hover:underline text-blue-500" - end + def remove_item_button(order_id, product_id) + button_to "Remove", remove_item_client_order_path(id: order_id, product_id: product_id), class: "hover:underline text-blue-500" + end - def coupon_form(order_id) - form(action: use_coupon_client_order_path(id: order_id), method: :post, class: "inline-flex gap-4 mt-8") do - input( - id: "coupon_code", - type: :text, - name: :coupon_code, - class: "focus:ring-blue-500 focus:border-blue-500 block shadow-sm sm:text-sm border-gray-300 rounded-md", - "data-turbo-permanent": true - ) - input(type: :submit, value: "Use Coupon", class: "px-4 py-2 border rounded-md shadow-sm text-sm font-medium border-gray-300 text-gray-700 bg-white hover:bg-gray-50") + def coupon_form(order_id) + form(action: use_coupon_client_order_path(id: order_id), method: :post, class: "inline-flex gap-4 mt-8") do + input( + id: "coupon_code", + type: :text, + name: :coupon_code, + class: "focus:ring-blue-500 focus:border-blue-500 block shadow-sm sm:text-sm border-gray-300 rounded-md", + "data-turbo-permanent": true + ) + input(type: :submit, value: "Use Coupon", class: "px-4 py-2 border rounded-md shadow-sm text-sm font-medium border-gray-300 text-gray-700 bg-white hover:bg-gray-50") + end end - end - def submit_form(order_id) - form(id: "form", action: client_orders_path, method: :post) do - input(type: :hidden, name: :order_id, value: order_id) - div(class: "mt-8") do - input type: :submit, value: "Create Order", class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" + def submit_form(order_id) + form(id: "form", action: client_orders_path, method: :post) do + input(type: :hidden, name: :order_id, value: order_id) + div(class: "mt-8") do + input type: :submit, value: "Create Order", class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" + end end end end diff --git a/rails_application/app/read_models/client_orders/rendering/orders_list.rb b/rails_application/app/read_models/client_orders/rendering/orders_list.rb index c73cd0fa..e240e530 100644 --- a/rails_application/app/read_models/client_orders/rendering/orders_list.rb +++ b/rails_application/app/read_models/client_orders/rendering/orders_list.rb @@ -1,111 +1,113 @@ module ClientOrders - class OrdersList < Arbre::Component - include Rails.application.routes.url_helpers + module Rendering + class OrdersList < Arbre::Component + include Rails.application.routes.url_helpers - def self.build(view_context, client_id) - new(Arbre::Context.new(nil, view_context)).build( - Client.find_by(uid: client_id), - Order.where(client_uid: client_id) - ) - end - - def build(client, client_orders, attributes = {}) - super(attributes) - - div class: "max-w-6xl mx-auto py-6 sm:px-6 lg:px-8" do - client_name_header(client) - orders_table(client, client_orders) - new_order_button + def self.build(view_context, client_id) + new(Arbre::Context.new(nil, view_context)).build( + Client.find_by(uid: client_id), + Order.where(client_uid: client_id) + ) end - end + def build(client, client_orders, attributes = {}) + super(attributes) - private + div class: "max-w-6xl mx-auto py-6 sm:px-6 lg:px-8" do + client_name_header(client) + orders_table(client, client_orders) + new_order_button + end - def client_name_header(client) - h1 class: "text-3xl font-bold text-gray-900" do - client.name end - end - def orders_table(client, client_orders) - return no_orders_message if client_orders.empty? - orders_table_content(client, client_orders) - end + private - def orders_table_content(client, client_orders) - table class: "w-full", id: "orders" do - headers_row - tbody do - orders_rows(client_orders) - summary_row(client) + def client_name_header(client) + h1 class: "text-3xl font-bold text-gray-900" do + client.name end end - end - def no_orders_message - para class: "py-6" do - "No orders to display." + def orders_table(client, client_orders) + return no_orders_message if client_orders.empty? + orders_table_content(client, client_orders) end - end - def summary_row(client) - tr class: "border-t font-bold" do - td colspan: 2, class: "py-2" do - para "Total paid orders" + def orders_table_content(client, client_orders) + table class: "w-full", id: "orders" do + headers_row + tbody do + orders_rows(client_orders) + summary_row(client) + end end - td class: "py-2 text-right border-t" do - number_to_currency(client.paid_orders_summary) + end + + def no_orders_message + para class: "py-6" do + "No orders to display." end end - end - def orders_rows(client_orders) - client_orders.each do |client_order| - tr class: "border-t" do - td class: "py-2" do - para(order_link_with_order_number(client_order) || 'Not submitted') + def summary_row(client) + tr class: "border-t font-bold" do + td colspan: 2, class: "py-2" do + para "Total paid orders" end - td class: "py-2 text-left" do - client_order.state - end - td class: "py-2 text-right" do - number_to_currency(client_order.discounted_value) + td class: "py-2 text-right border-t" do + number_to_currency(client.paid_orders_summary) end end end - end - def headers_row - thead do - tr class: "border-t" do - th class: "text-left py-2" do - "Number" - end - th class: "text-left py-2" do - "State" + def orders_rows(client_orders) + client_orders.each do |client_order| + tr class: "border-t" do + td class: "py-2" do + para(order_link_with_order_number(client_order) || 'Not submitted') + end + td class: "py-2 text-left" do + client_order.state + end + td class: "py-2 text-right" do + number_to_currency(client_order.discounted_value) + end end - th class: "text-right py-2" do - "Price" + end + end + + def headers_row + thead do + tr class: "border-t" do + th class: "text-left py-2" do + "Number" + end + th class: "text-left py-2" do + "State" + end + th class: "text-right py-2" do + "Price" + end end end end - end - def new_order_button - para( - link_to( - "New order", - new_client_order_path, - class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded")) - end + def new_order_button + para( + link_to( + "New order", + new_client_order_path, + class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded")) + end - def order_link_with_order_number(order) - link_to( - order.number, - client_order_path(order.order_uid), - class: "text-blue-500 hover:text-blue-700" - ) + def order_link_with_order_number(order) + link_to( + order.number, + client_order_path(order.order_uid), + class: "text-blue-500 hover:text-blue-700" + ) + end end end end \ No newline at end of file diff --git a/rails_application/app/read_models/client_orders/rendering/show_order.rb b/rails_application/app/read_models/client_orders/rendering/show_order.rb index 27611d83..c0b242cf 100644 --- a/rails_application/app/read_models/client_orders/rendering/show_order.rb +++ b/rails_application/app/read_models/client_orders/rendering/show_order.rb @@ -1,103 +1,105 @@ module ClientOrders - class ShowOrder < Arbre::Component - include Rails.application.routes.url_helpers + module Rendering + class ShowOrder < Arbre::Component + include Rails.application.routes.url_helpers - def self.build(view_context, order_id) - order = ClientOrders::Order.find_by_order_uid(order_id) - order_lines = ClientOrders::OrderLine.where(order_uid: order_id) - new(Arbre::Context.new(nil, view_context)).build(order, order_lines) - end + def self.build(view_context, order_id) + order = ClientOrders::Order.find_by_order_uid(order_id) + order_lines = ClientOrders::OrderLine.where(order_uid: order_id) + new(Arbre::Context.new(nil, view_context)).build(order, order_lines) + end - def build(order, order_lines, attributes = {}) - super(attributes) - div do + def build(order, order_lines, attributes = {}) + super(attributes) div do - para(secondary_action_button { link_to 'Back', client_orders_path }) - end - div class: "max-w-6xl mx-auto py-6 sm:px-6 lg:px-8" do - header_content(order) - - div class: "mb-8" do - state_section(order) + div do + para(secondary_action_button { link_to 'Back', client_orders_path }) end + div class: "max-w-6xl mx-auto py-6 sm:px-6 lg:px-8" do + header_content(order) + + div class: "mb-8" do + state_section(order) + end - order_table(order_lines, order) + order_table(order_lines, order) + end end end - end - private + private - def header_content(order) - h2 do - "Order #{order.number}" + def header_content(order) + h2 do + "Order #{order.number}" + end end - end - def state_section(order) - dl do - dt(class: "font-bold") { "State" } - dd(class: "mb-2") { order.state } + def state_section(order) + dl do + dt(class: "font-bold") { "State" } + dd(class: "mb-2") { order.state } + end end - end - def order_table(order_lines, order) - table class: "w-full" do - headers_row - tbody do - order_lines.each do |item| - item_row(item) + def order_table(order_lines, order) + table class: "w-full" do + headers_row + tbody do + order_lines.each do |item| + item_row(item) + end end + footer_rows(order) end - footer_rows(order) end - end - def headers_row - thead do - tr do - %w[Product Quantity Price Value].each do |header| - th(class: "text-left py-2") { header } + def headers_row + thead do + tr do + %w[Product Quantity Price Value].each do |header| + th(class: "text-left py-2") { header } + end end end end - end - def item_row(item) - tr class: "border-t" do - td(class: "py-2") { item.product_name } - td(class: "py-2") { item.product_quantity } - td(class: "py-2") { number_to_currency(item.product_price) } - td(class: "py-2 text-right") { number_to_currency(item.value) } + def item_row(item) + tr class: "border-t" do + td(class: "py-2") { item.product_name } + td(class: "py-2") { item.product_quantity } + td(class: "py-2") { number_to_currency(item.product_price) } + td(class: "py-2 text-right") { number_to_currency(item.value) } + end end - end - def footer_rows(order) - tfoot class: "border-t-4" do - before_discounts_row(order) if order.discounted_value != order.total_value - general_discount_row(order) if order.percentage_discount - total_row(order) + def footer_rows(order) + tfoot class: "border-t-4" do + before_discounts_row(order) if order.discounted_value != order.total_value + general_discount_row(order) if order.percentage_discount + total_row(order) + end end - end - def before_discounts_row(order) - tr class: "border-t" do - td(class: "py-2", colspan: 3) { "Before discounts" } - td(class: "py-2 text-right", id: "before-discounts-value") { number_to_currency(order.total_value) } + def before_discounts_row(order) + tr class: "border-t" do + td(class: "py-2", colspan: 3) { "Before discounts" } + td(class: "py-2 text-right", id: "before-discounts-value") { number_to_currency(order.total_value) } + end end - end - def general_discount_row(order) - tr class: "border-t" do - td(class: "py-2", colspan: 3) { "General discount" } - td(class: "py-2 text-right") { "#{order.percentage_discount}%" } + def general_discount_row(order) + tr class: "border-t" do + td(class: "py-2", colspan: 3) { "General discount" } + td(class: "py-2 text-right") { "#{order.percentage_discount}%" } + end end - end - def total_row(order) - tr class: "border-t" do - td(class: "py-2", colspan: 3) { "Total" } - td(class: "py-2 text-right font-bold") { number_to_currency(order.discounted_value) } + def total_row(order) + tr class: "border-t" do + td(class: "py-2", colspan: 3) { "Total" } + td(class: "py-2 text-right font-bold") { number_to_currency(order.discounted_value) } + end end end end diff --git a/rails_application/test/client_orders/order_placed_test.rb b/rails_application/test/client_orders/order_placed_test.rb index 9252c5c2..d73964bd 100644 --- a/rails_application/test/client_orders/order_placed_test.rb +++ b/rails_application/test/client_orders/order_placed_test.rb @@ -87,7 +87,7 @@ def test_assign_customer_first def assert_clickable_order_number(customer_id, order_id, order_number) view_context = OrdersController.new.view_context - orders_list = ClientOrders::OrdersList.build(view_context, customer_id) + orders_list = ClientOrders::Rendering::OrdersList.build(view_context, customer_id) links_to_orders = Nokogiri::HTML(orders_list).xpath('//table').xpath(".//a") assert_equal(1, links_to_orders.size) assert_equal("/client_orders/#{order_id}", links_to_orders.first.attributes["href"].value) diff --git a/rails_application/test/client_orders/update_product_availability_test.rb b/rails_application/test/client_orders/update_product_availability_test.rb index 16f072e1..481b3e14 100644 --- a/rails_application/test/client_orders/update_product_availability_test.rb +++ b/rails_application/test/client_orders/update_product_availability_test.rb @@ -9,15 +9,15 @@ def test_reflects_change other_product_id = prepare_product assert_changes("Product.find_by_uid(product_id).available?", from: true, to: false) do - UpdateProductAvailability.new.call(availability_changed_event(product_id, -1)) + ProductHandlers::UpdateProductAvailability.new.call(availability_changed_event(product_id, -1)) end assert_changes("Product.find_by_uid(product_id).available?", from: false, to: true) do - UpdateProductAvailability.new.call(availability_changed_event(product_id, 10)) + ProductHandlers::UpdateProductAvailability.new.call(availability_changed_event(product_id, 10)) end assert_changes("Product.find_by_uid(product_id).available?", from: true, to: false) do - UpdateProductAvailability.new.call(availability_changed_event(product_id, 0)) + ProductHandlers::UpdateProductAvailability.new.call(availability_changed_event(product_id, 0)) end assert Product.find_by_uid(other_product_id).available?