Skip to content

Commit

Permalink
tests + announce notification fix (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored Sep 4, 2021
1 parent 25edd57 commit ff05046
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 165 deletions.
25 changes: 0 additions & 25 deletions internal/db/bundb/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,12 @@ import (
"time"

"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type AccountTestSuite struct {
BunDBStandardTestSuite
}

func (suite *AccountTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *AccountTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *AccountTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}

func (suite *AccountTestSuite) TestGetAccountByIDWithExtras() {
account, err := suite.db.GetAccountByID(context.Background(), suite.testAccounts["local_account_1"].ID)
if err != nil {
Expand Down
25 changes: 0 additions & 25 deletions internal/db/bundb/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,12 @@ import (

"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type BasicTestSuite struct {
BunDBStandardTestSuite
}

func (suite *BasicTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *BasicTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *BasicTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}

func (suite *BasicTestSuite) TestGetAccountByID() {
testAccount := suite.testAccounts["local_account_1"]

Expand Down
25 changes: 25 additions & 0 deletions internal/db/bundb/bundb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type BunDBStandardTestSuite struct {
Expand All @@ -44,3 +45,27 @@ type BunDBStandardTestSuite struct {
testTags map[string]*gtsmodel.Tag
testMentions map[string]*gtsmodel.Mention
}

func (suite *BunDBStandardTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *BunDBStandardTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *BunDBStandardTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}
65 changes: 65 additions & 0 deletions internal/db/bundb/mention_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors [email protected]
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 <http://www.gnu.org/licenses/>.
*/

package bundb_test

import (
"context"
"testing"

"github.com/stretchr/testify/suite"
)

type MentionTestSuite struct {
BunDBStandardTestSuite
}

func (suite *MentionTestSuite) TestGetMention() {
m := suite.testMentions["local_user_2_mention_zork"]

dbMention, err := suite.db.GetMention(context.Background(), m.ID)
suite.NoError(err)
suite.NotNil(dbMention)
suite.Equal(m.ID, dbMention.ID)
suite.Equal(m.OriginAccountID, dbMention.OriginAccountID)
suite.NotNil(dbMention.OriginAccount)
suite.Equal(m.TargetAccountID, dbMention.TargetAccountID)
suite.NotNil(dbMention.TargetAccount)
suite.Equal(m.StatusID, dbMention.StatusID)
suite.NotNil(dbMention.Status)
}

func (suite *MentionTestSuite) TestGetMentions() {
m := suite.testMentions["local_user_2_mention_zork"]

dbMentions, err := suite.db.GetMentions(context.Background(), []string{m.ID})
suite.NoError(err)
suite.Len(dbMentions, 1)
dbMention := dbMentions[0]
suite.Equal(m.ID, dbMention.ID)
suite.Equal(m.OriginAccountID, dbMention.OriginAccountID)
suite.NotNil(dbMention.OriginAccount)
suite.Equal(m.TargetAccountID, dbMention.TargetAccountID)
suite.NotNil(dbMention.TargetAccount)
suite.Equal(m.StatusID, dbMention.StatusID)
suite.NotNil(dbMention.Status)
}

func TestMentionTestSuite(t *testing.T) {
suite.Run(t, new(MentionTestSuite))
}
25 changes: 0 additions & 25 deletions internal/db/bundb/relationship_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,12 @@ import (

"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type RelationshipTestSuite struct {
BunDBStandardTestSuite
}

func (suite *RelationshipTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *RelationshipTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *RelationshipTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}

func (suite *RelationshipTestSuite) TestIsBlocked() {
suite.Suite.T().Skip("TODO: implement")
}
Expand Down
25 changes: 0 additions & 25 deletions internal/db/bundb/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,12 @@ import (
"testing"

"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type SessionTestSuite struct {
BunDBStandardTestSuite
}

func (suite *SessionTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *SessionTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *SessionTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}

func (suite *SessionTestSuite) TestGetSession() {
session, err := suite.db.GetSession(context.Background())
suite.NoError(err)
Expand Down
25 changes: 0 additions & 25 deletions internal/db/bundb/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,12 @@ import (
"time"

"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type StatusTestSuite struct {
BunDBStandardTestSuite
}

func (suite *StatusTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *StatusTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *StatusTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}

func (suite *StatusTestSuite) TestGetStatusByID() {
status, err := suite.db.GetStatusByID(context.Background(), suite.testStatuses["local_account_1_status_1"].ID)
if err != nil {
Expand Down
25 changes: 0 additions & 25 deletions internal/db/bundb/timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,12 @@ import (
"testing"

"github.com/stretchr/testify/suite"
"github.com/superseriousbusiness/gotosocial/testrig"
)

type TimelineTestSuite struct {
BunDBStandardTestSuite
}

func (suite *TimelineTestSuite) SetupSuite() {
suite.testTokens = testrig.NewTestTokens()
suite.testClients = testrig.NewTestClients()
suite.testApplications = testrig.NewTestApplications()
suite.testUsers = testrig.NewTestUsers()
suite.testAccounts = testrig.NewTestAccounts()
suite.testAttachments = testrig.NewTestAttachments()
suite.testStatuses = testrig.NewTestStatuses()
suite.testTags = testrig.NewTestTags()
suite.testMentions = testrig.NewTestMentions()
}

func (suite *TimelineTestSuite) SetupTest() {
suite.config = testrig.NewTestConfig()
suite.db = testrig.NewTestDB()
suite.log = testrig.NewTestLog()

testrig.StandardDBSetup(suite.db, suite.testAccounts)
}

func (suite *TimelineTestSuite) TearDownTest() {
testrig.StandardDBTeardown(suite.db)
}

func (suite *TimelineTestSuite) TestGetPublicTimeline() {
viewingAccount := suite.testAccounts["local_account_1"]

Expand Down
2 changes: 1 addition & 1 deletion internal/processing/fromclientapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/messages"
)

func (p *processor) processFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
func (p *processor) ProcessFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
switch clientMsg.APActivityType {
case ap.ActivityCreate:
// CREATE
Expand Down
14 changes: 6 additions & 8 deletions internal/processing/fromcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ func (p *processor) notifyStatus(ctx context.Context, status *gtsmodel.Status) e
}

// make sure a notif doesn't already exist for this mention
err := p.db.GetWhere(ctx, []db.Where{
if err := p.db.GetWhere(ctx, []db.Where{
{Key: "notification_type", Value: gtsmodel.NotificationMention},
{Key: "target_account_id", Value: m.TargetAccountID},
{Key: "origin_account_id", Value: status.AccountID},
{Key: "status_id", Value: status.ID},
}, &gtsmodel.Notification{})
if err == nil {
{Key: "origin_account_id", Value: m.OriginAccountID},
{Key: "status_id", Value: m.StatusID},
}, &gtsmodel.Notification{}); err == nil {
// notification exists already so just continue
continue
}
if err != db.ErrNoEntries {
} else if err != db.ErrNoEntries {
// there's a real error in the db
return fmt.Errorf("notifyStatus: error checking existence of notification for mention with id %s : %s", m.ID, err)
}
Expand Down Expand Up @@ -254,7 +252,7 @@ func (p *processor) notifyAnnounce(ctx context.Context, status *gtsmodel.Status)
status.BoostOfAccount = boostedAcct
}

if status.BoostOfAccount.Domain == "" {
if status.BoostOfAccount.Domain != "" {
// remote account, nothing to do
return nil
}
Expand Down
6 changes: 2 additions & 4 deletions internal/processing/fromfederator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/messages"
)

func (p *processor) processFromFederator(ctx context.Context, federatorMsg messages.FromFederator) error {
func (p *processor) ProcessFromFederator(ctx context.Context, federatorMsg messages.FromFederator) error {
l := p.log.WithFields(logrus.Fields{
"func": "processFromFederator",
"federatorMsg": fmt.Sprintf("%+v", federatorMsg),
Expand Down Expand Up @@ -104,9 +104,7 @@ func (p *processor) processFromFederator(ctx context.Context, federatorMsg messa
incomingAnnounce.ID = incomingAnnounceID

if err := p.db.PutStatus(ctx, incomingAnnounce); err != nil {
if err != db.ErrNoEntries {
return fmt.Errorf("error adding dereferenced announce to the db: %s", err)
}
return fmt.Errorf("error adding dereferenced announce to the db: %s", err)
}

if err := p.timelineStatus(ctx, incomingAnnounce); err != nil {
Expand Down
Loading

0 comments on commit ff05046

Please sign in to comment.