Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
Dishika Vaishkiyar
2024-10-25 17:01:03 +05:30
коммит произвёл GitHub
родитель 64b30abbce
Коммит 4f5a389185
2 изменённых файлов: 76 добавлений и 22 удалений

Просмотреть файл

@@ -92,7 +92,6 @@ issues:
channels/app/authorization_test.go|\
channels/app/auto_responder_test.go|\
channels/app/bot.go|\
channels/app/bot_test.go|\
channels/app/brand.go|\
channels/app/busy_test.go|\
channels/app/channel.go|\

Просмотреть файл

@@ -79,7 +79,10 @@ func TestCreateBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}()
assert.Equal(t, "username", bot.Username)
assert.Equal(t, "a bot", bot.Description)
assert.Equal(t, th.BasicUser.Id, bot.OwnerId)
@@ -197,7 +200,10 @@ func TestPatchBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}()
botPatch := &model.BotPatch{
Username: sToP("invalid username"),
@@ -220,7 +226,10 @@ func TestPatchBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}()
botPatch := &model.BotPatch{
Username: sToP("username"),
@@ -246,7 +255,10 @@ func TestPatchBot(t *testing.T) {
createdBot, err := th.App.CreateBot(th.Context, bot)
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
require.Nil(t, err)
}()
botPatch := &model.BotPatch{
Username: sToP("username2"),
@@ -278,7 +290,10 @@ func TestPatchBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}()
botPatch := &model.BotPatch{
Username: sToP(th.BasicUser2.Username),
@@ -300,7 +315,10 @@ func TestGetBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot1.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot1.UserId)
require.Nil(t, err)
}()
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username2",
@@ -308,7 +326,10 @@ func TestGetBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot2.UserId)
require.Nil(t, err)
}()
deletedBot, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username3",
@@ -318,7 +339,10 @@ func TestGetBot(t *testing.T) {
require.Nil(t, err)
deletedBot, err = th.App.UpdateBotActive(th.Context, deletedBot.UserId, false)
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, deletedBot.UserId)
defer func() {
err := th.App.PermanentDeleteBot(th.Context, deletedBot.UserId)
require.Nil(t, err)
}()
t.Run("get unknown bot", func(t *testing.T) {
_, err := th.App.GetBot(th.Context, model.NewId(), false)
@@ -364,7 +388,10 @@ func TestGetBots(t *testing.T) {
OwnerId: OwnerId1,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot1.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot1.UserId)
require.Nil(t, err)
}()
deletedBot1, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username4",
@@ -374,7 +401,10 @@ func TestGetBots(t *testing.T) {
require.Nil(t, err)
deletedBot1, err = th.App.UpdateBotActive(th.Context, deletedBot1.UserId, false)
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, deletedBot1.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, deletedBot1.UserId)
require.Nil(t, err)
}()
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username2",
@@ -382,7 +412,10 @@ func TestGetBots(t *testing.T) {
OwnerId: OwnerId1,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot2.UserId)
require.Nil(t, err)
}()
bot3, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username3",
@@ -390,7 +423,10 @@ func TestGetBots(t *testing.T) {
OwnerId: OwnerId1,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot3.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot3.UserId)
require.Nil(t, err)
}()
bot4, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username5",
@@ -398,7 +434,10 @@ func TestGetBots(t *testing.T) {
OwnerId: OwnerId2,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot4.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot4.UserId)
require.Nil(t, err)
}()
deletedBot2, err := th.App.CreateBot(th.Context, &model.Bot{
Username: "username6",
@@ -408,7 +447,10 @@ func TestGetBots(t *testing.T) {
require.Nil(t, err)
deletedBot2, err = th.App.UpdateBotActive(th.Context, deletedBot2.UserId, false)
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, deletedBot2.UserId)
defer func() {
err := th.App.PermanentDeleteBot(th.Context, deletedBot2.UserId)
require.Nil(t, err)
}()
t.Run("get bots, page=0, perPage=10", func(t *testing.T) {
bots, err := th.App.GetBots(th.Context, &model.BotGetOptions{
@@ -563,7 +605,10 @@ func TestUpdateBotActive(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}()
disabledBot, err := th.App.UpdateBotActive(th.Context, bot.UserId, false)
require.Nil(t, err)
@@ -613,7 +658,8 @@ func TestDisableUserBots(t *testing.T) {
bots := []*model.Bot{}
defer func() {
for _, bot := range bots {
th.App.PermanentDeleteBot(th.Context, bot.UserId)
err := th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}
}()
@@ -634,7 +680,10 @@ func TestDisableUserBots(t *testing.T) {
OwnerId: ownerId2,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, u2bot1.UserId)
defer func() {
err = th.App.PermanentDeleteBot(th.Context, u2bot1.UserId)
require.Nil(t, err)
}()
err = th.App.disableUserBots(th.Context, ownerId1)
require.Nil(t, err)
@@ -667,7 +716,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
userBots := []*model.Bot{}
defer func() {
for _, bot := range userBots {
th.App.PermanentDeleteBot(th.Context, bot.UserId)
err := th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}
}()
@@ -680,7 +730,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
_, err := th.App.CreateUser(th.Context, &sysadmin1)
require.Nil(t, err, "failed to create user")
th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
_, err = th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
require.Nil(t, err)
sysadmin2 := model.User{
Email: "sys2@example.com",
@@ -690,7 +741,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
_, err = th.App.CreateUser(th.Context, &sysadmin2)
require.Nil(t, err, "failed to create user")
th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
_, err = th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
require.Nil(t, err)
// create user to be disabled
user1, err := th.App.CreateUser(th.Context, &model.User{
@@ -829,7 +881,10 @@ func TestConvertUserToBot(t *testing.T) {
Id: th.BasicUser.Id,
})
require.Nil(t, err)
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
defer func() {
err := th.App.PermanentDeleteBot(th.Context, bot.UserId)
require.Nil(t, err)
}()
assert.Equal(t, "username", bot.Username)
assert.Equal(t, th.BasicUser.Id, bot.OwnerId)
})