@@ -55,7 +55,7 @@ func Test_ListDiscussions(t *testing.T) {
5555 } `graphql:"category"`
5656 URL githubv4.String `graphql:"url"`
5757 }
58- } `graphql:"discussions(categoryId: $categoryId, orderBy: {field: $sort, direction: $direction}, first: $first, after: $after)"`
58+ } `graphql:"discussions(categoryId: $categoryId, orderBy: {field: $sort, direction: $direction}, first: $first, after: $after, last: $last, before: $before )"`
5959 } `graphql:"repository(owner: $owner, name: $repo)"`
6060 }
6161
@@ -66,7 +66,9 @@ func Test_ListDiscussions(t *testing.T) {
6666 "sort" : githubv4 .DiscussionOrderField ("" ),
6767 "direction" : githubv4 .OrderDirection ("" ),
6868 "first" : githubv4 .Int (0 ),
69+ "last" : githubv4 .Int (0 ),
6970 "after" : githubv4 .String ("" ),
71+ "before" : githubv4 .String ("" ),
7072 }
7173
7274 varsListInvalid := map [string ]interface {}{
@@ -76,7 +78,9 @@ func Test_ListDiscussions(t *testing.T) {
7678 "sort" : githubv4 .DiscussionOrderField ("" ),
7779 "direction" : githubv4 .OrderDirection ("" ),
7880 "first" : githubv4 .Int (0 ),
81+ "last" : githubv4 .Int (0 ),
7982 "after" : githubv4 .String ("" ),
83+ "before" : githubv4 .String ("" ),
8084 }
8185
8286 varsListWithCategory := map [string ]interface {}{
@@ -86,7 +90,9 @@ func Test_ListDiscussions(t *testing.T) {
8690 "sort" : githubv4 .DiscussionOrderField ("" ),
8791 "direction" : githubv4 .OrderDirection ("" ),
8892 "first" : githubv4 .Int (0 ),
93+ "last" : githubv4 .Int (0 ),
8994 "after" : githubv4 .String ("" ),
95+ "before" : githubv4 .String ("" ),
9096 }
9197
9298 tests := []struct {
@@ -144,6 +150,58 @@ func Test_ListDiscussions(t *testing.T) {
144150 expectError : false ,
145151 expectedIds : []int64 {2 , 3 },
146152 },
153+ {
154+ name : "both first and last parameters provided" ,
155+ vars : varsListAll , // vars don't matter since error occurs before GraphQL call
156+ reqParams : map [string ]interface {}{
157+ "owner" : "owner" ,
158+ "repo" : "repo" ,
159+ "first" : int32 (10 ),
160+ "last" : int32 (5 ),
161+ },
162+ response : mockResponseListAll , // response doesn't matter since error occurs before GraphQL call
163+ expectError : true ,
164+ errContains : "only one of 'first' or 'last' may be specified" ,
165+ },
166+ {
167+ name : "after with last parameters provided" ,
168+ vars : varsListAll , // vars don't matter since error occurs before GraphQL call
169+ reqParams : map [string ]interface {}{
170+ "owner" : "owner" ,
171+ "repo" : "repo" ,
172+ "after" : "cursor123" ,
173+ "last" : int32 (5 ),
174+ },
175+ response : mockResponseListAll , // response doesn't matter since error occurs before GraphQL call
176+ expectError : true ,
177+ errContains : "'after' cannot be used with 'last'. Did you mean to use 'before' instead?" ,
178+ },
179+ {
180+ name : "before with first parameters provided" ,
181+ vars : varsListAll , // vars don't matter since error occurs before GraphQL call
182+ reqParams : map [string ]interface {}{
183+ "owner" : "owner" ,
184+ "repo" : "repo" ,
185+ "before" : "cursor456" ,
186+ "first" : int32 (10 ),
187+ },
188+ response : mockResponseListAll , // response doesn't matter since error occurs before GraphQL call
189+ expectError : true ,
190+ errContains : "'before' cannot be used with 'first'. Did you mean to use 'after' instead?" ,
191+ },
192+ {
193+ name : "both after and before parameters provided" ,
194+ vars : varsListAll , // vars don't matter since error occurs before GraphQL call
195+ reqParams : map [string ]interface {}{
196+ "owner" : "owner" ,
197+ "repo" : "repo" ,
198+ "after" : "cursor123" ,
199+ "before" : "cursor456" ,
200+ },
201+ response : mockResponseListAll , // response doesn't matter since error occurs before GraphQL call
202+ expectError : true ,
203+ errContains : "only one of 'after' or 'before' may be specified" ,
204+ },
147205 }
148206
149207 for _ , tc := range tests {
0 commit comments