2019-05-30 09:09:05 -06:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-05-30 09:09:05 -06:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 07:36:47 -07:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2023-09-01 05:26:07 -06:00
|
|
|
"code.gitea.io/gitea/modules/contexttest"
|
2019-05-30 09:09:05 -06:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2021-01-26 08:36:53 -07:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2019-05-30 09:09:05 -06:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepoEdit(t *testing.T) {
|
2021-11-12 07:36:47 -07:00
|
|
|
unittest.PrepareTestEnv(t)
|
2019-05-30 09:09:05 -06:00
|
|
|
|
2023-09-01 05:26:07 -06:00
|
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1")
|
|
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Repo.Owner = ctx.Doer
|
2019-05-30 09:09:05 -06:00
|
|
|
description := "new description"
|
|
|
|
website := "http://wwww.newwebsite.com"
|
|
|
|
private := true
|
|
|
|
hasIssues := false
|
|
|
|
hasWiki := false
|
|
|
|
defaultBranch := "master"
|
|
|
|
hasPullRequests := true
|
|
|
|
ignoreWhitespaceConflicts := true
|
|
|
|
allowMerge := false
|
|
|
|
allowRebase := false
|
|
|
|
allowRebaseMerge := false
|
|
|
|
allowSquashMerge := false
|
|
|
|
archived := true
|
|
|
|
opts := api.EditRepoOption{
|
|
|
|
Name: &ctx.Repo.Repository.Name,
|
|
|
|
Description: &description,
|
|
|
|
Website: &website,
|
|
|
|
Private: &private,
|
|
|
|
HasIssues: &hasIssues,
|
|
|
|
HasWiki: &hasWiki,
|
|
|
|
DefaultBranch: &defaultBranch,
|
|
|
|
HasPullRequests: &hasPullRequests,
|
|
|
|
IgnoreWhitespaceConflicts: &ignoreWhitespaceConflicts,
|
|
|
|
AllowMerge: &allowMerge,
|
|
|
|
AllowRebase: &allowRebase,
|
|
|
|
AllowRebaseMerge: &allowRebaseMerge,
|
|
|
|
AllowSquash: &allowSquashMerge,
|
|
|
|
Archived: &archived,
|
|
|
|
}
|
|
|
|
|
2023-05-20 19:50:53 -06:00
|
|
|
web.SetForm(ctx, &opts)
|
|
|
|
Edit(ctx)
|
2019-05-30 09:09:05 -06:00
|
|
|
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
2021-12-09 18:27:50 -07:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
2019-05-30 09:09:05 -06:00
|
|
|
ID: 1,
|
2021-11-16 01:53:21 -07:00
|
|
|
}, unittest.Cond("name = ? AND is_archived = 1", *opts.Name))
|
2019-05-30 09:09:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoEditNameChange(t *testing.T) {
|
2021-11-12 07:36:47 -07:00
|
|
|
unittest.PrepareTestEnv(t)
|
2019-05-30 09:09:05 -06:00
|
|
|
|
2023-09-01 05:26:07 -06:00
|
|
|
ctx, _ := contexttest.MockAPIContext(t, "user2/repo1")
|
|
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2022-03-22 01:03:22 -06:00
|
|
|
ctx.Repo.Owner = ctx.Doer
|
2019-05-30 09:09:05 -06:00
|
|
|
name := "newname"
|
|
|
|
opts := api.EditRepoOption{
|
|
|
|
Name: &name,
|
|
|
|
}
|
|
|
|
|
2023-05-20 19:50:53 -06:00
|
|
|
web.SetForm(ctx, &opts)
|
|
|
|
Edit(ctx)
|
2019-05-30 09:09:05 -06:00
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{
|
2019-05-30 09:09:05 -06:00
|
|
|
ID: 1,
|
2021-11-16 01:53:21 -07:00
|
|
|
}, unittest.Cond("name = ?", opts.Name))
|
2019-05-30 09:09:05 -06:00
|
|
|
}
|