4
4
"context"
5
5
"encoding/json"
6
6
"net/http"
7
- "strings"
8
7
"testing"
9
8
"time"
10
9
@@ -168,17 +167,17 @@ func Test_ListDiscussions(t *testing.T) {
168
167
}
169
168
require .NoError (t ,err )
170
169
171
- var returnedDiscussions []* github.Issue
170
+ var returnedDiscussions []* github.Discussion
172
171
err = json .Unmarshal ([]byte (text ),& returnedDiscussions )
173
172
require .NoError (t ,err )
174
173
175
174
assert .Len (t ,returnedDiscussions ,tc .expectedCount ,"Expected %d discussions, got %d" ,tc .expectedCount ,len (returnedDiscussions ))
176
175
177
- // Verify that all returned discussions have a categorylabel if filtered
176
+ // Verify that all returned discussions have a category if filtered
178
177
if _ ,hasCategory := tc .reqParams ["category" ];hasCategory {
179
178
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 categorylabel prefix " )
179
+ require .NotNil (t ,discussion .DiscussionCategory ,"Discussion should have category" )
180
+ assert .NotEmpty (t ,* discussion .DiscussionCategory .Name ,"Discussion should have categoryname " )
182
181
}
183
182
}
184
183
})
@@ -200,7 +199,6 @@ func Test_GetDiscussion(t *testing.T) {
200
199
Discussion struct {
201
200
Number githubv4.Int
202
201
Body githubv4.String
203
- State githubv4.String
204
202
CreatedAt githubv4.DateTime
205
203
URL githubv4.String `graphql:"url"`
206
204
Category struct {
@@ -218,7 +216,7 @@ func Test_GetDiscussion(t *testing.T) {
218
216
name string
219
217
response githubv4mock.GQLResponse
220
218
expectError bool
221
- expected * github.Issue
219
+ expected * github.Discussion
222
220
errContains string
223
221
}{
224
222
{
@@ -227,23 +225,19 @@ func Test_GetDiscussion(t *testing.T) {
227
225
"repository" :map [string ]any {"discussion" :map [string ]any {
228
226
"number" :1 ,
229
227
"body" :"This is a test discussion" ,
230
- "state" :"open" ,
231
228
"url" :"https://github.com/owner/repo/discussions/1" ,
232
229
"createdAt" :"2025-04-25T12:00:00Z" ,
233
230
"category" :map [string ]any {"name" :"General" },
234
231
}},
235
232
}),
236
233
expectError :false ,
237
- expected :& github.Issue {
234
+ expected :& github.Discussion {
238
235
HTMLURL :github .Ptr ("https://github.com/owner/repo/discussions/1" ),
239
236
Number :github .Ptr (1 ),
240
237
Body :github .Ptr ("This is a test discussion" ),
241
- State :github .Ptr ("open" ),
242
238
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" ),
247
241
},
248
242
},
249
243
},
@@ -272,15 +266,13 @@ func Test_GetDiscussion(t *testing.T) {
272
266
}
273
267
274
268
require .NoError (t ,err )
275
- var out github.Issue
269
+ var out github.Discussion
276
270
require .NoError (t ,json .Unmarshal ([]byte (text ),& out ))
277
271
assert .Equal (t ,* tc .expected .HTMLURL ,* out .HTMLURL )
278
272
assert .Equal (t ,* tc .expected .Number ,* out .Number )
279
273
assert .Equal (t ,* tc .expected .Body ,* out .Body )
280
- assert .Equal (t ,* tc .expected .State ,* out .State )
281
274
// 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 )
284
276
})
285
277
}
286
278
}