[TESTS] add TestAPIForkDifferentName

Refs: https://codeberg.org/forgejo/forgejo/pulls/1719

(cherry picked from commit ed34138915)
(cherry picked from commit 166d769a6e)
(cherry picked from commit 8da818646c)
(cherry picked from commit 95c9d6ede4)
(cherry picked from commit 505ffa2cc4)
(cherry picked from commit 602bf1fa7f)

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

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

(cherry picked from commit d600fabdbc)
(cherry picked from commit 40c1130c41)
(cherry picked from commit 7b254f84cf)
(cherry picked from commit af15c5a60a)
This commit is contained in:
zareck 2023-11-04 15:23:44 -03:00 committed by Earl Warren
parent 5b2f1d7149
commit 852b42bc7a
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -209,6 +209,29 @@ func TestAPIEditPull(t *testing.T) {
MakeRequest(t, req, http.StatusNotFound) 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) { func doAPIGetPullFiles(ctx APITestContext, pr *api.PullRequest, callback func(*testing.T, []*api.ChangedFile)) func(*testing.T) {
return func(t *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)). req := NewRequest(t, http.MethodGet, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/files", ctx.Username, ctx.Reponame, pr.Index)).