Skip to content

Commit 3916357

Browse files
cassiozareckearl-warren
authored andcommitted
[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) (cherry picked from commit 602bf1f) [TESTS] add TestAPIForkDifferentName (squash) do not use token= query param See https://codeberg.org/forgejo/forgejo/commit/33439b733a (cherry picked from commit d600fab) (cherry picked from commit 40c1130c410359ab007c2b92081856ca0f805c55) (cherry picked from commit 7b254f84cfd3aa58ee80d7ea8ae0e1c9636cdc3e) (cherry picked from commit af15c5a60a773b4af8760f94b82ab704f19a29be) (cherry picked from commit 852b42bc7a48620efd778cea728374cc1e325451) (cherry picked from commit 90b3d0ca09a2057265ee371767232496399168ce)
1 parent 6f960f2 commit 3916357

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/integration/api_pull_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,29 @@ func TestAPIEditPull(t *testing.T) {
209209
MakeRequest(t, req, http.StatusNotFound)
210210
}
211211

212+
func TestAPIForkDifferentName(t *testing.T) {
213+
defer tests.PrepareTestEnv(t)()
214+
215+
// Step 1: get a repo and a user that can fork this repo
216+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
217+
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
218+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
219+
220+
session := loginUser(t, user.Name)
221+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeWriteUser)
222+
223+
// Step 2: fork this repo with another name
224+
forkName := "myfork"
225+
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/forks", owner.Name, repo.Name),
226+
&api.CreateForkOption{Name: &forkName}).AddTokenAuth(token)
227+
MakeRequest(t, req, http.StatusAccepted)
228+
229+
// Step 3: make a PR onto the original repo, it should succeed
230+
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/pulls?state=all", owner.Name, repo.Name),
231+
&api.CreatePullRequestOption{Head: user.Name + ":master", Base: "master", Title: "hi"}).AddTokenAuth(token)
232+
MakeRequest(t, req, http.StatusCreated)
233+
}
234+
212235
func doAPIGetPullFiles(ctx APITestContext, pr *api.PullRequest, callback func(*testing.T, []*api.ChangedFile)) func(*testing.T) {
213236
return func(t *testing.T) {
214237
req := NewRequest(t, http.MethodGet, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/files", ctx.Username, ctx.Reponame, pr.Index)).

0 commit comments

Comments
 (0)