forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_test.go
51 lines (44 loc) · 1.11 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
package intercom
import (
"errors"
"testing"
"time"
)
func TestEventSaveFail(t *testing.T) {
eventService := EventService{Repository: TestEventAPI{t: t, body: failBody}}
err := eventService.Save(&Event{})
if err.Error() != "Missing Identifier" {
t.Errorf("Error not propagated")
}
}
func failBody(t *testing.T, event Event) error {
return errors.New("Missing Identifier")
}
func TestEventSave(t *testing.T) {
eventService := EventService{Repository: TestEventAPI{t: t, body: successBody}}
event := Event{}
event.UserID = "27"
event.EventName = "govent"
event.CreatedAt = int64(time.Now().Unix())
event.Metadata = map[string]interface{}{"is_cool": true}
eventService.Save(&event)
}
func successBody(t *testing.T, event Event) error {
if event.UserID != "27" {
t.Errorf("UserID not set")
}
if event.EventName != "govent" {
t.Errorf("EventName not set")
}
if event.Metadata["is_cool"] != true {
t.Errorf("Metadata not set")
}
return nil
}
type TestEventAPI struct {
t *testing.T
body func(*testing.T, Event) error
}
func (t TestEventAPI) save(event *Event) error {
return t.body(t.t, *event)
}