2019-11-08 14:54:50 -06:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package action
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-08-24 21:31:57 -05:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2022-11-19 02:12:33 -06:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-12-09 19:27:50 -06:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 08:36:47 -06:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 03:49:20 -06:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 06:34:35 -06:00
|
|
|
|
2019-11-08 14:54:50 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2022-04-14 08:58:21 -05:00
|
|
|
unittest.MainTest(m, &unittest.TestOptions{
|
|
|
|
GiteaRootPath: filepath.Join("..", "..", ".."),
|
|
|
|
})
|
2019-11-08 14:54:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenameRepoAction(t *testing.T) {
|
2021-11-12 08:36:47 -06:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-11-08 14:54:50 -06:00
|
|
|
|
2022-08-15 21:22:25 -05:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
|
2019-11-08 14:54:50 -06:00
|
|
|
repo.Owner = user
|
|
|
|
|
|
|
|
oldRepoName := repo.Name
|
|
|
|
const newRepoName = "newRepoName"
|
|
|
|
repo.Name = newRepoName
|
|
|
|
repo.LowerName = strings.ToLower(newRepoName)
|
|
|
|
|
2022-08-24 21:31:57 -05:00
|
|
|
actionBean := &activities_model.Action{
|
|
|
|
OpType: activities_model.ActionRenameRepo,
|
2019-11-08 14:54:50 -06:00
|
|
|
ActUserID: user.ID,
|
|
|
|
ActUser: user,
|
|
|
|
RepoID: repo.ID,
|
|
|
|
Repo: repo,
|
|
|
|
IsPrivate: repo.IsPrivate,
|
|
|
|
Content: oldRepoName,
|
|
|
|
}
|
2021-11-16 02:53:21 -06:00
|
|
|
unittest.AssertNotExistsBean(t, actionBean)
|
2019-11-08 14:54:50 -06:00
|
|
|
|
2022-11-19 02:12:33 -06:00
|
|
|
NewNotifier().NotifyRenameRepository(db.DefaultContext, user, repo, oldRepoName)
|
2019-11-08 14:54:50 -06:00
|
|
|
|
2021-11-16 02:53:21 -06:00
|
|
|
unittest.AssertExistsAndLoadBean(t, actionBean)
|
2022-08-24 21:31:57 -05:00
|
|
|
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
2019-11-08 14:54:50 -06:00
|
|
|
}
|