-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtracker_test.go
More file actions
48 lines (40 loc) · 1.64 KB
/
tracker_test.go
File metadata and controls
48 lines (40 loc) · 1.64 KB
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
package appsflyer
import (
"encoding/json"
"testing"
"time"
)
const (
advertisingID = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"
appsFlyerID = "1111111111111-1111111"
iosEventJSON = `{"appsflyer_id":"1111111111111-1111111","ip":"1.2.3.4","eventName":"af_start_trial","eventTime":"2019-02-15 06:30:36.869","eventValue":"{\"af_currency\":\"USD\",\"af_revenue\":\"59.99\",\"expiry\":\"2014/11/11\"}","idfa":"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA","af_events_api":"true"}`
androidEventJSON = `{"advertising_id":"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA","appsflyer_id":"1111111111111-1111111","eventName":"af_start_trial","eventValue":"","af_events_api":"true"}`
)
var validDate = time.Date(2014, time.November, 11, 19, 0, 0, 0, time.Local)
var validTime = time.Date(2019, time.February, 15, 6, 30, 36, 869*1000000, time.UTC)
func TestEventWithOptionalParams(t *testing.T) {
evt := NewEvent(appsFlyerID, IOS).
SetName(StartTrial).
SetAdvertisingID(advertisingID).
SetDateValue("expiry", validDate).
SetDeviceIP("1.2.3.4").
SetEventTime(validTime).
SetRevenue(59.99, "USD")
if buf, err := json.Marshal(evt); err != nil {
t.Errorf("Should have read event. %s", err)
} else if string(buf) != iosEventJSON {
t.Error(string(buf))
t.Error("Should become valid JSON")
}
}
func TestEventWithoutOptionalParams(t *testing.T) {
evt := NewEvent(appsFlyerID, Android)
evt.SetName(StartTrial)
evt.SetAdvertisingID(advertisingID)
if buf, err := json.Marshal(evt); err != nil {
t.Errorf("Should have read event. %s", err)
} else if string(buf) != androidEventJSON {
t.Error("Should become valid JSON")
}
}
// TODO: Test using JSON configuration