(t *testing.T)
| 2442 | } |
| 2443 | |
| 2444 | func Test_CreatePullRequest(t *testing.T) { |
| 2445 | // Verify tool definition once |
| 2446 | serverTool := CreatePullRequest(translations.NullTranslationHelper) |
| 2447 | tool := serverTool.Tool |
| 2448 | require.NoError(t, toolsnaps.Test(tool.Name, tool)) |
| 2449 | |
| 2450 | assert.Equal(t, "create_pull_request", tool.Name) |
| 2451 | assert.NotEmpty(t, tool.Description) |
| 2452 | schema := tool.InputSchema.(*jsonschema.Schema) |
| 2453 | assert.Contains(t, schema.Properties, "owner") |
| 2454 | assert.Contains(t, schema.Properties, "repo") |
| 2455 | assert.Contains(t, schema.Properties, "title") |
| 2456 | assert.Contains(t, schema.Properties, "body") |
| 2457 | assert.Contains(t, schema.Properties, "head") |
| 2458 | assert.Contains(t, schema.Properties, "base") |
| 2459 | assert.Contains(t, schema.Properties, "draft") |
| 2460 | assert.Contains(t, schema.Properties, "maintainer_can_modify") |
| 2461 | assert.ElementsMatch(t, schema.Required, []string{"owner", "repo", "title", "head", "base"}) |
| 2462 | |
| 2463 | // Setup mock PR for success case |
| 2464 | mockPR := &github.PullRequest{ |
| 2465 | Number: github.Ptr(42), |
| 2466 | Title: github.Ptr("Test PR"), |
| 2467 | State: github.Ptr("open"), |
| 2468 | HTMLURL: github.Ptr("https://github.com/owner/repo/pull/42"), |
| 2469 | Head: &github.PullRequestBranch{ |
| 2470 | SHA: github.Ptr("abcd1234"), |
| 2471 | Ref: github.Ptr("feature-branch"), |
| 2472 | }, |
| 2473 | Base: &github.PullRequestBranch{ |
| 2474 | SHA: github.Ptr("efgh5678"), |
| 2475 | Ref: github.Ptr("main"), |
| 2476 | }, |
| 2477 | Body: github.Ptr("This is a test PR"), |
| 2478 | Draft: github.Ptr(false), |
| 2479 | MaintainerCanModify: github.Ptr(true), |
| 2480 | User: &github.User{ |
| 2481 | Login: github.Ptr("testuser"), |
| 2482 | }, |
| 2483 | } |
| 2484 | |
| 2485 | tests := []struct { |
| 2486 | name string |
| 2487 | mockedClient *http.Client |
| 2488 | requestArgs map[string]any |
| 2489 | expectError bool |
| 2490 | expectedPR *github.PullRequest |
| 2491 | expectedErrMsg string |
| 2492 | }{ |
| 2493 | { |
| 2494 | name: "successful PR creation", |
| 2495 | mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ |
| 2496 | PostReposPullsByOwnerByRepo: expectRequestBody(t, map[string]any{ |
| 2497 | "title": "Test PR", |
| 2498 | "body": "This is a test PR", |
| 2499 | "head": "feature-branch", |
| 2500 | "base": "main", |
| 2501 | "draft": false, |
nothing calls this directly
no test coverage detected