code.gitea.io/gitea@v1.21.7/services/feed/action_test.go (about)

     1  // Copyright 2019 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package feed
     5  
     6  import (
     7  	"path/filepath"
     8  	"strings"
     9  	"testing"
    10  
    11  	activities_model "code.gitea.io/gitea/models/activities"
    12  	"code.gitea.io/gitea/models/db"
    13  	repo_model "code.gitea.io/gitea/models/repo"
    14  	"code.gitea.io/gitea/models/unittest"
    15  	user_model "code.gitea.io/gitea/models/user"
    16  
    17  	_ "code.gitea.io/gitea/models/actions"
    18  
    19  	"github.com/stretchr/testify/assert"
    20  )
    21  
    22  func TestMain(m *testing.M) {
    23  	unittest.MainTest(m, &unittest.TestOptions{
    24  		GiteaRootPath: filepath.Join("..", ".."),
    25  	})
    26  }
    27  
    28  func TestRenameRepoAction(t *testing.T) {
    29  	assert.NoError(t, unittest.PrepareTestDatabase())
    30  
    31  	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
    32  	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
    33  	repo.Owner = user
    34  
    35  	oldRepoName := repo.Name
    36  	const newRepoName = "newRepoName"
    37  	repo.Name = newRepoName
    38  	repo.LowerName = strings.ToLower(newRepoName)
    39  
    40  	actionBean := &activities_model.Action{
    41  		OpType:    activities_model.ActionRenameRepo,
    42  		ActUserID: user.ID,
    43  		ActUser:   user,
    44  		RepoID:    repo.ID,
    45  		Repo:      repo,
    46  		IsPrivate: repo.IsPrivate,
    47  		Content:   oldRepoName,
    48  	}
    49  	unittest.AssertNotExistsBean(t, actionBean)
    50  
    51  	NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName)
    52  
    53  	unittest.AssertExistsAndLoadBean(t, actionBean)
    54  	unittest.CheckConsistencyFor(t, &activities_model.Action{})
    55  }