-
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.
- Loading branch information
Showing
10 changed files
with
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class RefundsController < ApplicationController | ||
def new | ||
@order = Orders::Order.find_by_uid(params[:order_id]) | ||
@refund = Refunds::Refund.new | ||
@order_lines = Orders::OrderLine.where(order_uid: params[:order_id]) | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
rails_application/app/read_models/refunds/configuration.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,20 @@ | ||
module Refunds | ||
class Refund < ApplicationRecord | ||
self.table_name = "refunds" | ||
|
||
has_many :refund_items, | ||
class_name: "Refunds::RefundItem", | ||
foreign_key: :order_uid, | ||
primary_key: :uid | ||
end | ||
|
||
class RefundItem < ApplicationRecord | ||
self.table_name = "refund_items" | ||
end | ||
|
||
class Configuration | ||
def call(event_store) | ||
@event_store = event_store | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<% content_for(:header) do %> | ||
Refund for Order <%= @order.number %> | ||
<% end %> | ||
|
||
<% content_for(:actions) do %> | ||
<%= secondary_action_button do %> | ||
<%= link_to 'Back', orders_path %> | ||
<% end %> | ||
|
||
<%= primary_form_action_button do %> | ||
Submit Refund | ||
<% end %> | ||
<% end %> | ||
|
||
<table class="w-full"> | ||
<thead> | ||
<tr class="border-b"> | ||
<th class="text-left py-2">Product</th> | ||
<th class="text-left py-2">Quantity</th> | ||
<th class="text-left py-2">Price</th> | ||
<th class="text-left py-2" colspan="3">Value</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @order_lines.each do |order_line| %> | ||
<tr class="border-b" id="order_line_product_<%= order_line.product_id %>"> | ||
<td class="py-2"><%= order_line.product_name %></td> | ||
<td class="py-2">0 / <%= order_line.quantity %></td> | ||
<td class="py-2"><%= number_to_currency(order_line.price) %></td> | ||
<td class="py-2"><%= number_to_currency(order_line.value) %></td> | ||
<td class="py-2"><%= button_to "Add", "#", class: "hover:underline text-blue-500" %></td> | ||
<td class="py-2 text-right"><%= button_to("Remove", "#", class: "hover:underline text-blue-500") %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
<tfoot class="border-t-4"> | ||
<tr class="border-t"> | ||
<td class="py-2" colspan="3">Total</td> | ||
<td class="py-2 font-bold"></td></td> | ||
</tr> | ||
</tfoot> | ||
</table> |
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
12 changes: 12 additions & 0 deletions
12
rails_application/db/migrate/20241209100544_create_refunds.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,12 @@ | ||
class CreateRefunds < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :refunds do |t| | ||
t.uuid :uid, null: false | ||
t.uuid :order_uid, null: false | ||
t.string :status, null: false | ||
t.decimal :total_value, precision: 8, scale: 2, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
rails_application/db/migrate/20241209102208_create_refund_items.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,12 @@ | ||
class CreateRefundItems < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table :refund_items do |t| | ||
t.uuid :refund_uid, null: false | ||
t.uuid :product_uid, null: false | ||
t.integer :quantity, null: false | ||
t.decimal :price, precision: 8, scale: 2, null: false | ||
|
||
t.timestamps | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "test_helper" | ||
|
||
class RefundsTest < InMemoryRESIntegrationTestCase | ||
def setup | ||
super | ||
add_available_vat_rate(10) | ||
end | ||
|
||
def test_happy_path | ||
shopify_id = register_customer("Shopify") | ||
order_id = SecureRandom.uuid | ||
async_remote_id = register_product("Async Remote", 39, 10) | ||
fearless_id = register_product("Fearless Refactoring", 49, 10) | ||
|
||
add_product_to_basket(order_id, async_remote_id) | ||
add_product_to_basket(order_id, fearless_id) | ||
add_product_to_basket(order_id, fearless_id) | ||
submit_order(shopify_id, order_id) | ||
|
||
get "/orders/#{order_id}" | ||
|
||
assert_select("a", "Refund") | ||
|
||
get "/orders/#{order_id}/refunds/new" | ||
|
||
assert_order_line_row(async_remote_id, "Async Remote", 1) | ||
assert_order_line_row(fearless_id, "Fearless Refactoring", 2) | ||
end | ||
|
||
private | ||
|
||
def assert_order_line_row(product_id, product_name, quantity) | ||
assert_select("#order_line_product_#{product_id}") do | ||
assert_select("td", product_name) | ||
assert_select("td", "0 / #{quantity}") | ||
end | ||
end | ||
end |