mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-02-03 20:21:00 +01:00
Test Web Push notifications from workers
This commit is contained in:
parent
05b8156ba5
commit
1d0e608c81
@ -36,6 +36,7 @@
|
|||||||
"github.com/superseriousbusiness/gotosocial/internal/stream"
|
"github.com/superseriousbusiness/gotosocial/internal/stream"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/webpush"
|
||||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -179,6 +180,28 @@ func (suite *FromClientAPITestSuite) checkStreamed(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkWebPushed asserts that the target account got a single Web Push notification with a given type.
|
||||||
|
func (suite *FromClientAPITestSuite) checkWebPushed(
|
||||||
|
sender *webpush.MockSender,
|
||||||
|
accountID string,
|
||||||
|
notificationType gtsmodel.NotificationType,
|
||||||
|
) {
|
||||||
|
pushedNotifications := sender.Sent[accountID]
|
||||||
|
if suite.Len(pushedNotifications, 1) {
|
||||||
|
pushedNotification := pushedNotifications[0]
|
||||||
|
suite.Equal(notificationType, pushedNotification.NotificationType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkNotWebPushed asserts that the target account got no Web Push notifications.
|
||||||
|
func (suite *FromClientAPITestSuite) checkNotWebPushed(
|
||||||
|
sender *webpush.MockSender,
|
||||||
|
accountID string,
|
||||||
|
) {
|
||||||
|
pushedNotifications := sender.Sent[accountID]
|
||||||
|
suite.Len(pushedNotifications, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) statusJSON(
|
func (suite *FromClientAPITestSuite) statusJSON(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
typeConverter *typeutils.Converter,
|
typeConverter *typeutils.Converter,
|
||||||
@ -341,6 +364,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithNotification() {
|
|||||||
string(notifJSON),
|
string(notifJSON),
|
||||||
stream.EventTypeNotification,
|
stream.EventTypeNotification,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for a Web Push status notification.
|
||||||
|
suite.checkWebPushed(testStructs.WebPushSender, receivingAccount.ID, gtsmodel.NotificationStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
|
||||||
@ -409,6 +435,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
|
|||||||
statusJSON,
|
statusJSON,
|
||||||
stream.EventTypeUpdate,
|
stream.EventTypeUpdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
|
||||||
@ -470,6 +499,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
|
|||||||
|
|
||||||
suite.ErrorIs(err, db.ErrNoEntries)
|
suite.ErrorIs(err, db.ErrNoEntries)
|
||||||
suite.Nil(notif)
|
suite.Nil(notif)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
|
||||||
@ -531,6 +563,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
|
|||||||
|
|
||||||
suite.ErrorIs(err, db.ErrNoEntries)
|
suite.ErrorIs(err, db.ErrNoEntries)
|
||||||
suite.Nil(notif)
|
suite.Nil(notif)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyOK() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyOK() {
|
||||||
@ -607,6 +642,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
|
|||||||
statusJSON,
|
statusJSON,
|
||||||
stream.EventTypeUpdate,
|
stream.EventTypeUpdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyNo() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyNo() {
|
||||||
@ -689,6 +727,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyLis
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPolicyNone() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPolicyNone() {
|
||||||
@ -765,6 +806,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyListRepliesPoli
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
|
||||||
@ -829,6 +873,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoost() {
|
|||||||
statusJSON,
|
statusJSON,
|
||||||
stream.EventTypeUpdate,
|
stream.EventTypeUpdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() {
|
func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostNoReblogs() {
|
||||||
@ -981,6 +1028,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWhichBeginsConversat
|
|||||||
conversationJSON,
|
conversationJSON,
|
||||||
stream.EventTypeConversation,
|
stream.EventTypeConversation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for a Web Push mention notification.
|
||||||
|
suite.checkWebPushed(testStructs.WebPushSender, receivingAccount.ID, gtsmodel.NotificationMention)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A public message to a local user should not result in a conversation notification.
|
// A public message to a local user should not result in a conversation notification.
|
||||||
@ -1050,6 +1100,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWhichShouldNotCreate
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for a Web Push mention notification.
|
||||||
|
suite.checkWebPushed(testStructs.WebPushSender, receivingAccount.ID, gtsmodel.NotificationMention)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A public status with a hashtag followed by a local user who does not otherwise follow the author
|
// A public status with a hashtag followed by a local user who does not otherwise follow the author
|
||||||
@ -1123,6 +1176,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithFollowedHashtag(
|
|||||||
"",
|
"",
|
||||||
stream.EventTypeUpdate,
|
stream.EventTypeUpdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A public status with a hashtag followed by a local user who does not otherwise follow the author
|
// A public status with a hashtag followed by a local user who does not otherwise follow the author
|
||||||
@ -1204,6 +1260,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithFollowedHashtagA
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A boost of a public status with a hashtag followed by a local user
|
// A boost of a public status with a hashtag followed by a local user
|
||||||
@ -1306,6 +1365,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBoostWithFollowedHashtag()
|
|||||||
"",
|
"",
|
||||||
stream.EventTypeUpdate,
|
stream.EventTypeUpdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A boost of a public status with a hashtag followed by a local user
|
// A boost of a public status with a hashtag followed by a local user
|
||||||
@ -1416,6 +1478,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBoostWithFollowedHashtagAn
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A boost of a public status with a hashtag followed by a local user
|
// A boost of a public status with a hashtag followed by a local user
|
||||||
@ -1526,6 +1591,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateBoostWithFollowedHashtagAn
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A public status with a hashtag followed by a local user who follows the author and has them on an exclusive list
|
// A public status with a hashtag followed by a local user who follows the author and has them on an exclusive list
|
||||||
@ -1598,6 +1666,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithAuthorOnExclusiv
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A public status with a hashtag followed by a local user who follows the author and has them on an exclusive list
|
// A public status with a hashtag followed by a local user who follows the author and has them on an exclusive list
|
||||||
@ -1712,6 +1783,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithAuthorOnExclusiv
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A public status with a hashtag followed by a local user who follows the author and has them on an exclusive list
|
// A public status with a hashtag followed by a local user who follows the author and has them on an exclusive list
|
||||||
@ -1837,6 +1911,9 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusWithAuthorOnExclusiv
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for a Web Push status notification.
|
||||||
|
suite.checkWebPushed(testStructs.WebPushSender, receivingAccount.ID, gtsmodel.NotificationStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updating a public status with a hashtag followed by a local user who does not otherwise follow the author
|
// Updating a public status with a hashtag followed by a local user who does not otherwise follow the author
|
||||||
@ -1910,6 +1987,9 @@ func (suite *FromClientAPITestSuite) TestProcessUpdateStatusWithFollowedHashtag(
|
|||||||
"",
|
"",
|
||||||
stream.EventTypeStatusUpdate,
|
stream.EventTypeStatusUpdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
|
func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
|
||||||
@ -1963,6 +2043,9 @@ func (suite *FromClientAPITestSuite) TestProcessStatusDelete() {
|
|||||||
stream.EventTypeDelete,
|
stream.EventTypeDelete,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for absence of Web Push notifications.
|
||||||
|
suite.checkNotWebPushed(testStructs.WebPushSender, receivingAccount.ID)
|
||||||
|
|
||||||
// Boost should no longer be in the database.
|
// Boost should no longer be in the database.
|
||||||
if !testrig.WaitFor(func() bool {
|
if !testrig.WaitFor(func() bool {
|
||||||
_, err := testStructs.State.DB.GetStatusByID(ctx, boostOfDeletedStatus.ID)
|
_, err := testStructs.State.DB.GetStatusByID(ctx, boostOfDeletedStatus.ID)
|
||||||
|
@ -45,6 +45,7 @@ func (suite *SurfaceNotifyTestSuite) TestSpamNotifs() {
|
|||||||
Stream: testStructs.Processor.Stream(),
|
Stream: testStructs.Processor.Stream(),
|
||||||
VisFilter: visibility.NewFilter(testStructs.State),
|
VisFilter: visibility.NewFilter(testStructs.State),
|
||||||
EmailSender: testStructs.EmailSender,
|
EmailSender: testStructs.EmailSender,
|
||||||
|
WebPushSender: testStructs.WebPushSender,
|
||||||
Conversations: testStructs.Processor.Conversations(),
|
Conversations: testStructs.Processor.Conversations(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ type TestStructs struct {
|
|||||||
HTTPClient *MockHTTPClient
|
HTTPClient *MockHTTPClient
|
||||||
TypeConverter *typeutils.Converter
|
TypeConverter *typeutils.Converter
|
||||||
EmailSender email.Sender
|
EmailSender email.Sender
|
||||||
|
WebPushSender *webpush.MockSender
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupTestStructs(
|
func SetupTestStructs(
|
||||||
@ -79,7 +80,7 @@ func SetupTestStructs(
|
|||||||
federator := NewTestFederator(&state, transportController, mediaManager)
|
federator := NewTestFederator(&state, transportController, mediaManager)
|
||||||
oauthServer := NewTestOauthServer(db)
|
oauthServer := NewTestOauthServer(db)
|
||||||
emailSender := NewEmailSender(rTemplatePath, nil)
|
emailSender := NewEmailSender(rTemplatePath, nil)
|
||||||
webPushSender := webpush.NewNoopSender()
|
webPushSender := webpush.NewMockSender()
|
||||||
|
|
||||||
common := common.New(
|
common := common.New(
|
||||||
&state,
|
&state,
|
||||||
@ -114,6 +115,7 @@ func SetupTestStructs(
|
|||||||
HTTPClient: httpClient,
|
HTTPClient: httpClient,
|
||||||
TypeConverter: typeconverter,
|
TypeConverter: typeconverter,
|
||||||
EmailSender: emailSender,
|
EmailSender: emailSender,
|
||||||
|
WebPushSender: webPushSender,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user