Skip to content

Commit ca6e770

Browse files
Client panel: Inbox without hardcoded messages
- temporarily call read model directly from the process - it's antipattern, but step towards proper process, while being green and without making too many changes at once - so far disabled mutant, driven by integration test
1 parent 9ffce6b commit ca6e770

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

ecommerce/processes/.mutant.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ matcher:
1616
- Processes::OrderItemInvoicingProcess#fetch_id
1717
- Processes::SyncShipmentFromPricing*
1818
- Processes::SyncInventoryFromOrdering*
19-
- Processes::NotifyPaymentsAboutOrderValue*
19+
- Processes::NotifyPaymentsAboutOrderValue*
20+
- Processes::WelcomeMessageProcess*

ecommerce/processes/lib/processes.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
require_relative 'processes/sync_shipment_from_pricing'
1818
require_relative 'processes/three_plus_one_free'
1919
require_relative 'processes/reservation_process'
20+
require_relative 'processes/welcome_message_process'
2021

2122
module Processes
2223
class Configuration
@@ -39,6 +40,7 @@ def call(event_store, command_bus)
3940
enable_shipment_process(event_store, command_bus)
4041
enable_order_item_invoicing_process(event_store, command_bus)
4142
enable_reservation_process(event_store, command_bus)
43+
enable_welcome_message_process(event_store, command_bus)
4244
end
4345

4446
private
@@ -137,5 +139,12 @@ def enable_coupon_discount_process(event_store, command_bus)
137139
.call(Pricing::CouponUsed, [:order_id, :discount],
138140
Pricing::SetPercentageDiscount, [:order_id, :amount])
139141
end
142+
143+
def enable_welcome_message_process(event_store, command_bus)
144+
event_store.subscribe(
145+
WelcomeMessageProcess.new(event_store, command_bus),
146+
to: [Crm::CustomerRegistered]
147+
)
148+
end
140149
end
141150
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Processes
2+
class WelcomeMessageProcess
3+
def initialize(event_store, command_bus)
4+
@event_store = event_store
5+
@command_bus = command_bus
6+
end
7+
8+
def call(event)
9+
case event
10+
when Crm::CustomerRegistered
11+
ClientInbox::Message.create(client_uid: event.data.fetch(:customer_id), title: "Welcome to our platform!")
12+
end
13+
end
14+
end
15+
end

rails_application/app/read_models/client_inbox/rendering/inbox_list.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@ class InboxList < Arbre::Component
66
include Rails.application.routes.url_helpers
77

88
def self.build(view_context, client_id)
9-
messages = inbox_messages(client_id)
10-
if messages.empty?
11-
messages << OpenStruct.new(
12-
id: SecureRandom.uuid,
13-
title: "Welcome to our platform!",
14-
created_at: 2.days.ago,
15-
read: false
16-
)
17-
end
18-
new(Arbre::Context.new(nil, view_context)).build(messages)
9+
new(Arbre::Context.new(nil, view_context)).build(inbox_messages(client_id))
1910
end
2011

2112
def build(messages, attributes = {})

rails_application/test/integration/client_inbox_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_customer_sees_inbox_messages
99
assert_response :success
1010
assert_select "h1", "Your Inbox"
1111

12-
assert_message("Welcome to our platform!", /\d+ days? ago/)
12+
assert_message("Welcome to our platform!", /minute ago/)
1313
end
1414

1515
private

0 commit comments

Comments
 (0)