-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathsegments_test.go
More file actions
68 lines (59 loc) · 2.54 KB
/
Copy pathsegments_test.go
File metadata and controls
68 lines (59 loc) · 2.54 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package customerio_test
import (
"context"
"testing"
"github.com/customerio/go-customerio/v3"
)
var (
idsByID = []string{"1", "2", "3"}
idsByEmail = []string{"alice@example.com", "bob@example.com"}
idsByCioID = []string{"cio_abc123", "cio_def456"}
)
func TestAddPeopleToSegment(t *testing.T) {
client, rec := trackServer(t)
ctx := context.Background()
checkParamError(t, client.AddPeopleToSegment(ctx, 0, idsByID), "segmentID")
checkParamError(t, client.AddPeopleToSegment(ctx, -1, idsByID), "segmentID")
checkParamError(t, client.AddPeopleToSegment(ctx, 7, nil), "ids")
checkParamError(t, client.AddPeopleToSegment(ctx, 7, []string{}), "ids")
runCases(t, rec,
[]testCase{
{"default", "POST", "/api/v1/segments/7/add_customers", map[string]any{"ids": idsByID}},
{"email", "POST", "/api/v1/segments/7/add_customers?id_type=email", map[string]any{"ids": idsByEmail}},
{"cio_id", "POST", "/api/v1/segments/7/add_customers?id_type=cio_id", map[string]any{"ids": idsByCioID}},
},
func(c testCase) error {
switch c.id {
case "email":
return client.AddPeopleToSegment(ctx, 7, idsByEmail, customerio.WithSegmentIDType(customerio.IdentifierTypeEmail))
case "cio_id":
return client.AddPeopleToSegment(ctx, 7, idsByCioID, customerio.WithSegmentIDType(customerio.IdentifierTypeCioID))
default:
return client.AddPeopleToSegment(ctx, 7, idsByID)
}
})
}
func TestRemovePeopleFromSegment(t *testing.T) {
client, rec := trackServer(t)
ctx := context.Background()
checkParamError(t, client.RemovePeopleFromSegment(ctx, 0, idsByID), "segmentID")
checkParamError(t, client.RemovePeopleFromSegment(ctx, -1, idsByID), "segmentID")
checkParamError(t, client.RemovePeopleFromSegment(ctx, 7, nil), "ids")
checkParamError(t, client.RemovePeopleFromSegment(ctx, 7, []string{}), "ids")
runCases(t, rec,
[]testCase{
{"default", "POST", "/api/v1/segments/7/remove_customers", map[string]any{"ids": idsByID}},
{"email", "POST", "/api/v1/segments/7/remove_customers?id_type=email", map[string]any{"ids": idsByEmail}},
{"cio_id", "POST", "/api/v1/segments/7/remove_customers?id_type=cio_id", map[string]any{"ids": idsByCioID}},
},
func(c testCase) error {
switch c.id {
case "email":
return client.RemovePeopleFromSegment(ctx, 7, idsByEmail, customerio.WithSegmentIDType(customerio.IdentifierTypeEmail))
case "cio_id":
return client.RemovePeopleFromSegment(ctx, 7, idsByCioID, customerio.WithSegmentIDType(customerio.IdentifierTypeCioID))
default:
return client.RemovePeopleFromSegment(ctx, 7, idsByID)
}
})
}