44 "context"
55 "encoding/json"
66 "net/http"
7- "strings"
87 "testing"
98 "time"
109
@@ -168,17 +167,17 @@ func Test_ListDiscussions(t *testing.T) {
168167 }
169168 require .NoError (t , err )
170169
171- var returnedDiscussions []* github.Issue
170+ var returnedDiscussions []* github.Discussion
172171 err = json .Unmarshal ([]byte (text ), & returnedDiscussions )
173172 require .NoError (t , err )
174173
175174 assert .Len (t , returnedDiscussions , tc .expectedCount , "Expected %d discussions, got %d" , tc .expectedCount , len (returnedDiscussions ))
176175
177- // Verify that all returned discussions have a category label if filtered
176+ // Verify that all returned discussions have a category if filtered
178177 if _ , hasCategory := tc .reqParams ["category" ]; hasCategory {
179178 for _ , discussion := range returnedDiscussions {
180- require .NotEmpty (t , discussion .Labels , "Discussion should have category label " )
181- assert .True (t , strings . HasPrefix ( * discussion .Labels [ 0 ] .Name , "category:" ), " Discussion should have category label prefix " )
179+ require .NotNil (t , discussion .DiscussionCategory , "Discussion should have category" )
180+ assert .NotEmpty (t , * discussion .DiscussionCategory .Name , "Discussion should have category name " )
182181 }
183182 }
184183 })
@@ -200,7 +199,6 @@ func Test_GetDiscussion(t *testing.T) {
200199 Discussion struct {
201200 Number githubv4.Int
202201 Body githubv4.String
203- State githubv4.String
204202 CreatedAt githubv4.DateTime
205203 URL githubv4.String `graphql:"url"`
206204 Category struct {
@@ -218,7 +216,7 @@ func Test_GetDiscussion(t *testing.T) {
218216 name string
219217 response githubv4mock.GQLResponse
220218 expectError bool
221- expected * github.Issue
219+ expected * github.Discussion
222220 errContains string
223221 }{
224222 {
@@ -227,23 +225,19 @@ func Test_GetDiscussion(t *testing.T) {
227225 "repository" : map [string ]any {"discussion" : map [string ]any {
228226 "number" : 1 ,
229227 "body" : "This is a test discussion" ,
230- "state" : "open" ,
231228 "url" : "https://github.com/owner/repo/discussions/1" ,
232229 "createdAt" : "2025-04-25T12:00:00Z" ,
233230 "category" : map [string ]any {"name" : "General" },
234231 }},
235232 }),
236233 expectError : false ,
237- expected : & github.Issue {
234+ expected : & github.Discussion {
238235 HTMLURL : github .Ptr ("https://github.com/owner/repo/discussions/1" ),
239236 Number : github .Ptr (1 ),
240237 Body : github .Ptr ("This is a test discussion" ),
241- State : github .Ptr ("open" ),
242238 CreatedAt : & github.Timestamp {Time : time .Date (2025 , 4 , 25 , 12 , 0 , 0 , 0 , time .UTC )},
243- Labels : []* github.Label {
244- {
245- Name : github .Ptr ("category:General" ),
246- },
239+ DiscussionCategory : & github.DiscussionCategory {
240+ Name : github .Ptr ("General" ),
247241 },
248242 },
249243 },
@@ -272,15 +266,13 @@ func Test_GetDiscussion(t *testing.T) {
272266 }
273267
274268 require .NoError (t , err )
275- var out github.Issue
269+ var out github.Discussion
276270 require .NoError (t , json .Unmarshal ([]byte (text ), & out ))
277271 assert .Equal (t , * tc .expected .HTMLURL , * out .HTMLURL )
278272 assert .Equal (t , * tc .expected .Number , * out .Number )
279273 assert .Equal (t , * tc .expected .Body , * out .Body )
280- assert .Equal (t , * tc .expected .State , * out .State )
281274 // Check category label
282- require .Len (t , out .Labels , 1 )
283- assert .Equal (t , * tc .expected .Labels [0 ].Name , * out .Labels [0 ].Name )
275+ assert .Equal (t , * tc .expected .DiscussionCategory .Name , * out .DiscussionCategory .Name )
284276 })
285277 }
286278}
0 commit comments