forked from intercom/intercom-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_api_test.go
43 lines (37 loc) · 1.11 KB
/
event_api_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
package intercom
import (
"testing"
"time"
"gopkg.in/intercom/intercom-go.v2/interfaces"
)
func TestEventAPISave(t *testing.T) {
http := TestEventHTTPClient{t: t, expectedURI: "/events"}
api := EventAPI{httpClient: &http}
event := Event{UserID: "27", CreatedAt: int64(time.Now().Unix()), EventName: "govent"}
api.save(&event)
}
func TestEventAPISaveFail(t *testing.T) {
http := TestEventHTTPClient{t: t, expectedURI: "/events", shouldFail: true}
api := EventAPI{httpClient: &http}
event := Event{UserID: "444", CreatedAt: int64(time.Now().Unix()), EventName: "govent"}
err := api.save(&event)
if herr, ok := err.(interfaces.HTTPError); ok && herr.Code != "not_found" {
t.Errorf("Error not returned")
}
}
type TestEventHTTPClient struct {
TestHTTPClient
t *testing.T
expectedURI string
shouldFail bool
}
func (t TestEventHTTPClient) Post(uri string, event interface{}) ([]byte, error) {
if uri != "/events" {
t.t.Errorf("Wrong endpoint called")
}
if t.shouldFail {
err := interfaces.HTTPError{StatusCode: 404, Code: "not_found", Message: "User Not Found"}
return nil, err
}
return nil, nil
}