-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.dispatch.command_test.go
134 lines (116 loc) · 3.19 KB
/
action.dispatch.command_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package testkit_test
import (
"time"
"github.com/dogmatiq/configkit"
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/engine"
"github.com/dogmatiq/testkit/envelope"
"github.com/dogmatiq/testkit/fact"
"github.com/dogmatiq/testkit/internal/testingmock"
g "github.com/onsi/ginkgo/v2"
gm "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)
var _ = g.Describe("func ExecuteCommand()", func() {
var (
app *ApplicationStub
t *testingmock.T
startTime time.Time
buf *fact.Buffer
test *Test
)
g.BeforeEach(func() {
app = &ApplicationStub{
ConfigureFunc: func(c dogma.ApplicationConfigurer) {
c.Identity("<app>", "a84b2620-4675-4024-b55b-cd5dbeb6e293")
c.RegisterIntegration(&IntegrationMessageHandlerStub{
ConfigureFunc: func(c dogma.IntegrationConfigurer) {
c.Identity("<integration>", "d1cf3af1-6c20-4125-8e68-192a6075d0b4")
c.Routes(
dogma.HandlesCommand[CommandStub[TypeA]](),
dogma.RecordsEvent[EventStub[TypeA]](),
)
},
})
},
}
t = &testingmock.T{}
startTime = time.Now()
buf = &fact.Buffer{}
test = Begin(
t,
app,
StartTimeAt(startTime),
WithUnsafeOperationOptions(
engine.WithObserver(buf),
),
)
})
g.It("dispatches the message", func() {
test.Prepare(
ExecuteCommand(CommandA1),
)
gm.Expect(buf.Facts()).To(gm.ContainElement(
fact.DispatchCycleBegun{
Envelope: &envelope.Envelope{
MessageID: "1",
CausationID: "1",
CorrelationID: "1",
Message: CommandA1,
CreatedAt: startTime,
},
EngineTime: startTime,
EnabledHandlerTypes: map[configkit.HandlerType]bool{
configkit.AggregateHandlerType: true,
configkit.IntegrationHandlerType: false,
configkit.ProcessHandlerType: true,
configkit.ProjectionHandlerType: false,
},
EnabledHandlers: map[string]bool{},
},
))
})
g.It("fails the test if the message type is unrecognized", func() {
t.FailSilently = true
test.Prepare(
ExecuteCommand(CommandX1),
)
gm.Expect(t.Failed()).To(gm.BeTrue())
gm.Expect(t.Logs).To(gm.ContainElement(
"cannot execute command, stubs.CommandStub[TypeX] is a not a recognized message type",
))
})
g.It("does not satisfy its own expectations", func() {
t.FailSilently = true
test.Expect(
ExecuteCommand(CommandA1),
ToExecuteCommand(CommandA1),
)
gm.Expect(t.Failed()).To(gm.BeTrue())
})
g.It("produces the expected caption", func() {
test.Prepare(
ExecuteCommand(CommandA1),
)
gm.Expect(t.Logs).To(gm.ContainElement(
"--- executing stubs.CommandStub[TypeA] command ---",
))
})
g.It("panics if the message is nil", func() {
gm.Expect(func() {
ExecuteCommand(nil)
}).To(gm.PanicWith("ExecuteCommand(<nil>): message must not be nil"))
})
g.It("captures the location that the action was created", func() {
act := executeCommand(CommandA1)
gm.Expect(act.Location()).To(MatchAllFields(
Fields{
"Func": gm.Equal("github.com/dogmatiq/testkit_test.executeCommand"),
"File": gm.HaveSuffix("/action.linenumber_test.go"),
"Line": gm.Equal(52),
},
))
})
})