From 602bf1fa7f2f3d4db73dbab83ba889a6b9701427 Mon Sep 17 00:00:00 2001 From: zareck Date: Sat, 4 Nov 2023 15:23:44 -0300 Subject: [PATCH] [TESTS] add TestAPIForkDifferentName Refs: https://codeberg.org/forgejo/forgejo/pulls/1719 (cherry picked from commit ed3413891523b07d4da47347b632ad3a3c7bd16f) (cherry picked from commit 166d769a6eda0cece2ccbfd3c12f1fce41e2c5b8) (cherry picked from commit 8da818646c7c129b9a61b9b983f20ab1af897bc4) (cherry picked from commit 95c9d6ede40f3aab7578f38b1881a2472fd20931) (cherry picked from commit 505ffa2cc444d5917d394a2cebd5e4554d6a0370) --- tests/integration/api_pull_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go index 33cc826e5e..86a8e279d8 100644 --- a/tests/integration/api_pull_test.go +++ b/tests/integration/api_pull_test.go @@ -209,6 +209,29 @@ func TestAPIEditPull(t *testing.T) { MakeRequest(t, req, http.StatusNotFound) } +func TestAPIForkDifferentName(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + // Step 1: get a repo and a user that can fork this repo + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) + + session := loginUser(t, user.Name) + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser) + + // Step 2: fork this repo with another name + forkName := "myfork" + req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/forks?token="+token, owner.Name, repo.Name), + &api.CreateForkOption{Name: &forkName}) + MakeRequest(t, req, http.StatusAccepted) + + // Step 3: make a PR onto the original repo, it should succeed + req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/pulls?state=all&token="+token, owner.Name, repo.Name), + &api.CreatePullRequestOption{Head: user.Name + ":master", Base: "master", Title: "hi"}) + MakeRequest(t, req, http.StatusCreated) +} + func doAPIGetPullFiles(ctx APITestContext, pr *api.PullRequest, callback func(*testing.T, []*api.ChangedFile)) func(*testing.T) { return func(t *testing.T) { req := NewRequest(t, http.MethodGet, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/files", ctx.Username, ctx.Reponame, pr.Index)).