mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-06 05:33:10 -06:00
Add pusher tests
This commit is contained in:
parent
8fa07824a5
commit
fb8d24b603
|
|
@ -102,6 +102,13 @@ type OpenID interface {
|
||||||
GetOpenIDTokenAttributes(ctx context.Context, token string) (*api.OpenIDTokenAttributes, error)
|
GetOpenIDTokenAttributes(ctx context.Context, token string) (*api.OpenIDTokenAttributes, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Pusher interface {
|
||||||
|
UpsertPusher(ctx context.Context, p api.Pusher, localpart string) error
|
||||||
|
GetPushers(ctx context.Context, localpart string) ([]api.Pusher, error)
|
||||||
|
RemovePusher(ctx context.Context, appid, pushkey, localpart string) error
|
||||||
|
RemovePushers(ctx context.Context, appid, pushkey string) error
|
||||||
|
}
|
||||||
|
|
||||||
type Database interface {
|
type Database interface {
|
||||||
Account
|
Account
|
||||||
AccountData
|
AccountData
|
||||||
|
|
@ -110,6 +117,7 @@ type Database interface {
|
||||||
LoginToken
|
LoginToken
|
||||||
OpenID
|
OpenID
|
||||||
Profile
|
Profile
|
||||||
|
Pusher
|
||||||
SaveThreePIDAssociation(ctx context.Context, threepid, localpart, medium string) (err error)
|
SaveThreePIDAssociation(ctx context.Context, threepid, localpart, medium string) (err error)
|
||||||
RemoveThreePIDAssociation(ctx context.Context, threepid string, medium string) (err error)
|
RemoveThreePIDAssociation(ctx context.Context, threepid string, medium string) (err error)
|
||||||
GetLocalpartForThreePID(ctx context.Context, threepid string, medium string) (localpart string, err error)
|
GetLocalpartForThreePID(ctx context.Context, threepid string, medium string) (localpart string, err error)
|
||||||
|
|
@ -122,11 +130,6 @@ type Database interface {
|
||||||
GetNotificationCount(ctx context.Context, localpart string, filter tables.NotificationFilter) (int64, error)
|
GetNotificationCount(ctx context.Context, localpart string, filter tables.NotificationFilter) (int64, error)
|
||||||
GetRoomNotificationCounts(ctx context.Context, localpart, roomID string) (total int64, highlight int64, _ error)
|
GetRoomNotificationCounts(ctx context.Context, localpart, roomID string) (total int64, highlight int64, _ error)
|
||||||
DeleteOldNotifications(ctx context.Context) error
|
DeleteOldNotifications(ctx context.Context) error
|
||||||
|
|
||||||
UpsertPusher(ctx context.Context, p api.Pusher, localpart string) error
|
|
||||||
GetPushers(ctx context.Context, localpart string) ([]api.Pusher, error)
|
|
||||||
RemovePusher(ctx context.Context, appid, pushkey, localpart string) error
|
|
||||||
RemovePushers(ctx context.Context, appid, pushkey string) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Err3PIDInUse is the error returned when trying to save an association involving
|
// Err3PIDInUse is the error returned when trying to save an association involving
|
||||||
|
|
|
||||||
|
|
@ -341,3 +341,55 @@ func Test_Profile(t *testing.T) {
|
||||||
assert.Equal(t, *wantProfile, searchRes[0])
|
assert.Equal(t, *wantProfile, searchRes[0])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Pusher(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
alice := test.NewUser()
|
||||||
|
aliceLocalpart, _, err := gomatrixserverlib.SplitID('@', alice.ID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
||||||
|
db, close := mustCreateDatabase(t, dbType)
|
||||||
|
defer close()
|
||||||
|
|
||||||
|
appID := util.RandomString(8)
|
||||||
|
var pushKeys []string
|
||||||
|
var gotPushers []api.Pusher
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
pushKey := util.RandomString(8)
|
||||||
|
|
||||||
|
wantPusher := api.Pusher{
|
||||||
|
PushKey: pushKey,
|
||||||
|
Kind: api.HTTPKind,
|
||||||
|
AppID: appID,
|
||||||
|
AppDisplayName: util.RandomString(8),
|
||||||
|
DeviceDisplayName: util.RandomString(8),
|
||||||
|
ProfileTag: util.RandomString(8),
|
||||||
|
Language: util.RandomString(2),
|
||||||
|
}
|
||||||
|
err = db.UpsertPusher(ctx, wantPusher, aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to upsert pusher")
|
||||||
|
|
||||||
|
// check it was actually persisted
|
||||||
|
gotPushers, err = db.GetPushers(ctx, aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to get pushers")
|
||||||
|
assert.Equal(t, i+1, len(gotPushers))
|
||||||
|
assert.Equal(t, wantPusher, gotPushers[i])
|
||||||
|
pushKeys = append(pushKeys, pushKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove single pusher
|
||||||
|
err = db.RemovePusher(ctx, appID, pushKeys[0], aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to remove pusher")
|
||||||
|
gotPushers, err := db.GetPushers(ctx, aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to get pushers")
|
||||||
|
assert.Equal(t, 1, len(gotPushers))
|
||||||
|
|
||||||
|
// remove last pusher
|
||||||
|
err = db.RemovePushers(ctx, appID, pushKeys[1])
|
||||||
|
assert.NoError(t, err, "unable to remove pusher")
|
||||||
|
gotPushers, err = db.GetPushers(ctx, aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to get pushers")
|
||||||
|
assert.Equal(t, 0, len(gotPushers))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue