-
Notifications
You must be signed in to change notification settings - Fork 0
/
parameters_test.go
167 lines (152 loc) · 5.82 KB
/
parameters_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package matomo
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAllEncoding(t *testing.T) {
Setup()
// start with just the recommended parameters
params := Parameters{
RecommendedParameters: &RecommendedParameters{
Rand: Int64Ptr(rand.Int63n(9999999999999999)),
},
}
encoded := params.encode()
assert.NotNil(t, encoded)
assert.NotNil(t, encoded["rand"])
assert.NotZero(t, encoded["rand"])
assert.Equal(t, "1", encoded["apiv"])
assert.Equal(t, "0", encoded["send_image"])
// make sure a few other params don't exist
assert.Equal(t, 3, len(encoded)) // increment as other auto-populated fields are added
assert.Empty(t, encoded["_rck"])
encoded = testAllParams.encode()
assert.Equal(t, len(encoded), len(encoded)) // this will increase as more fields are supported
fmt.Println(encoded)
}
func TestUserParameterEncoding(t *testing.T) {
Setup()
emptyUserParams := &UserParameters{}
encoded := emptyUserParams.encode()
// the times should be set to the current server time automatically
assert.Equal(t, 3, len(encoded))
// populate all the fields and encode
encoded = testUserParams.encode()
assert.Equal(t, len(encoded), len(encoded))
assert.Equal(t, fmt.Sprintf("%d", *testUserParams.IDTS), encoded["_idts"])
assert.Equal(t, fmt.Sprintf("%d", *testUserParams.ViewTS), encoded["_viewts"])
assert.Equal(t, "1", encoded["_idvc"])
assert.Equal(t, "Keyword Test", encoded["_rck"])
assert.Equal(t, "Testing", encoded["_rcn"])
assert.Equal(t, encoded["ua"], encoded["ua"])
assert.Equal(t, "0", encoded["ag"])
assert.Equal(t, "1", encoded["cookie"])
assert.Equal(t, "0", encoded["dir"])
assert.Equal(t, "0", encoded["fla"])
assert.Equal(t, "0", encoded["gears"])
assert.Equal(t, "0", encoded["java"])
assert.Equal(t, "en-US", encoded["lang"])
assert.Equal(t, "1", encoded["new_visit"])
assert.Equal(t, "1", encoded["pdf"])
assert.Equal(t, "0", encoded["qt"])
assert.Equal(t, "0", encoded["realp"])
assert.Equal(t, "1x1", encoded["res"])
assert.Equal(t, "test-user", encoded["uid"])
assert.Equal(t, "/users", encoded["urlref"])
assert.Equal(t, "0", encoded["wma"])
}
func TestEventParameterEncodings(t *testing.T) {
Setup()
emptyEventParams := &EventTrackingParameters{}
encoded := emptyEventParams.encode()
assert.Equal(t, 0, len(encoded))
// populate all the fields and encode
encoded = testEventParams.encode()
assert.Equal(t, *testEventParams.Category, encoded["e_c"])
assert.Equal(t, *testEventParams.Action, encoded["e_a"])
assert.Equal(t, *testEventParams.Name, encoded["e_n"])
assert.Equal(t, fmt.Sprintf("%v", *testEventParams.Value), encoded["e_v"])
}
func TestActionParametersEncodings(t *testing.T) {
Setup()
emptyActionParams := &ActionParameters{}
encoded := emptyActionParams.encode()
assert.Equal(t, 0, len(encoded))
// populate all the fields and encode
encoded = testActionParams.encode()
assert.Equal(t, *testActionParams.ActionName, encoded["action_name"])
assert.Equal(t, *testActionParams.Url, encoded["url"])
assert.Equal(t, *testActionParams.Download, encoded["download"])
assert.Equal(t, *testActionParams.Link, encoded["link"])
}
func TestContentParameterEncodings(t *testing.T) {
Setup()
emptyContentParams := &ContentTrackingParameters{}
encoded := emptyContentParams.encode()
assert.Equal(t, 0, len(encoded))
// populate all the fields and encode
encoded = testContentParams.encode()
assert.Equal(t, *testContentParams.Target, encoded["c_t"])
assert.Equal(t, *testContentParams.Piece, encoded["c_p"])
assert.Equal(t, *testContentParams.Name, encoded["c_n"])
assert.Equal(t, *testContentParams.Interaction, encoded["c_i"])
}
var testAllParams = Parameters{
RecommendedParameters: &RecommendedParameters{},
UserParameters: testUserParams,
ActionParameters: testActionParams,
PagePerformanceParameters: &PagePerformanceParameters{},
EventTrackingParameters: &EventTrackingParameters{},
ContentTrackingParameters: testContentParams,
EcommerceParameters: &EcommerceParameters{},
OtherParameters: &OtherParameters{},
}
var testActionParams = &ActionParameters{
ActionName: StringPtr("Welcome to Sussy Baka Among Us"),
Url: StringPtr("https://wiki.helluvaos.com/"),
Download: StringPtr("https://laboratory.luvvvvuratory.raphielscape.com/download.zip"),
Link: StringPtr("https://wiki.helluvaos.com/"),
}
var testUserParams = &UserParameters{
URLRef: StringPtr("/users"),
CVar: StringPtr("{\"id\": 1}"),
IDVC: Int64Ptr(1),
ViewTS: Int64Ptr(time.Now().Add(-1 * time.Minute).Unix()),
IDTS: Int64Ptr(time.Now().Add(-10 * time.Minute).Unix()),
CampaignName: StringPtr("Testing"),
CampaignKeyword: StringPtr("Keyword Test"),
Resolution: StringPtr("1x1"),
CurrentHour: new(string),
CurrentMinute: new(string),
CurrentSecond: new(string),
UserPlugins: &UserPlugins{
Flash: BoolPtr(false),
Java: BoolPtr(false),
Director: BoolPtr(false),
Quicktime: BoolPtr(false),
RealPlayer: BoolPtr(false),
PDF: BoolPtr(true),
WMA: BoolPtr(false),
Gears: BoolPtr(false),
Silverlight: BoolPtr(false)},
CookiesSupported: BoolPtr(true),
UserAgent: StringPtr("Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0"),
Lang: StringPtr("en-US"),
UserID: StringPtr("test-user"),
NewVisit: BoolPtr(true),
}
var testEventParams = &EventTrackingParameters{
Category: StringPtr("Event Category"),
Action: StringPtr("Event Action"),
Name: StringPtr("Event Name"),
Value: Float64Ptr(42.42),
}
var testContentParams = &ContentTrackingParameters{
Name: StringPtr("Content Name"),
Piece: StringPtr("download.zip"),
Target: StringPtr("https://laboratory.luvvvvuratory.raphielscape.com/download.zip"),
Interaction: StringPtr("Event"),
}