[bugfix] Fix setting bot on/off (#3986)

* [bugfix] Fix setting bot on/off

* read client messages in tests

* test fix
This commit is contained in:
tobi
2025-04-11 16:36:40 +02:00
committed by GitHub
parent eb4114bf12
commit c8a780e12a
5 changed files with 97 additions and 23 deletions

View File

@@ -26,6 +26,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/ap"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
type AccountUpdateTestSuite struct {
@@ -331,6 +332,64 @@ func (suite *AccountUpdateTestSuite) TestAccountUpdateNoteNotFields() {
suite.Equal(fieldsBefore, len(dbAccount.Fields))
}
func (suite *AccountUpdateTestSuite) TestAccountUpdateBotNotBot() {
testAccount := &gtsmodel.Account{}
*testAccount = *suite.testAccounts["local_account_1"]
ctx := context.Background()
// Call update function to set bot = true.
apiAccount, errWithCode := suite.accountProcessor.Update(
ctx,
testAccount,
&apimodel.UpdateCredentialsRequest{
Bot: util.Ptr(true),
},
)
if errWithCode != nil {
suite.FailNow(errWithCode.Error())
}
// Returned profile should be updated.
suite.True(apiAccount.Bot)
// We should have an update in the client api channel.
msg, _ := suite.getClientMsg(5 * time.Second)
suite.NotNil(msg)
// Check database model of account as well.
dbAccount, err := suite.db.GetAccountByID(ctx, testAccount.ID)
if err != nil {
suite.FailNow(err.Error())
}
suite.True(dbAccount.ActorType.IsBot())
// Call update function to set bot = false.
apiAccount, errWithCode = suite.accountProcessor.Update(
ctx,
testAccount,
&apimodel.UpdateCredentialsRequest{
Bot: util.Ptr(false),
},
)
if errWithCode != nil {
suite.FailNow(errWithCode.Error())
}
// Returned profile should be updated.
suite.False(apiAccount.Bot)
// We should have an update in the client api channel.
msg, _ = suite.getClientMsg(5 * time.Second)
suite.NotNil(msg)
// Check database model of account as well.
dbAccount, err = suite.db.GetAccountByID(ctx, testAccount.ID)
if err != nil {
suite.FailNow(err.Error())
}
suite.False(dbAccount.ActorType.IsBot())
}
func TestAccountUpdateTestSuite(t *testing.T) {
suite.Run(t, new(AccountUpdateTestSuite))
}