flamingo.me/flamingo-commerce/v3@v3.11.0/checkout/domain/placeorder/states/success_test.go (about) 1 package states_test 2 3 import ( 4 "context" 5 "testing" 6 7 "flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/process" 8 "flamingo.me/flamingo-commerce/v3/checkout/domain/placeorder/states" 9 "flamingo.me/flamingo/v3/framework/flamingo" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 type ( 15 eventRouter struct { 16 validator func(flamingo.Event) 17 } 18 ) 19 20 func (e *eventRouter) Dispatch(_ context.Context, event flamingo.Event) { 21 e.validator(event) 22 } 23 24 func TestSuccess_IsFinal(t *testing.T) { 25 s := states.Success{} 26 assert.True(t, s.IsFinal()) 27 } 28 29 func TestSuccess_Name(t *testing.T) { 30 s := states.Success{} 31 assert.Equal(t, "Success", s.Name()) 32 } 33 34 func TestSuccess_Rollback(t *testing.T) { 35 s := states.Success{} 36 assert.Nil(t, s.Rollback(context.Background(), nil)) 37 } 38 39 func TestSuccess_Run(t *testing.T) { 40 p := &process.Process{} 41 s := new(states.Success).Inject(&eventRouter{ 42 validator: func(event flamingo.Event) { 43 require.IsType(t, &states.SuccessEvent{}, event) 44 assert.Equal(t, event.(*states.SuccessEvent).ProcessContext, p.Context()) 45 }, 46 }) 47 assert.Equal(t, s.Run(context.Background(), p), process.RunResult{}) 48 }