From ff05046df7c0ce21f70b0dd8dce59dd5e01771de Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Sat, 4 Sep 2021 13:29:56 +0200 Subject: tests + announce notification fix (#193) --- internal/processing/fromfederator_test.go | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 internal/processing/fromfederator_test.go (limited to 'internal/processing/fromfederator_test.go') diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go new file mode 100644 index 000000000..598af5337 --- /dev/null +++ b/internal/processing/fromfederator_test.go @@ -0,0 +1,86 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package processing_test + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/suite" + "github.com/superseriousbusiness/gotosocial/internal/ap" + "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/messages" +) + +type FromFederatorTestSuite struct { + ProcessingStandardTestSuite +} + +// remote_account_1 boosts the first status of local_account_1 +func (suite *FromFederatorTestSuite) TestProcessFederationAnnounce() { + boostedStatus := suite.testStatuses["local_account_1_status_1"] + boostingAccount := suite.testAccounts["remote_account_1"] + announceStatus := >smodel.Status{} + announceStatus.URI = "https://example.org/some-announce-uri" + announceStatus.BoostOf = >smodel.Status{ + URI: boostedStatus.URI, + } + announceStatus.CreatedAt = time.Now() + announceStatus.UpdatedAt = time.Now() + announceStatus.AccountID = boostingAccount.ID + announceStatus.AccountURI = boostingAccount.URI + announceStatus.Account = boostingAccount + announceStatus.Visibility = boostedStatus.Visibility + + err := suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{ + APObjectType: ap.ActivityAnnounce, + APActivityType: ap.ActivityCreate, + GTSModel: announceStatus, + ReceivingAccount: suite.testAccounts["local_account_1"], + }) + suite.NoError(err) + + // side effects should be triggered + // 1. status should have an ID, and be in the database + suite.NotEmpty(announceStatus.ID) + _, err = suite.db.GetStatusByID(context.Background(), announceStatus.ID) + suite.NoError(err) + + // 2. a notification should exist for the announce + where := []db.Where{ + { + Key: "status_id", + Value: announceStatus.ID, + }, + } + notif := >smodel.Notification{} + err = suite.db.GetWhere(context.Background(), where, notif) + suite.NoError(err) + suite.Equal(gtsmodel.NotificationReblog, notif.NotificationType) + suite.Equal(boostedStatus.AccountID, notif.TargetAccountID) + suite.Equal(announceStatus.AccountID, notif.OriginAccountID) + suite.Equal(announceStatus.ID, notif.StatusID) + suite.False(notif.Read) +} + +func TestFromFederatorTestSuite(t *testing.T) { + suite.Run(t, &FromFederatorTestSuite{}) +} -- cgit v1.2.3