-
Notifications
You must be signed in to change notification settings - Fork 1
/
avoNetworkCallsHandler_test.go
100 lines (88 loc) · 2.61 KB
/
avoNetworkCallsHandler_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
package avoinspector
import (
"reflect"
"testing"
)
func TestAvoNetworkCallsHandler_bodyForSessionStartedCall(t *testing.T) {
// Create an instance of AvoNetworkCallsHandler
handler := &AvoNetworkCallsHandler{
apiKey: "test-api-key",
envName: "test",
appName: "test-app",
appVersion: "1.0.0",
libVersion: "1.0.0",
samplingRate: 1.0,
shouldLog: false,
}
// Mock newGuid function
newGuid = func() string {
return "test-message-id"
}
// Call the method being tested
sessionStartedBody := handler.bodyForSessionStartedCall("test-session-id")
// Verify the result
expectedSessionStartedBody := SessionStartedBody{
BaseBody: BaseBody{
ApiKey: "test-api-key",
AppName: "test-app",
AppVersion: "1.0.0",
LibVersion: "1.0.0",
Env: "test",
LibPlatform: "go",
MessageId: "test-message-id",
TrackingId: "",
CreatedAt: sessionStartedBody.CreatedAt,
SessionId: "test-session-id",
SamplingRate: 1.0,
},
Type: "sessionStarted",
}
if !reflect.DeepEqual(sessionStartedBody, expectedSessionStartedBody) {
t.Errorf("unexpected sessionStartedBody, got: %+v, want: %+v", sessionStartedBody, expectedSessionStartedBody)
}
}
func TestAvoNetworkCallsHandler_bodyForEventSchemaCall(t *testing.T) {
// Create an instance of AvoNetworkCallsHandler
handler := &AvoNetworkCallsHandler{
apiKey: "test-api-key",
envName: "test",
appName: "test-app",
appVersion: "1.0.0",
libVersion: "1.0.0",
samplingRate: 1.0,
shouldLog: false,
}
// Mock newGuid function
newGuid = func() string {
return "test-message-id"
}
// Prepare test event properties
eventProperties := []Property{
{PropertyName: "property1", PropertyType: "value1"},
{PropertyName: "property2", PropertyType: "value2"},
}
// Call the method being tested
eventSchemaBody := handler.bodyForEventSchemaCall("test-session-id", "test-event", eventProperties)
// Verify the result
expectedEventSchemaBody := EventSchemaBody{
BaseBody: BaseBody{
ApiKey: "test-api-key",
AppName: "test-app",
AppVersion: "1.0.0",
LibVersion: "1.0.0",
Env: "test",
LibPlatform: "go",
MessageId: "test-message-id",
TrackingId: "",
CreatedAt: eventSchemaBody.CreatedAt,
SessionId: "test-session-id",
SamplingRate: 1.0,
},
Type: "event",
EventName: "test-event",
EventProperties: eventProperties,
}
if !reflect.DeepEqual(eventSchemaBody, expectedEventSchemaBody) {
t.Errorf("unexpected eventSchemaBody, got: %+v, want: %+v", eventSchemaBody, expectedEventSchemaBody)
}
}