[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 602bf1fa7f2f3d4db73dbab83ba889a6b9701427)

[TESTS] add TestAPIForkDifferentName (squash) do not use token= query param

See https://codeberg.org/forgejo/forgejo/commit/33439b733a

(cherry picked from commit d600fabdbcaa8eb01e7b0f6bf337fa1aa844c2da)
(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)
This commit is contained in:
zareck 2023-11-04 15:23:44 -03:00 committed by Earl Warren
parent 6f960f23e5
commit 3916357840
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 0579CB2928A78A00

View file

@ -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", owner.Name, repo.Name),
&api.CreateForkOption{Name: &forkName}).AddTokenAuth(token)
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", owner.Name, repo.Name),
&api.CreatePullRequestOption{Head: user.Name + ":master", Base: "master", Title: "hi"}).AddTokenAuth(token)
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)).