-
Notifications
You must be signed in to change notification settings - Fork 20
/
capture_test.go
54 lines (43 loc) · 1.23 KB
/
capture_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
package posthog
import "testing"
func TestCaptureMissingEvent(t *testing.T) {
capture := Capture{
DistinctId: "1",
}
if err := capture.Validate(); err == nil {
t.Error("validating an invalid capture object succeeded:", capture)
} else if e, ok := err.(FieldError); !ok {
t.Error("invalid error type returned when validating capture:", err)
} else if e != (FieldError{
Type: "posthog.Capture",
Name: "Event",
Value: "",
}) {
t.Error("invalid error value returned when validating capture:", err)
}
}
func TestCaptureMissingDistinctId(t *testing.T) {
capture := Capture{
Event: "1",
}
if err := capture.Validate(); err == nil {
t.Error("validating an invalid capture object succeeded:", capture)
} else if e, ok := err.(FieldError); !ok {
t.Error("invalid error type returned when validating capture:", err)
} else if e != (FieldError{
Type: "posthog.Capture",
Name: "DistinctId",
Value: "",
}) {
t.Error("invalid error value returned when validating capture:", err)
}
}
func TestCaptureValidWithDistinctId(t *testing.T) {
capture := Capture{
Event: "1",
DistinctId: "2",
}
if err := capture.Validate(); err != nil {
t.Error("validating a valid capture object failed:", capture, err)
}
}