-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent_test.go
58 lines (48 loc) · 1.22 KB
/
event_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
package theta_test
import (
"context"
"fmt"
"time"
"github.com/phogolabs/theta"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/phogolabs/theta/fake"
)
var _ = Describe("CompositeEventHandler", func() {
var (
reactor *theta.CompositeEventHandler
event *theta.EventArgs
handler *FakeEventHandler
)
BeforeEach(func() {
event = &theta.EventArgs{
Event: &theta.Event{
ID: "event-001",
Source: "twilio",
Sender: "members-api",
Name: "member_created",
Timestamp: time.Now(),
},
Meta: theta.Metadata{},
Body: []byte("{}"),
}
handler = &FakeEventHandler{}
reactor = &theta.CompositeEventHandler{
handler,
}
})
It("reacts on event successfully", func() {
Expect(reactor.HandleContext(context.TODO(), event)).To(Succeed())
Expect(handler.HandleContextCallCount()).To(Equal(1))
_, args := handler.HandleContextArgsForCall(0)
Expect(args.Event.ID).To(Equal(event.Event.ID))
})
Context("when the event handler fails", func() {
BeforeEach(func() {
handler.HandleContextReturns(fmt.Errorf("oh no"))
})
It("returns an error", func() {
Expect(reactor.HandleContext(context.TODO(), event)).To(MatchError("oh no"))
})
})
})