(t *testing.T)
| 1168 | } |
| 1169 | |
| 1170 | func Test_CreateIssue(t *testing.T) { |
| 1171 | // Verify tool definition once |
| 1172 | serverTool := IssueWrite(translations.NullTranslationHelper) |
| 1173 | tool := serverTool.Tool |
| 1174 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 1175 | require.Empty(t, serverTool.FeatureFlagEnable) |
| 1176 | |
| 1177 | assert.Equal(t, "issue_write", tool.Name) |
| 1178 | assert.NotEmpty(t, tool.Description) |
| 1179 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "method") |
| 1180 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "owner") |
| 1181 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "repo") |
| 1182 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "title") |
| 1183 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "body") |
| 1184 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "assignees") |
| 1185 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "labels") |
| 1186 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "milestone") |
| 1187 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "type") |
| 1188 | assert.Contains(t, tool.InputSchema.(*jsonschema.Schema).Properties, "issue_fields") |
| 1189 | assert.ElementsMatch(t, tool.InputSchema.(*jsonschema.Schema).Required, []string{"method", "owner", "repo"}) |
| 1190 | |
| 1191 | // Setup mock issue for success case |
| 1192 | mockIssue := &github.Issue{ |
| 1193 | Number: github.Ptr(123), |
| 1194 | Title: github.Ptr("Test Issue"), |
| 1195 | Body: github.Ptr("This is a test issue"), |
| 1196 | State: github.Ptr("open"), |
| 1197 | HTMLURL: github.Ptr("https://github.com/owner/repo/issues/123"), |
| 1198 | Assignees: []*github.User{{Login: github.Ptr("user1")}, {Login: github.Ptr("user2")}}, |
| 1199 | Labels: []*github.Label{{Name: github.Ptr("bug")}, {Name: github.Ptr("help wanted")}}, |
| 1200 | Milestone: &github.Milestone{Number: github.Ptr(5)}, |
| 1201 | Type: &github.IssueType{Name: github.Ptr("Bug")}, |
| 1202 | } |
| 1203 | |
| 1204 | tests := []struct { |
| 1205 | name string |
| 1206 | mockedClient *http.Client |
| 1207 | mockedGQLClient *http.Client |
| 1208 | requestArgs map[string]any |
| 1209 | expectError bool |
| 1210 | expectedIssue *github.Issue |
| 1211 | expectedErrMsg string |
| 1212 | }{ |
| 1213 | { |
| 1214 | name: "successful issue creation with all fields", |
| 1215 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 1216 | PostReposIssuesByOwnerByRepo: expectRequestBody(t, map[string]any{ |
| 1217 | "title": "Test Issue", |
| 1218 | "body": "This is a test issue", |
| 1219 | "labels": []any{"bug", "help wanted"}, |
| 1220 | "assignees": []any{"user1", "user2"}, |
| 1221 | "milestone": float64(5), |
| 1222 | "type": "Bug", |
| 1223 | }).andThen( |
| 1224 | mockResponse(t, http.StatusCreated, mockIssue), |
| 1225 | ), |
| 1226 | }), |
| 1227 | requestArgs: map[string]any{ |
nothing calls this directly
no test coverage detected