Add GetUserByToken test

This commit is contained in:
nxshock 2019-07-23 20:46:12 +05:00
parent 1dbc5082a9
commit b7cb0db6c5

View File

@ -58,3 +58,25 @@ func TestUserMessageInWrongRoom(t *testing.T) {
err = user2.SendMessage(room, "hello")
assert.NotNil(t, err)
}
func TestGetUserByToken(t *testing.T) {
backend := NewBackend("localhost")
user, token, err := backend.Register("user1", "", "")
assert.Nil(t, err)
assert.NotEmpty(t, token)
gotUser := backend.GetUserByToken(token)
assert.Equal(t, user, gotUser)
}
func TestGetUserByWrongToken(t *testing.T) {
backend := NewBackend("localhost")
_, token, err := backend.Register("user1", "", "")
assert.Nil(t, err)
assert.NotEmpty(t, token)
gotUser := backend.GetUserByToken("wrong token")
assert.Nil(t, gotUser)
}