Skip to content

Commit 72dc8ff

Browse files
author
Jin Huang
committed
Add more test cases
1 parent 5646f5a commit 72dc8ff

File tree

2 files changed

+89
-7
lines changed

2 files changed

+89
-7
lines changed

zendesk/group_test.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
)
88

9-
func TestGetGroups(t *testing.T) {
9+
func TestGetGroupsIterator(t *testing.T) {
1010
mockAPI := newMockAPI(http.MethodGet, "groups.json")
1111
client := newTestClient(mockAPI)
1212
defer mockAPI.Close()
@@ -17,23 +17,23 @@ func TestGetGroups(t *testing.T) {
1717
it := client.GetGroupsIterator(ctx, ops)
1818

1919
expectedLength := 1
20+
groupsCount := 0
2021
for it.HasMore() {
2122
groups, err := it.GetNext()
2223
if len(groups) != expectedLength {
2324
t.Fatalf("expected length of groups is 1, but got %d", len(groups))
2425
}
25-
if err == nil {
26-
for _, group := range groups {
27-
println(group.Name)
28-
}
29-
}
26+
groupsCount += len(groups)
3027
if err != nil {
3128
t.Fatalf("Failed to get groups: %s", err)
3229
}
3330
}
31+
if groupsCount != 1 {
32+
t.Fatalf("expected length of groups is 1, but got %d", groupsCount)
33+
}
3434
}
3535

36-
func TestGetGroupsIterator(t *testing.T) {
36+
func TestGetGroups(t *testing.T) {
3737
mockAPI := newMockAPI(http.MethodGet, "groups.json")
3838
client := newTestClient(mockAPI)
3939
defer mockAPI.Close()
@@ -48,6 +48,36 @@ func TestGetGroupsIterator(t *testing.T) {
4848
}
4949
}
5050

51+
func TestGetGroupsOBP(t *testing.T) {
52+
mockAPI := newMockAPI(http.MethodGet, "groups.json")
53+
client := newTestClient(mockAPI)
54+
defer mockAPI.Close()
55+
56+
groups, _, err := client.GetGroupsOBP(ctx, nil)
57+
if err != nil {
58+
t.Fatalf("Failed to get groups: %s", err)
59+
}
60+
61+
if len(groups) != 1 {
62+
t.Fatalf("expected length of groups is 1, but got %d", len(groups))
63+
}
64+
}
65+
66+
func TestGetGroupsCBP(t *testing.T) {
67+
mockAPI := newMockAPI(http.MethodGet, "groups.json")
68+
client := newTestClient(mockAPI)
69+
defer mockAPI.Close()
70+
71+
groups, _, err := client.GetGroupsCBP(ctx, nil)
72+
if err != nil {
73+
t.Fatalf("Failed to get groups: %s", err)
74+
}
75+
76+
if len(groups) != 1 {
77+
t.Fatalf("expected length of groups is 1, but got %d", len(groups))
78+
}
79+
}
80+
5181
func TestCreateGroup(t *testing.T) {
5282
mockAPI := newMockAPIWithStatus(http.MethodPost, "groups.json", http.StatusCreated)
5383
client := newTestClient(mockAPI)

zendesk/ticket_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,58 @@ func TestGetOrganizationTickets(t *testing.T) {
127127
}
128128
}
129129

130+
func TestGetOrganizationTicketsOBP(t *testing.T) {
131+
mockAPI := newMockAPI(http.MethodGet, "tickets.json")
132+
client := newTestClient(mockAPI)
133+
defer mockAPI.Close()
134+
135+
tickets, _, err := client.GetOrganizationTicketsOBP(ctx, &OBPOptions{
136+
PageOptions: PageOptions{
137+
Page: 1,
138+
PerPage: 10,
139+
},
140+
CommonOptions: CommonOptions{
141+
SortBy: "created_at",
142+
SortOrder: "asc",
143+
Id: 360363695492,
144+
},
145+
})
146+
if err != nil {
147+
t.Fatalf("Failed to get tickets: %s", err)
148+
}
149+
150+
expectedLength := 2
151+
if len(tickets) != expectedLength {
152+
t.Fatalf("Returned tickets does not have the expected length %d. Tickets length is %d", expectedLength, len(tickets))
153+
}
154+
}
155+
156+
func TestGetOrganizationTicketsCBP(t *testing.T) {
157+
mockAPI := newMockAPI(http.MethodGet, "tickets.json")
158+
client := newTestClient(mockAPI)
159+
defer mockAPI.Close()
160+
161+
tickets, _, err := client.GetOrganizationTicketsCBP(ctx, &CBPOptions{
162+
CursorPagination: CursorPagination{
163+
PageSize: 10,
164+
PageAfter: "",
165+
},
166+
CommonOptions: CommonOptions{
167+
SortBy: "created_at",
168+
SortOrder: "asc",
169+
Id: 360363695492,
170+
},
171+
})
172+
if err != nil {
173+
t.Fatalf("Failed to get tickets: %s", err)
174+
}
175+
176+
expectedLength := 2
177+
if len(tickets) != expectedLength {
178+
t.Fatalf("Returned tickets does not have the expected length %d. Tickets length is %d", expectedLength, len(tickets))
179+
}
180+
}
181+
130182
func TestGetOrganizationTicketsIterator(t *testing.T) {
131183
mockAPI := newMockAPI(http.MethodGet, "tickets.json")
132184
client := newTestClient(mockAPI)

0 commit comments

Comments
 (0)