2019-11-09 04:54:50 +08:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-11-09 04:54:50 +08:00
|
|
|
|
2023-09-05 21:00:52 +08:00
|
|
|
package feed
|
2019-11-09 04:54:50 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-08-25 10:31:57 +08:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2022-11-19 09:12:33 +01:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-12-10 09:27:50 +08:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 17:49:20 +08:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-17 20:34:35 +08:00
|
|
|
|
2024-11-06 19:28:11 -08:00
|
|
|
_ "code.gitea.io/gitea/models"
|
2023-09-08 12:51:15 +08:00
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
|
|
|
|
2019-11-09 04:54:50 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-28 09:38:53 +08:00
|
|
|
unittest.MainTest(m)
|
2019-11-09 04:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRenameRepoAction(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-11-09 04:54:50 +08:00
|
|
|
|
2022-08-16 10:22:25 +08:00
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
|
2019-11-09 04:54:50 +08:00
|
|
|
repo.Owner = user
|
|
|
|
|
|
|
|
oldRepoName := repo.Name
|
|
|
|
const newRepoName = "newRepoName"
|
|
|
|
repo.Name = newRepoName
|
|
|
|
repo.LowerName = strings.ToLower(newRepoName)
|
|
|
|
|
2022-08-25 10:31:57 +08:00
|
|
|
actionBean := &activities_model.Action{
|
|
|
|
OpType: activities_model.ActionRenameRepo,
|
2019-11-09 04:54:50 +08:00
|
|
|
ActUserID: user.ID,
|
|
|
|
ActUser: user,
|
|
|
|
RepoID: repo.ID,
|
|
|
|
Repo: repo,
|
|
|
|
IsPrivate: repo.IsPrivate,
|
|
|
|
Content: oldRepoName,
|
|
|
|
}
|
2021-11-16 16:53:21 +08:00
|
|
|
unittest.AssertNotExistsBean(t, actionBean)
|
2019-11-09 04:54:50 +08:00
|
|
|
|
2023-09-06 02:37:47 +08:00
|
|
|
NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName)
|
2019-11-09 04:54:50 +08:00
|
|
|
|
2021-11-16 16:53:21 +08:00
|
|
|
unittest.AssertExistsAndLoadBean(t, actionBean)
|
2022-08-25 10:31:57 +08:00
|
|
|
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
2019-11-09 04:54:50 +08:00
|
|
|
}
|