code.gitea.io/gitea@v1.19.3/modules/notification/action/action_test.go (about)

     1  // Copyright 2019 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package action
     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  	"github.com/stretchr/testify/assert"
    18  )
    19  
    20  func TestMain(m *testing.M) {
    21  	unittest.MainTest(m, &unittest.TestOptions{
    22  		GiteaRootPath: filepath.Join("..", "..", ".."),
    23  	})
    24  }
    25  
    26  func TestRenameRepoAction(t *testing.T) {
    27  	assert.NoError(t, unittest.PrepareTestDatabase())
    28  
    29  	user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
    30  	repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
    31  	repo.Owner = user
    32  
    33  	oldRepoName := repo.Name
    34  	const newRepoName = "newRepoName"
    35  	repo.Name = newRepoName
    36  	repo.LowerName = strings.ToLower(newRepoName)
    37  
    38  	actionBean := &activities_model.Action{
    39  		OpType:    activities_model.ActionRenameRepo,
    40  		ActUserID: user.ID,
    41  		ActUser:   user,
    42  		RepoID:    repo.ID,
    43  		Repo:      repo,
    44  		IsPrivate: repo.IsPrivate,
    45  		Content:   oldRepoName,
    46  	}
    47  	unittest.AssertNotExistsBean(t, actionBean)
    48  
    49  	NewNotifier().NotifyRenameRepository(db.DefaultContext, user, repo, oldRepoName)
    50  
    51  	unittest.AssertExistsAndLoadBean(t, actionBean)
    52  	unittest.CheckConsistencyFor(t, &activities_model.Action{})
    53  }