Skip to content

Commit 751dfa5

Browse files
committed
update tests to account for recent changes (author login, updated at date)
1 parent bcb82c8 commit 751dfa5

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

pkg/github/discussions_test.go

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,37 @@ import (
1717

1818
var (
1919
discussionsGeneral = []map[string]any{
20-
{"number": 1, "title": "Discussion 1 title", "createdAt": "2023-01-01T00:00:00Z", "url": "https://github.com/owner/repo/discussions/1", "category": map[string]any{"name": "General"}},
21-
{"number": 3, "title": "Discussion 3 title", "createdAt": "2023-03-01T00:00:00Z", "url": "https://github.com/owner/repo/discussions/3", "category": map[string]any{"name": "General"}},
20+
{"number": 1, "title": "Discussion 1 title", "createdAt": "2023-01-01T00:00:00Z", "updatedAt": "2023-01-01T00:00:00Z", "author": map[string]any{"login": "user1"}, "url": "https://github.com/owner/repo/discussions/1", "category": map[string]any{"name": "General"}},
21+
{"number": 3, "title": "Discussion 3 title", "createdAt": "2023-03-01T00:00:00Z", "updatedAt": "2023-02-01T00:00:00Z", "author": map[string]any{"login": "user1"}, "url": "https://github.com/owner/repo/discussions/3", "category": map[string]any{"name": "General"}},
2222
}
2323
discussionsAll = []map[string]any{
24-
{"number": 1, "title": "Discussion 1 title", "createdAt": "2023-01-01T00:00:00Z", "url": "https://github.com/owner/repo/discussions/1", "category": map[string]any{"name": "General"}},
25-
{"number": 2, "title": "Discussion 2 title", "createdAt": "2023-02-01T00:00:00Z", "url": "https://github.com/owner/repo/discussions/2", "category": map[string]any{"name": "Questions"}},
26-
{"number": 3, "title": "Discussion 3 title", "createdAt": "2023-03-01T00:00:00Z", "url": "https://github.com/owner/repo/discussions/3", "category": map[string]any{"name": "General"}},
24+
{
25+
"number": 1,
26+
"title": "Discussion 1 title",
27+
"createdAt": "2023-01-01T00:00:00Z",
28+
"updatedAt": "2023-01-01T00:00:00Z",
29+
"author": map[string]any{"login": "user1"},
30+
"url": "https://github.com/owner/repo/discussions/1",
31+
"category": map[string]any{"name": "General"},
32+
},
33+
{
34+
"number": 2,
35+
"title": "Discussion 2 title",
36+
"createdAt": "2023-02-01T00:00:00Z",
37+
"updatedAt": "2023-02-01T00:00:00Z",
38+
"author": map[string]any{"login": "user2"},
39+
"url": "https://github.com/owner/repo/discussions/2",
40+
"category": map[string]any{"name": "Questions"},
41+
},
42+
{
43+
"number": 3,
44+
"title": "Discussion 3 title",
45+
"createdAt": "2023-03-01T00:00:00Z",
46+
"updatedAt": "2023-03-01T00:00:00Z",
47+
"author": map[string]any{"login": "user3"},
48+
"url": "https://github.com/owner/repo/discussions/3",
49+
"category": map[string]any{"name": "General"},
50+
},
2751
}
2852
mockResponseListAll = githubv4mock.DataResponse(map[string]any{
2953
"repository": map[string]any{
@@ -48,15 +72,19 @@ func Test_ListDiscussions(t *testing.T) {
4872
assert.Contains(t, toolDef.InputSchema.Properties, "repo")
4973
assert.ElementsMatch(t, toolDef.InputSchema.Required, []string{"owner", "repo"})
5074

51-
// mock for the call to ListDiscussions without category filter
52-
var qDiscussions struct {
75+
// Mock for BasicNoOrder query
76+
var qBasicNoOrder struct {
5377
Repository struct {
5478
Discussions struct {
5579
Nodes []struct {
5680
Number githubv4.Int
5781
Title githubv4.String
5882
CreatedAt githubv4.DateTime
59-
Category struct {
83+
UpdatedAt githubv4.DateTime
84+
Author struct {
85+
Login githubv4.String
86+
}
87+
Category struct {
6088
Name githubv4.String
6189
} `graphql:"category"`
6290
URL githubv4.String `graphql:"url"`
@@ -65,15 +93,19 @@ func Test_ListDiscussions(t *testing.T) {
6593
} `graphql:"repository(owner: $owner, name: $repo)"`
6694
}
6795

68-
// mock for the call to get discussions with category filter
69-
var qDiscussionsFiltered struct {
96+
// Mock for WithCategoryNoOrder query
97+
var qWithCategoryNoOrder struct {
7098
Repository struct {
7199
Discussions struct {
72100
Nodes []struct {
73101
Number githubv4.Int
74102
Title githubv4.String
75103
CreatedAt githubv4.DateTime
76-
Category struct {
104+
UpdatedAt githubv4.DateTime // Added
105+
Author struct { // Added
106+
Login githubv4.String
107+
}
108+
Category struct {
77109
Name githubv4.String
78110
} `graphql:"category"`
79111
URL githubv4.String `graphql:"url"`
@@ -141,15 +173,16 @@ func Test_ListDiscussions(t *testing.T) {
141173

142174
switch tc.name {
143175
case "list all discussions without category filter":
144-
// Simple case - no category filter
145-
matcher := githubv4mock.NewQueryMatcher(qDiscussions, varsListAll, mockResponseListAll)
176+
// Simple case - BasicNoOrder query structure (i.e. no order, no category)
177+
matcher := githubv4mock.NewQueryMatcher(qBasicNoOrder, varsListAll, mockResponseListAll)
146178
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
147179
case "filter by category ID":
148-
// Simple case - category filter using category ID directly
149-
matcher := githubv4mock.NewQueryMatcher(qDiscussionsFiltered, varsDiscussionsFiltered, mockResponseListGeneral)
180+
// WithCategoryNoOrder
181+
matcher := githubv4mock.NewQueryMatcher(qWithCategoryNoOrder, varsDiscussionsFiltered, mockResponseListGeneral)
150182
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
183+
// BasicNoOrder
151184
case "repository not found error":
152-
matcher := githubv4mock.NewQueryMatcher(qDiscussions, varsRepoNotFound, mockErrorRepoNotFound)
185+
matcher := githubv4mock.NewQueryMatcher(qBasicNoOrder, varsRepoNotFound, mockErrorRepoNotFound)
153186
httpClient = githubv4mock.NewMockedHTTPClient(matcher)
154187
}
155188

0 commit comments

Comments
 (0)