File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ module Stores
2+ class ProductRegistration
3+ def initialize ( event_store )
4+ @event_store = event_store
5+ end
6+
7+ def call ( cmd )
8+ @event_store . publish ( product_registered_event ( cmd ) , stream_name : stream_name ( cmd ) )
9+ end
10+
11+ private
12+
13+ def product_registered_event ( cmd )
14+ ProductRegistered . new (
15+ data : {
16+ store_id : cmd . store_id ,
17+ product_id : cmd . product_id ,
18+ }
19+ )
20+ end
21+
22+ def stream_name ( cmd )
23+ "Stores::Store$#{ cmd . store_id } "
24+ end
25+ end
26+ end
Original file line number Diff line number Diff line change 1+ require_relative 'test_helper'
2+ module Stores
3+ class ProductRegistrationTest < Test
4+ cover "Stores*"
5+
6+ def test_product_should_get_registered
7+ store_id = SecureRandom . uuid
8+ product_id = SecureRandom . uuid
9+ assert register_product ( store_id , product_id )
10+ end
11+
12+ def test_should_publish_event
13+ store_id = SecureRandom . uuid
14+ product_id = SecureRandom . uuid
15+ product_registered = Stores ::ProductRegistered . new ( data : { store_id : store_id , product_id : product_id } )
16+ assert_events ( "Stores::Store$#{ store_id } " , product_registered ) do
17+ register_product ( store_id , product_id )
18+ end
19+ end
20+
21+ private
22+
23+ def register_product ( store_id , product_id )
24+ run_command ( RegisterProduct . new ( store_id : store_id , product_id : product_id ) )
25+ end
26+ end
27+ end
You can’t perform that action at this time.
0 commit comments