Skip to content

Commit e3a7f9f

Browse files
committed
test fixes
1 parent ab684d3 commit e3a7f9f

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

capture_test.go

-12
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,3 @@ func TestCaptureValidWithDistinctId(t *testing.T) {
5252
t.Error("validating a valid capture object failed:", capture, err)
5353
}
5454
}
55-
56-
func TestGroupsCapture(t *testing.T) {
57-
// capture := Capture{
58-
// Event: "1",
59-
// DistinctId: "2",
60-
// Groups: Groups{}.Set("company", "id:5").Set("instance", "app.posthog.com"),
61-
// }
62-
63-
// if e, ok := capture.Validate()(FieldError); !ok {
64-
// t.Error("???", err)
65-
// }
66-
}

group_identify.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ func (msg GroupIdentify) internal() {
1919
}
2020

2121
func (msg GroupIdentify) Validate() error {
22-
if len(msg.DistinctId) == 0 {
22+
if len(msg.Type) == 0 {
2323
return FieldError{
2424
Type: "posthog.GroupIdentify",
25-
Name: "DistinctId",
26-
Value: msg.DistinctId,
25+
Name: "Type",
26+
Value: msg.Type,
27+
}
28+
}
29+
30+
if len(msg.Key) == 0 {
31+
return FieldError{
32+
Type: "posthog.GroupIdentify",
33+
Name: "Key",
34+
Value: msg.Key,
2735
}
2836
}
2937

group_identify_test.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package posthog
22

33
import "testing"
44

5-
func TestGroupIdentifyMissingDistinctId(t *testing.T) {
5+
func TestGroupIdentifyMissingType(t *testing.T) {
66
groupIdentify := GroupIdentify{}
77

88
if err := groupIdentify.Validate(); err == nil {
@@ -13,16 +13,34 @@ func TestGroupIdentifyMissingDistinctId(t *testing.T) {
1313

1414
} else if e != (FieldError{
1515
Type: "posthog.GroupIdentify",
16-
Name: "DistinctId",
16+
Name: "Type",
17+
Value: "",
18+
}) {
19+
t.Error("invalid error value returned when validating group identify:", err)
20+
}
21+
}
22+
func TestGroupIdentifyMissingKey(t *testing.T) {
23+
groupIdentify := GroupIdentify{}
24+
25+
if err := groupIdentify.Validate(); err == nil {
26+
t.Error("validating an invalid group identify object succeeded:", groupIdentify)
27+
28+
} else if e, ok := err.(FieldError); !ok {
29+
t.Error("invalid error type returned when validating group identify:", err)
30+
31+
} else if e != (FieldError{
32+
Type: "posthog.GroupIdentify",
33+
Name: "Key",
1734
Value: "",
1835
}) {
1936
t.Error("invalid error value returned when validating group identify:", err)
2037
}
2138
}
2239

23-
func TestGroupIdentifyValidWithDistinctId(t *testing.T) {
24-
groupIdentify := Identify{
25-
DistinctId: "organization_id:5",
40+
func TestGroupIdentifyValidWithTypeAndKey(t *testing.T) {
41+
groupIdentify := GroupIdentify{
42+
Type: "organization",
43+
Key: "id:5",
2644
}
2745

2846
if err := groupIdentify.Validate(); err != nil {

0 commit comments

Comments
 (0)