(t *testing.T)
| 4102 | } |
| 4103 | |
| 4104 | func TestAddIssueComment(t *testing.T) { |
| 4105 | t.Parallel() |
| 4106 | |
| 4107 | serverTool := AddIssueComment(translations.NullTranslationHelper) |
| 4108 | tool := serverTool.Tool |
| 4109 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 4110 | |
| 4111 | assert.Equal(t, "add_issue_comment", tool.Name) |
| 4112 | assert.NotEmpty(t, tool.Description) |
| 4113 | schema := tool.InputSchema.(*jsonschema.Schema) |
| 4114 | assert.Contains(t, schema.Properties, "owner") |
| 4115 | assert.Contains(t, schema.Properties, "repo") |
| 4116 | assert.Contains(t, schema.Properties, "issue_number") |
| 4117 | assert.Contains(t, schema.Properties, "comment_id") |
| 4118 | assert.Contains(t, schema.Properties, "body") |
| 4119 | assert.Contains(t, schema.Properties, "reaction") |
| 4120 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "issue_number"}) |
| 4121 | |
| 4122 | mockComment := &github.IssueComment{ |
| 4123 | ID: github.Ptr(int64(456)), |
| 4124 | Body: github.Ptr("This is a comment"), |
| 4125 | HTMLURL: github.Ptr("https://github.com/owner/repo/issues/42#issuecomment-456"), |
| 4126 | } |
| 4127 | mockReaction := &github.Reaction{ |
| 4128 | ID: github.Ptr(int64(789)), |
| 4129 | Content: github.Ptr("heart"), |
| 4130 | } |
| 4131 | mockIssueComment := &github.IssueComment{ |
| 4132 | ID: github.Ptr(int64(999)), |
| 4133 | IssueURL: github.Ptr("https://api.github.com/repos/owner/repo/issues/42"), |
| 4134 | } |
| 4135 | commentCreatedAfterReactionFailure := &atomic.Bool{} |
| 4136 | |
| 4137 | tests := []struct { |
| 4138 | name string |
| 4139 | mockedClient *http.Client |
| 4140 | requestArgs map[string]any |
| 4141 | expectToolError bool |
| 4142 | expectedToolErrMsg string |
| 4143 | unexpectedCall *atomic.Bool |
| 4144 | }{ |
| 4145 | { |
| 4146 | name: "successful comment on issue", |
| 4147 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 4148 | PostReposIssuesCommentsByOwnerByRepoByIssueNumber: mockResponse(t, http.StatusCreated, mockComment), |
| 4149 | }), |
| 4150 | requestArgs: map[string]any{ |
| 4151 | "owner": "owner", |
| 4152 | "repo": "repo", |
| 4153 | "issue_number": float64(42), |
| 4154 | "body": "This is a comment", |
| 4155 | }, |
| 4156 | }, |
| 4157 | { |
| 4158 | name: "successful reaction to issue", |
| 4159 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 4160 | PostReposIssuesReactionsByOwnerByRepoByIssueNumber: mockResponse(t, http.StatusCreated, mockReaction), |
| 4161 | }), |
nothing calls this directly
no test coverage detected