mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 11:13:12 -06:00
Add ThreePID tests
This commit is contained in:
parent
fb8d24b603
commit
0d4e0bed3f
|
|
@ -109,6 +109,13 @@ type Pusher interface {
|
||||||
RemovePushers(ctx context.Context, appid, pushkey string) error
|
RemovePushers(ctx context.Context, appid, pushkey string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ThreePID interface {
|
||||||
|
SaveThreePIDAssociation(ctx context.Context, threepid, localpart, 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)
|
||||||
|
GetThreePIDsForLocalpart(ctx context.Context, localpart string) (threepids []authtypes.ThreePID, err error)
|
||||||
|
}
|
||||||
|
|
||||||
type Database interface {
|
type Database interface {
|
||||||
Account
|
Account
|
||||||
AccountData
|
AccountData
|
||||||
|
|
@ -118,10 +125,7 @@ type Database interface {
|
||||||
OpenID
|
OpenID
|
||||||
Profile
|
Profile
|
||||||
Pusher
|
Pusher
|
||||||
SaveThreePIDAssociation(ctx context.Context, threepid, localpart, medium string) (err error)
|
ThreePID
|
||||||
RemoveThreePIDAssociation(ctx context.Context, threepid string, medium string) (err error)
|
|
||||||
GetLocalpartForThreePID(ctx context.Context, threepid string, medium string) (localpart string, err error)
|
|
||||||
GetThreePIDsForLocalpart(ctx context.Context, localpart string) (threepids []authtypes.ThreePID, err error)
|
|
||||||
|
|
||||||
InsertNotification(ctx context.Context, localpart, eventID string, pos int64, tweaks map[string]interface{}, n *api.Notification) error
|
InsertNotification(ctx context.Context, localpart, eventID string, pos int64, tweaks map[string]interface{}, n *api.Notification) error
|
||||||
DeleteNotificationsUpTo(ctx context.Context, localpart, roomID string, pos int64) (affected bool, err error)
|
DeleteNotificationsUpTo(ctx context.Context, localpart, roomID string, pos int64) (affected bool, err error)
|
||||||
|
|
|
||||||
|
|
@ -393,3 +393,41 @@ func Test_Pusher(t *testing.T) {
|
||||||
assert.Equal(t, 0, len(gotPushers))
|
assert.Equal(t, 0, len(gotPushers))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_ThreePID(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()
|
||||||
|
threePID := util.RandomString(8)
|
||||||
|
medium := util.RandomString(8)
|
||||||
|
err = db.SaveThreePIDAssociation(ctx, threePID, aliceLocalpart, medium)
|
||||||
|
assert.NoError(t, err, "unable to save threepid association")
|
||||||
|
|
||||||
|
// get the stored threepid
|
||||||
|
gotLocalpart, err := db.GetLocalpartForThreePID(ctx, threePID, medium)
|
||||||
|
assert.NoError(t, err, "unable to get localpart for threepid")
|
||||||
|
assert.Equal(t, aliceLocalpart, gotLocalpart)
|
||||||
|
|
||||||
|
threepids, err := db.GetThreePIDsForLocalpart(ctx, aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to get threepids for localpart")
|
||||||
|
assert.Equal(t, 1, len(threepids))
|
||||||
|
assert.Equal(t, authtypes.ThreePID{
|
||||||
|
Address: threePID,
|
||||||
|
Medium: medium,
|
||||||
|
}, threepids[0])
|
||||||
|
|
||||||
|
// remove threepid association
|
||||||
|
err = db.RemoveThreePIDAssociation(ctx, threePID, medium)
|
||||||
|
assert.NoError(t, err, "unexpected error")
|
||||||
|
|
||||||
|
// verify it was deleted
|
||||||
|
threepids, err = db.GetThreePIDsForLocalpart(ctx, aliceLocalpart)
|
||||||
|
assert.NoError(t, err, "unable to get threepids for localpart")
|
||||||
|
assert.Equal(t, 0, len(threepids))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue