gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

user_test.go (2411B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package bundb_test
     19 
     20 import (
     21 	"context"
     22 	"testing"
     23 
     24 	"github.com/stretchr/testify/suite"
     25 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
     26 )
     27 
     28 type UserTestSuite struct {
     29 	BunDBStandardTestSuite
     30 }
     31 
     32 func (suite *UserTestSuite) TestGetAllUsers() {
     33 	users, err := suite.db.GetAllUsers(context.Background())
     34 	suite.NoError(err)
     35 	suite.Len(users, len(suite.testUsers))
     36 }
     37 
     38 func (suite *UserTestSuite) TestGetUser() {
     39 	user, err := suite.db.GetUserByID(context.Background(), suite.testUsers["local_account_1"].ID)
     40 	suite.NoError(err)
     41 	suite.NotNil(user)
     42 }
     43 
     44 func (suite *UserTestSuite) TestGetUserByEmailAddress() {
     45 	user, err := suite.db.GetUserByEmailAddress(context.Background(), suite.testUsers["local_account_1"].Email)
     46 	suite.NoError(err)
     47 	suite.NotNil(user)
     48 }
     49 
     50 func (suite *UserTestSuite) TestGetUserByAccountID() {
     51 	user, err := suite.db.GetUserByAccountID(context.Background(), suite.testAccounts["local_account_1"].ID)
     52 	suite.NoError(err)
     53 	suite.NotNil(user)
     54 }
     55 
     56 func (suite *UserTestSuite) TestUpdateUserSelectedColumns() {
     57 	testUser := suite.testUsers["local_account_1"]
     58 
     59 	updateUser := new(gtsmodel.User)
     60 	*updateUser = *testUser
     61 	updateUser.Email = "whatever"
     62 	updateUser.Locale = "es"
     63 
     64 	err := suite.db.UpdateUser(context.Background(), updateUser)
     65 	suite.NoError(err)
     66 
     67 	dbUser, err := suite.db.GetUserByID(context.Background(), testUser.ID)
     68 	suite.NoError(err)
     69 	suite.NotNil(dbUser)
     70 	suite.Equal(updateUser.Email, dbUser.Email)
     71 	suite.Equal(updateUser.Locale, dbUser.Locale)
     72 	suite.Equal(testUser.AccountID, dbUser.AccountID)
     73 }
     74 
     75 func TestUserTestSuite(t *testing.T) {
     76 	suite.Run(t, new(UserTestSuite))
     77 }