diff options
Diffstat (limited to 'internal/processing/account')
| -rw-r--r-- | internal/processing/account/update.go | 12 | ||||
| -rw-r--r-- | internal/processing/account/update_test.go | 59 |
2 files changed, 69 insertions, 2 deletions
diff --git a/internal/processing/account/update.go b/internal/processing/account/update.go index 60d2cb8f6..83a046a25 100644 --- a/internal/processing/account/update.go +++ b/internal/processing/account/update.go @@ -77,8 +77,16 @@ func (p *Processor) Update(ctx context.Context, account *gtsmodel.Account, form acctColumns = append(acctColumns, "discoverable") } - if form.Bot != nil { - account.ActorType = gtsmodel.AccountActorTypeService + if bot := form.Bot; bot != nil { + if *bot { + // Mark account as an Application. + // See: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-application + account.ActorType = gtsmodel.AccountActorTypeApplication + } else { + // Mark account as a Person. + // See: https://www.w3.org/TR/activitystreams-vocabulary/#dfn-person + account.ActorType = gtsmodel.AccountActorTypePerson + } acctColumns = append(acctColumns, "actor_type") } diff --git a/internal/processing/account/update_test.go b/internal/processing/account/update_test.go index a07562544..674502b75 100644 --- a/internal/processing/account/update_test.go +++ b/internal/processing/account/update_test.go @@ -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 := >smodel.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)) } |
