-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixpanel_test.go
53 lines (42 loc) · 996 Bytes
/
mixpanel_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
package mixpanel
import (
"net/http"
"testing"
"time"
)
type mockHTTPHandler struct {
apiURL string
}
func (mock *mockHTTPHandler) SendRequest(method string, endpoint string, data Props) (*http.Response, error) {
return nil, &http.Response{
Body: "Success",
Status: 200,
}
}
func TestCustomHTTPClient(t *testing.T) {
mixpanel := NewMixpanel("token_here", &mockHTTPHandler{
apiURL: "http://example.com",
})
got, err := mixpanel.Track("event", "123", map[string]interface{}{"time": time.Now()})
want := &http.Response{
Body: "Success",
Status: 200,
}
if err != nil {
t.Fatal(err)
}
if got != want {
t.Errorf("\n got: %s\nwant: %s\n", got, want)
}
}
func TestEncodeData(t *testing.T) {
props := map[string]interface{}{"prop1": "value1", "props2": "value2"}
got, err := EncodeData(props)
want := "eyJwcm9wMSI6InZhbHVlMSIsInByb3BzMiI6InZhbHVlMiJ9"
if err != nil {
t.Fatal(err)
}
if got != want {
t.Errorf("\n got: %s\nwant: %s\n", got, want)
}
}