Skip to content

Commit 6a16955

Browse files
committed
test: add type test for create and update issues
1 parent e733f06 commit 6a16955

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

pkg/github/issues_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ func Test_CreateIssue(t *testing.T) {
396396
assert.Contains(t, tool.InputSchema.Properties, "assignees")
397397
assert.Contains(t, tool.InputSchema.Properties, "labels")
398398
assert.Contains(t, tool.InputSchema.Properties, "milestone")
399+
assert.Contains(t, tool.InputSchema.Properties, "type")
399400
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "title"})
400401

401402
// Setup mock issue for success case
@@ -408,6 +409,7 @@ func Test_CreateIssue(t *testing.T) {
408409
Assignees: []*github.User{{Login: github.Ptr("user1")}, {Login: github.Ptr("user2")}},
409410
Labels: []*github.Label{{Name: github.Ptr("bug")}, {Name: github.Ptr("help wanted")}},
410411
Milestone: &github.Milestone{Number: github.Ptr(5)},
412+
Type: &github.IssueType{Name: github.Ptr("Bug")},
411413
}
412414

413415
tests := []struct {
@@ -429,6 +431,7 @@ func Test_CreateIssue(t *testing.T) {
429431
"labels": []any{"bug", "help wanted"},
430432
"assignees": []any{"user1", "user2"},
431433
"milestone": float64(5),
434+
"type": "Bug",
432435
}).andThen(
433436
mockResponse(t, http.StatusCreated, mockIssue),
434437
),
@@ -442,6 +445,7 @@ func Test_CreateIssue(t *testing.T) {
442445
"assignees": []any{"user1", "user2"},
443446
"labels": []any{"bug", "help wanted"},
444447
"milestone": float64(5),
448+
"type": "Bug",
445449
},
446450
expectError: false,
447451
expectedIssue: mockIssue,
@@ -537,6 +541,10 @@ func Test_CreateIssue(t *testing.T) {
537541
assert.Equal(t, *tc.expectedIssue.Body, *returnedIssue.Body)
538542
}
539543

544+
if tc.expectedIssue.Type != nil {
545+
assert.Equal(t, *tc.expectedIssue.Type.Name, *returnedIssue.Type.Name)
546+
}
547+
540548
// Check assignees if expected
541549
if len(tc.expectedIssue.Assignees) > 0 {
542550
assert.Equal(t, len(tc.expectedIssue.Assignees), len(returnedIssue.Assignees))
@@ -748,6 +756,7 @@ func Test_UpdateIssue(t *testing.T) {
748756
assert.Contains(t, tool.InputSchema.Properties, "labels")
749757
assert.Contains(t, tool.InputSchema.Properties, "assignees")
750758
assert.Contains(t, tool.InputSchema.Properties, "milestone")
759+
assert.Contains(t, tool.InputSchema.Properties, "type")
751760
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo", "issue_number"})
752761

753762
// Setup mock issue for success case
@@ -760,6 +769,7 @@ func Test_UpdateIssue(t *testing.T) {
760769
Assignees: []*github.User{{Login: github.Ptr("assignee1")}, {Login: github.Ptr("assignee2")}},
761770
Labels: []*github.Label{{Name: github.Ptr("bug")}, {Name: github.Ptr("priority")}},
762771
Milestone: &github.Milestone{Number: github.Ptr(5)},
772+
Type: &github.IssueType{Name: github.Ptr("Bug")},
763773
}
764774

765775
tests := []struct {
@@ -782,6 +792,7 @@ func Test_UpdateIssue(t *testing.T) {
782792
"labels": []any{"bug", "priority"},
783793
"assignees": []any{"assignee1", "assignee2"},
784794
"milestone": float64(5),
795+
"type": "Bug",
785796
}).andThen(
786797
mockResponse(t, http.StatusOK, mockIssue),
787798
),
@@ -797,6 +808,7 @@ func Test_UpdateIssue(t *testing.T) {
797808
"labels": []any{"bug", "priority"},
798809
"assignees": []any{"assignee1", "assignee2"},
799810
"milestone": float64(5),
811+
"type": "Bug",
800812
},
801813
expectError: false,
802814
expectedIssue: mockIssue,
@@ -808,24 +820,27 @@ func Test_UpdateIssue(t *testing.T) {
808820
mock.PatchReposIssuesByOwnerByRepoByIssueNumber,
809821
mockResponse(t, http.StatusOK, &github.Issue{
810822
Number: github.Ptr(123),
811-
Title: github.Ptr("Only Title Updated"),
823+
Title: github.Ptr("Updated Issue Title"),
812824
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"),
813825
State: github.Ptr("open"),
826+
Type: &github.IssueType{Name: github.Ptr("Feature")},
814827
}),
815828
),
816829
),
817830
requestArgs: map[string]interface{}{
818831
"owner": "owner",
819832
"repo": "repo",
820833
"issue_number": float64(123),
821-
"title": "Only Title Updated",
834+
"title": "Updated Issue Title",
835+
"type": "Feature",
822836
},
823837
expectError: false,
824838
expectedIssue: &github.Issue{
825839
Number: github.Ptr(123),
826-
Title: github.Ptr("Only Title Updated"),
840+
Title: github.Ptr("Updated Issue Title"),
827841
HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"),
828842
State: github.Ptr("open"),
843+
Type: &github.IssueType{Name: github.Ptr("Feature")},
829844
},
830845
},
831846
{
@@ -914,6 +929,10 @@ func Test_UpdateIssue(t *testing.T) {
914929
assert.Equal(t, *tc.expectedIssue.Body, *returnedIssue.Body)
915930
}
916931

932+
if tc.expectedIssue.Type != nil {
933+
assert.Equal(t, *tc.expectedIssue.Type.Name, *returnedIssue.Type.Name)
934+
}
935+
917936
// Check assignees if expected
918937
if len(tc.expectedIssue.Assignees) > 0 {
919938
assert.Len(t, returnedIssue.Assignees, len(tc.expectedIssue.Assignees))

0 commit comments

Comments
 (0)