Skip to content

Commit fd59e68

Browse files
Created a new InvoiceGeneration class
It should work similar to TotalOrderValue and we can then move the Pricing::Offer logic of splitting things into invoice items, to this process.
1 parent 78a3309 commit fd59e68

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

rails_application/.mutant.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ matcher:
5151
- Processes::NotifyPaymentsAboutOrderValue*
5252
- Processes::WelcomeMessageProcess*
5353
- Processes::TotalOrderValue#fetch_id
54+
- Processes::InvoiceGeneration#fetch_id

rails_application/app/processes/processes/configuration.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def call(event_store, command_bus)
2121
enable_reservation_process(event_store, command_bus)
2222
enable_welcome_message_process(event_store, command_bus)
2323
enable_total_order_value_process(event_store, command_bus)
24+
enable_invoice_generation_process(event_store, command_bus)
2425
end
2526

2627
private
@@ -133,5 +134,12 @@ def enable_total_order_value_process(event_store, command_bus)
133134
to: TotalOrderValue.subscribed_events
134135
)
135136
end
137+
138+
def enable_invoice_generation_process(event_store, command_bus)
139+
event_store.subscribe(
140+
InvoiceGeneration.new(event_store, command_bus),
141+
to: InvoiceGeneration.subscribed_events
142+
)
143+
end
136144
end
137145
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Processes
2+
class InvoiceGeneration
3+
include Infra::ProcessManager.with_state { Invoice }
4+
5+
subscribes_to(
6+
Pricing::PriceItemAdded,
7+
Pricing::PriceItemRemoved,
8+
Pricing::PercentageDiscountSet,
9+
Pricing::PercentageDiscountChanged,
10+
Pricing::PercentageDiscountRemoved
11+
)
12+
13+
14+
private
15+
16+
def fetch_id(event)
17+
event.data.fetch(:order_id)
18+
end
19+
20+
end
21+
22+
Invoice = Data.define do
23+
end
24+
25+
end

rails_application/app/processes/processes/total_order_value.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class TotalOrderValue
1010
Pricing::PercentageDiscountRemoved
1111
)
1212

13-
private
14-
1513
def act
1614
publish_total_order_value(state.subtotal, state.discounted_value)
1715
end
@@ -33,6 +31,7 @@ def apply(event)
3331
state
3432
end
3533
end
34+
3635
private
3736

3837
def publish_total_order_value(total_amount, discounted_amount)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "test_helper"
2+
3+
module Processes
4+
class InvoiceGenerationTest < ProcessTest
5+
cover "Processes::InvoiceGeneration"
6+
7+
def test_basic_invoice_generation
8+
assert true
9+
end
10+
11+
private
12+
13+
end
14+
end

0 commit comments

Comments
 (0)