(t *testing.T)
| 704 | } |
| 705 | |
| 706 | func Test_MergePullRequest(t *testing.T) { |
| 707 | // Verify tool definition once |
| 708 | serverTool := MergePullRequest(translations.NullTranslationHelper) |
| 709 | tool := serverTool.Tool |
| 710 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 711 | |
| 712 | assert.Equal(t, "merge_pull_request", tool.Name) |
| 713 | assert.NotEmpty(t, tool.Description) |
| 714 | schema := tool.InputSchema.(*jsonschema.Schema) |
| 715 | assert.Contains(t, schema.Properties, "owner") |
| 716 | assert.Contains(t, schema.Properties, "repo") |
| 717 | assert.Contains(t, schema.Properties, "pullNumber") |
| 718 | assert.Contains(t, schema.Properties, "commit_title") |
| 719 | assert.Contains(t, schema.Properties, "commit_message") |
| 720 | assert.Contains(t, schema.Properties, "merge_method") |
| 721 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "pullNumber"}) |
| 722 | |
| 723 | // Setup mock merge result for success case |
| 724 | mockMergeResult := &github.PullRequestMergeResult{ |
| 725 | Merged: github.Ptr(true), |
| 726 | Message: github.Ptr("Pull Request successfully merged"), |
| 727 | SHA: github.Ptr("abcd1234efgh5678"), |
| 728 | } |
| 729 | |
| 730 | tests := []struct { |
| 731 | name string |
| 732 | mockedClient *http.Client |
| 733 | requestArgs map[string]any |
| 734 | expectError bool |
| 735 | expectedMergeResult *github.PullRequestMergeResult |
| 736 | expectedErrMsg string |
| 737 | }{ |
| 738 | { |
| 739 | name: "successful merge", |
| 740 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 741 | PutReposPullsMergeByOwnerByRepoByPullNumber: expectRequestBody(t, map[string]any{ |
| 742 | "commit_title": "Merge PR #42", |
| 743 | "commit_message": "Merging awesome feature", |
| 744 | "merge_method": "squash", |
| 745 | }).andThen( |
| 746 | mockResponse(t, http.StatusOK, mockMergeResult), |
| 747 | ), |
| 748 | }), |
| 749 | requestArgs: map[string]any{ |
| 750 | "owner": "owner", |
| 751 | "repo": "repo", |
| 752 | "pullNumber": float64(42), |
| 753 | "commit_title": "Merge PR #42", |
| 754 | "commit_message": "Merging awesome feature", |
| 755 | "merge_method": "squash", |
| 756 | }, |
| 757 | expectError: false, |
| 758 | expectedMergeResult: mockMergeResult, |
| 759 | }, |
| 760 | { |
| 761 | name: "merge fails", |
| 762 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 763 | PutReposPullsMergeByOwnerByRepoByPullNumber: func(w http.ResponseWriter, _ *http.Request) { |
nothing calls this directly
no test coverage detected