@@ -155,47 +155,53 @@ func Test_ListDiscussions(t *testing.T) {
155155
156156 // Variables matching what GraphQL receives after JSON marshaling/unmarshaling
157157 varsListAll := map [string ]interface {}{
158- "owner" : githubv4 . String ( "owner" ) ,
159- "repo" : githubv4 . String ( "repo" ) ,
158+ "owner" : "owner" ,
159+ "repo" : "repo" ,
160160 "first" : float64 (30 ),
161161 "after" : (* string )(nil ),
162162 }
163163
164164 varsRepoNotFound := map [string ]interface {}{
165- "owner" : githubv4 . String ( "owner" ) ,
166- "repo" : githubv4 . String ( "nonexistent-repo" ) ,
165+ "owner" : "owner" ,
166+ "repo" : "nonexistent-repo" ,
167167 "first" : float64 (30 ),
168168 "after" : (* string )(nil ),
169169 }
170170
171171 varsDiscussionsFiltered := map [string ]interface {}{
172- "owner" : githubv4 . String ( "owner" ) ,
173- "repo" : githubv4 . String ( "repo" ) ,
174- "categoryId" : githubv4 . ID ( "DIC_kwDOABC123" ) ,
172+ "owner" : "owner" ,
173+ "repo" : "repo" ,
174+ "categoryId" : "DIC_kwDOABC123" ,
175175 "first" : float64 (30 ),
176176 "after" : (* string )(nil ),
177177 }
178178
179179 varsOrderByCreatedAsc := map [string ]interface {}{
180- "owner" : githubv4 .String ("owner" ),
181- "repo" : githubv4 .String ("repo" ),
182- "orderByField" : githubv4 .DiscussionOrderField ("CREATED_AT" ),
183- "orderByDirection" : githubv4 .OrderDirection ("ASC" ),
180+ "owner" : "owner" ,
181+ "repo" : "repo" ,
182+ "orderByField" : "CREATED_AT" ,
183+ "orderByDirection" : "ASC" ,
184+ "first" : float64 (30 ),
185+ "after" : (* string )(nil ),
184186 }
185187
186188 varsOrderByUpdatedDesc := map [string ]interface {}{
187- "owner" : githubv4 .String ("owner" ),
188- "repo" : githubv4 .String ("repo" ),
189- "orderByField" : githubv4 .DiscussionOrderField ("UPDATED_AT" ),
190- "orderByDirection" : githubv4 .OrderDirection ("DESC" ),
189+ "owner" : "owner" ,
190+ "repo" : "repo" ,
191+ "orderByField" : "UPDATED_AT" ,
192+ "orderByDirection" : "DESC" ,
193+ "first" : float64 (30 ),
194+ "after" : (* string )(nil ),
191195 }
192196
193197 varsCategoryWithOrder := map [string ]interface {}{
194- "owner" : githubv4 .String ("owner" ),
195- "repo" : githubv4 .String ("repo" ),
196- "categoryId" : githubv4 .ID ("DIC_kwDOABC123" ),
197- "orderByField" : githubv4 .DiscussionOrderField ("CREATED_AT" ),
198- "orderByDirection" : githubv4 .OrderDirection ("DESC" ),
198+ "owner" : "owner" ,
199+ "repo" : "repo" ,
200+ "categoryId" : "DIC_kwDOABC123" ,
201+ "orderByField" : "CREATED_AT" ,
202+ "orderByDirection" : "DESC" ,
203+ "first" : float64 (30 ),
204+ "after" : (* string )(nil ),
199205 }
200206
201207 tests := []struct {
@@ -310,41 +316,40 @@ func Test_ListDiscussions(t *testing.T) {
310316 },
311317 }
312318
319+ // Define the actual query strings that match the implementation
320+ qBasicNoOrder := "query($after:String$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
321+ qWithCategoryNoOrder := "query($after:String$categoryId:ID!$first:Int!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, categoryId: $categoryId){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
322+ qBasicWithOrder := "query($after:String$first:Int!$orderByDirection:OrderDirection!$orderByField:DiscussionOrderField!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, orderBy: { field: $orderByField, direction: $orderByDirection }){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
323+ qWithCategoryAndOrder := "query($after:String$categoryId:ID!$first:Int!$orderByDirection:OrderDirection!$orderByField:DiscussionOrderField!$owner:String!$repo:String!){repository(owner: $owner, name: $repo){discussions(first: $first, after: $after, categoryId: $categoryId, orderBy: { field: $orderByField, direction: $orderByDirection }){nodes{number,title,createdAt,updatedAt,author{login},category{name},url},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}"
324+
313325 for _ , tc := range tests {
314326 t .Run (tc .name , func (t * testing.T ) {
315327 var httpClient * http.Client
316328
317329 switch tc .name {
318330 case "list all discussions without category filter" :
319- // Simple case - BasicNoOrder query structure (i.e. no order, no category)
320- matcher := githubv4mock .NewQueryMatcher (& BasicNoOrder {}, varsListAll , mockResponseListAll )
331+ matcher := githubv4mock .NewQueryMatcher (qBasicNoOrder , varsListAll , mockResponseListAll )
321332 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
322333 case "filter by category ID" :
323- // WithCategoryNoOrder
324- matcher := githubv4mock .NewQueryMatcher (& WithCategoryNoOrder {}, varsDiscussionsFiltered , mockResponseListGeneral )
334+ matcher := githubv4mock .NewQueryMatcher (qWithCategoryNoOrder , varsDiscussionsFiltered , mockResponseListGeneral )
325335 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
326336 case "order by created at ascending" :
327- // BasicWithOrder - use ordered response
328- matcher := githubv4mock .NewQueryMatcher (& BasicWithOrder {}, varsOrderByCreatedAsc , mockResponseOrderedCreatedAsc )
337+ matcher := githubv4mock .NewQueryMatcher (qBasicWithOrder , varsOrderByCreatedAsc , mockResponseOrderedCreatedAsc )
329338 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
330339 case "order by updated at descending" :
331- // BasicWithOrder - use ordered response
332- matcher := githubv4mock .NewQueryMatcher (& BasicWithOrder {}, varsOrderByUpdatedDesc , mockResponseOrderedUpdatedDesc )
340+ matcher := githubv4mock .NewQueryMatcher (qBasicWithOrder , varsOrderByUpdatedDesc , mockResponseOrderedUpdatedDesc )
333341 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
334342 case "filter by category with order" :
335- // WithCategoryAndOrder - use ordered response
336- matcher := githubv4mock .NewQueryMatcher (& WithCategoryAndOrder {}, varsCategoryWithOrder , mockResponseGeneralOrderedDesc )
343+ matcher := githubv4mock .NewQueryMatcher (qWithCategoryAndOrder , varsCategoryWithOrder , mockResponseGeneralOrderedDesc )
337344 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
338345 case "order by without direction (should not use ordering)" :
339- // BasicNoOrder - because useOrdering will be false
340- matcher := githubv4mock .NewQueryMatcher (& BasicNoOrder {}, varsListAll , mockResponseListAll )
346+ matcher := githubv4mock .NewQueryMatcher (qBasicNoOrder , varsListAll , mockResponseListAll )
341347 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
342348 case "direction without order by (should not use ordering)" :
343- // BasicNoOrder - because useOrdering will be false
344- matcher := githubv4mock .NewQueryMatcher (& BasicNoOrder {}, varsListAll , mockResponseListAll )
349+ matcher := githubv4mock .NewQueryMatcher (qBasicNoOrder , varsListAll , mockResponseListAll )
345350 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
346351 case "repository not found error" :
347- matcher := githubv4mock .NewQueryMatcher (& BasicNoOrder {} , varsRepoNotFound , mockErrorRepoNotFound )
352+ matcher := githubv4mock .NewQueryMatcher (qBasicNoOrder , varsRepoNotFound , mockErrorRepoNotFound )
348353 httpClient = githubv4mock .NewMockedHTTPClient (matcher )
349354 }
350355
0 commit comments