This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mixpanel_test.go
47 lines (38 loc) · 1.69 KB
/
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
package mixpanel
import "testing"
func TestRedirectURL(t *testing.T) {
mp := NewMixpanel("abc")
props := Properties{
"a": "apples",
"b": "bananas",
"c": "cherries",
}
actualURI, err := mp.RedirectURL("12345", "Clicked through", "http://example.com", props)
if err != nil {
t.Fatal(err)
}
// data decodes to:
// "{\"event\":\"Clicked through\",\"properties\":{\"$distinct_id\":\"12345\",\"$token\":\"abc\",\"a\":\"apples\",\"b\":\"bananas\",\"c\":\"cherries\",\"mp_lib\":\"timehop/go-mixpanel\"}}"
expectedURI := `http://api.mixpanel.com/track?data=eyJldmVudCI6IkNsaWNrZWQgdGhyb3VnaCIsInByb3BlcnRpZXMiOnsiJGRpc3RpbmN0X2lkIjoiMTIzNDUiLCIkdG9rZW4iOiJhYmMiLCJhIjoiYXBwbGVzIiwiYiI6ImJhbmFuYXMiLCJjIjoiY2hlcnJpZXMiLCJtcF9saWIiOiJ0aW1laG9wL2dvLW1peHBhbmVsIn19&redirect=http%3A%2F%2Fexample.com`
if actualURI != expectedURI {
t.Errorf("\n got: %s\nwant: %s\n", actualURI, expectedURI)
}
}
func TestTrackingPixel(t *testing.T) {
mp := NewMixpanel("abc")
props := Properties{
"a": "apples",
"b": "bananas",
"c": "cherries",
}
actualURI, err := mp.TrackingPixel("12345", "Clicked through", props)
if err != nil {
t.Fatal(err)
}
// data decodes to:
// "{\"event\":\"Clicked through\",\"properties\":{\"$distinct_id\":\"12345\",\"$token\":\"abc\",\"a\":\"apples\",\"b\":\"bananas\",\"c\":\"cherries\",\"mp_lib\":\"timehop/go-mixpanel\"}}"
expectedURI := "http://api.mixpanel.com/track?data=eyJldmVudCI6IkNsaWNrZWQgdGhyb3VnaCIsInByb3BlcnRpZXMiOnsiJGRpc3RpbmN0X2lkIjoiMTIzNDUiLCIkdG9rZW4iOiJhYmMiLCJhIjoiYXBwbGVzIiwiYiI6ImJhbmFuYXMiLCJjIjoiY2hlcnJpZXMiLCJtcF9saWIiOiJ0aW1laG9wL2dvLW1peHBhbmVsIn19&img=1"
if actualURI != expectedURI {
t.Errorf("\n got: %s\nwant: %s\n", actualURI, expectedURI)
}
}