From b02c6f99acac7aebbcf6801ce21787eb5b66d8ba Mon Sep 17 00:00:00 2001 From: nxshock Date: Mon, 22 Jul 2019 19:31:33 +0500 Subject: [PATCH] Add user ID test --- internal/backends/memory/rooms_test.go | 18 ------------- internal/backends/memory/user_test.go | 37 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 internal/backends/memory/user_test.go diff --git a/internal/backends/memory/rooms_test.go b/internal/backends/memory/rooms_test.go index 0d3543e..ea0029a 100644 --- a/internal/backends/memory/rooms_test.go +++ b/internal/backends/memory/rooms_test.go @@ -1,7 +1,6 @@ package memory import ( - "strings" "testing" "github.com/nxshock/signaller/internal/models/createroom" @@ -9,23 +8,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRegisterUser(t *testing.T) { - backend := NewBackend("localhost") - - var ( - username = "user1" - password = "password1" - device = "device1" - ) - - user, token, err := backend.Register(username, password, device) - assert.Nil(t, err) - assert.Equal(t, username, user.Name()) - assert.Equal(t, password, user.Password()) - assert.NotEmpty(t, token) - assert.True(t, strings.HasSuffix(user.ID(), backend.hostname)) -} - func TestCreateRoom(t *testing.T) { backend := NewBackend("localhost") diff --git a/internal/backends/memory/user_test.go b/internal/backends/memory/user_test.go new file mode 100644 index 0000000..11673fe --- /dev/null +++ b/internal/backends/memory/user_test.go @@ -0,0 +1,37 @@ +package memory + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRegisterUser(t *testing.T) { + backend := NewBackend("localhost") + + var ( + username = "user1" + password = "password1" + device = "device1" + ) + + user, token, err := backend.Register(username, password, device) + assert.Nil(t, err) + assert.Equal(t, username, user.Name()) + assert.Equal(t, password, user.Password()) + assert.NotEmpty(t, token) +} + +func TestUserID(t *testing.T) { + var ( + userName = "user1" + hostName = "localhost" + expectedUserID = "@user1:localhost" + ) + + backend := NewBackend(hostName) + user, _, err := backend.Register(userName, "", "") + assert.Nil(t, err) + + assert.Equal(t, expectedUserID, user.ID()) +}