From b7cb0db6c5a2b901cb3762419b60c187350c567a Mon Sep 17 00:00:00 2001 From: nxshock Date: Tue, 23 Jul 2019 20:46:12 +0500 Subject: [PATCH] Add GetUserByToken test --- internal/backends/memory/user_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/backends/memory/user_test.go b/internal/backends/memory/user_test.go index f56251b..adde353 100644 --- a/internal/backends/memory/user_test.go +++ b/internal/backends/memory/user_test.go @@ -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) +}