|
6 | 6 | "io/ioutil" |
7 | 7 | "testing" |
8 | 8 |
|
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + |
9 | 11 | "github.com/cli/cli/internal/ghrepo" |
10 | 12 | "github.com/cli/cli/pkg/httpmock" |
11 | 13 | ) |
@@ -68,3 +70,76 @@ func TestIssueList(t *testing.T) { |
68 | 70 | t.Errorf("expected %q, got %q", "ENDCURSOR", endCursor) |
69 | 71 | } |
70 | 72 | } |
| 73 | + |
| 74 | +func TestIssueList_pagination(t *testing.T) { |
| 75 | + http := &httpmock.Registry{} |
| 76 | + client := NewClient(ReplaceTripper(http)) |
| 77 | + |
| 78 | + http.StubResponse(200, bytes.NewBufferString(` |
| 79 | + { "data": { "repository": { |
| 80 | + "hasIssuesEnabled": true, |
| 81 | + "issues": { |
| 82 | + "nodes": [ |
| 83 | + { |
| 84 | + "title": "issue1", |
| 85 | + "labels": { "nodes": [ { "name": "bug" } ], "totalCount": 1 }, |
| 86 | + "assignees": { "nodes": [ { "login": "user1" } ], "totalCount": 1 } |
| 87 | + } |
| 88 | + ], |
| 89 | + "pageInfo": { |
| 90 | + "hasNextPage": true, |
| 91 | + "endCursor": "ENDCURSOR" |
| 92 | + }, |
| 93 | + "totalCount": 2 |
| 94 | + } |
| 95 | + } } } |
| 96 | + `)) |
| 97 | + http.StubResponse(200, bytes.NewBufferString(` |
| 98 | + { "data": { "repository": { |
| 99 | + "hasIssuesEnabled": true, |
| 100 | + "issues": { |
| 101 | + "nodes": [ |
| 102 | + { |
| 103 | + "title": "issue2", |
| 104 | + "labels": { "nodes": [ { "name": "enhancement" } ], "totalCount": 1 }, |
| 105 | + "assignees": { "nodes": [ { "login": "user2" } ], "totalCount": 1 } |
| 106 | + } |
| 107 | + ], |
| 108 | + "pageInfo": { |
| 109 | + "hasNextPage": false, |
| 110 | + "endCursor": "ENDCURSOR" |
| 111 | + }, |
| 112 | + "totalCount": 2 |
| 113 | + } |
| 114 | + } } } |
| 115 | + `)) |
| 116 | + |
| 117 | + repo := ghrepo.New("OWNER", "REPO") |
| 118 | + res, err := IssueList(client, repo, "", nil, "", 0, "", "", "") |
| 119 | + if err != nil { |
| 120 | + t.Fatalf("IssueList() error = %v", err) |
| 121 | + } |
| 122 | + |
| 123 | + assert.Equal(t, 2, res.TotalCount) |
| 124 | + assert.Equal(t, 2, len(res.Issues)) |
| 125 | + |
| 126 | + getLabels := func(i Issue) []string { |
| 127 | + var labels []string |
| 128 | + for _, l := range i.Labels.Nodes { |
| 129 | + labels = append(labels, l.Name) |
| 130 | + } |
| 131 | + return labels |
| 132 | + } |
| 133 | + getAssignees := func(i Issue) []string { |
| 134 | + var logins []string |
| 135 | + for _, u := range i.Assignees.Nodes { |
| 136 | + logins = append(logins, u.Login) |
| 137 | + } |
| 138 | + return logins |
| 139 | + } |
| 140 | + |
| 141 | + assert.Equal(t, []string{"bug"}, getLabels(res.Issues[0])) |
| 142 | + assert.Equal(t, []string{"user1"}, getAssignees(res.Issues[0])) |
| 143 | + assert.Equal(t, []string{"enhancement"}, getLabels(res.Issues[1])) |
| 144 | + assert.Equal(t, []string{"user2"}, getAssignees(res.Issues[1])) |
| 145 | +} |
0 commit comments