-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevent_test.go
61 lines (47 loc) · 1.45 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
59
60
61
package ess
import (
"testing"
"time"
)
func TestEvent_For_usesAggregateIdAsStreamId(t *testing.T) {
aggregate := newTestAggregate("id")
event := NewEvent("test.run").For(aggregate)
if got, want := event.StreamId, aggregate.Id(); got != want {
t.Errorf(`event.StreamId = %v; want %v`, got, want)
}
}
func TestEvent_Add_addsFieldToPayload(t *testing.T) {
event := NewEvent("test.run").
Add("a", 1).
Add("b", 2)
if got, want := event.Payload["a"].(int), 1; got != want {
t.Errorf(`event.Payload["a"].(int) = %v; want %v`, got, want)
}
if got, want := event.Payload["b"].(int), 2; got != want {
t.Errorf(`event.Payload["b"].(int) = %v; want %v`, got, want)
}
}
func TestEvent_Add_overwritesExistingValues(t *testing.T) {
event := NewEvent("test.run").
Add("a", 1).
Add("a", 2)
if got, want := event.Payload["a"], 2; got != want {
t.Errorf(`event.Payload["a"] = %v; want %v`, got, want)
}
}
func TestEvent_Occur_setsOccurredOnBasedOnClock(t *testing.T) {
clock := &StaticClock{time.Now()}
event := NewEvent("test.run").
Occur(clock)
if got, want := event.OccurredOn, clock.Time; !got.Equal(want) {
t.Errorf(`event.OccurredOn = %v; want %v`, got, want)
}
}
func TestEvent_Persist_setsPersistedAtBasedOnClock(t *testing.T) {
clock := &StaticClock{time.Now()}
event := NewEvent("test.run").
Persist(clock)
if got, want := event.PersistedAt, clock.Time; !got.Equal(want) {
t.Errorf(`event.PersistedAt = %v; want %v`, got, want)
}
}