chore(auth): #331 remove duplicated/outdated tests #347
@@ -5,7 +5,6 @@ import (
|
|||||||
"me-fit/mocks"
|
"me-fit/mocks"
|
||||||
"me-fit/types"
|
"me-fit/types"
|
||||||
|
|
||||||
"errors"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,104 +14,6 @@ import (
|
|||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSignIn(t *testing.T) {
|
|
||||||
|
|
||||||
t.Parallel()
|
|
||||||
t.Run("should return user if password is correct", func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
salt := []byte("salt")
|
|
||||||
verifiedAt := time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
|
||||||
user := types.NewUser(
|
|
||||||
uuid.New(),
|
|
||||||
"test@test.de",
|
|
||||||
true,
|
|
||||||
&verifiedAt,
|
|
||||||
false,
|
|
||||||
GetHashPassword("password", salt),
|
|
||||||
salt,
|
|
||||||
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
||||||
)
|
|
||||||
|
|
||||||
session := types.NewSession("sessionId", user.Id, time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC))
|
|
||||||
|
|
||||||
mockAuthDb := mocks.NewMockAuth(t)
|
|
||||||
mockAuthDb.EXPECT().GetUserByEmail("test@test.de").Return(user, nil)
|
|
||||||
mockAuthDb.EXPECT().DeleteOldSessions(user.Id).Return(nil)
|
|
||||||
mockAuthDb.EXPECT().InsertSession(session).Return(nil)
|
|
||||||
mockRandom := mocks.NewMockRandom(t)
|
|
||||||
mockRandom.EXPECT().String(32).Return("sessionId", nil)
|
|
||||||
mockClock := mocks.NewMockClock(t)
|
|
||||||
mockClock.EXPECT().Now().Return(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
||||||
mockMail := mocks.NewMockMail(t)
|
|
||||||
|
|
||||||
underTest := NewAuthImpl(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
|
||||||
|
|
||||||
actualSession, actualUser, err := underTest.SignIn(nil, user.Email, "password")
|
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
assert.Equal(t, session, actualSession)
|
|
||||||
assert.Equal(t, user, actualUser)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("should return ErrInvalidCretentials if password is not correct", func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
salt := []byte("salt")
|
|
||||||
verifiedAt := time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
|
||||||
|
|
||||||
user := types.NewUser(
|
|
||||||
uuid.New(),
|
|
||||||
"test@test.de",
|
|
||||||
true,
|
|
||||||
&verifiedAt,
|
|
||||||
false,
|
|
||||||
GetHashPassword("password", salt),
|
|
||||||
salt,
|
|
||||||
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
||||||
)
|
|
||||||
|
|
||||||
mockAuthDb := mocks.NewMockAuth(t)
|
|
||||||
mockAuthDb.EXPECT().GetUserByEmail(user.Email).Return(user, nil)
|
|
||||||
mockRandom := mocks.NewMockRandom(t)
|
|
||||||
mockClock := mocks.NewMockClock(t)
|
|
||||||
mockMail := mocks.NewMockMail(t)
|
|
||||||
|
|
||||||
underTest := NewAuthImpl(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
|
||||||
|
|
||||||
_, _, err := underTest.SignIn(nil, "test@test.de", "wrong password")
|
|
||||||
|
|
||||||
assert.Equal(t, ErrInvalidCredentials, err)
|
|
||||||
})
|
|
||||||
t.Run("should return ErrInvalidCretentials if user has not been found", func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
mockAuthDb := mocks.NewMockAuth(t)
|
|
||||||
mockAuthDb.EXPECT().GetUserByEmail("test").Return(nil, db.ErrNotFound)
|
|
||||||
mockRandom := mocks.NewMockRandom(t)
|
|
||||||
mockClock := mocks.NewMockClock(t)
|
|
||||||
mockMail := mocks.NewMockMail(t)
|
|
||||||
|
|
||||||
underTest := NewAuthImpl(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
|
||||||
|
|
||||||
_, _, err := underTest.SignIn(nil, "test", "test")
|
|
||||||
assert.Equal(t, ErrInvalidCredentials, err)
|
|
||||||
})
|
|
||||||
t.Run("should forward ErrInternal on any other error", func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
mockAuthDb := mocks.NewMockAuth(t)
|
|
||||||
mockAuthDb.EXPECT().GetUserByEmail("test").Return(nil, errors.New("Some undefined error"))
|
|
||||||
mockRandom := mocks.NewMockRandom(t)
|
|
||||||
mockClock := mocks.NewMockClock(t)
|
|
||||||
mockMail := mocks.NewMockMail(t)
|
|
||||||
|
|
||||||
underTest := NewAuthImpl(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
|
||||||
|
|
||||||
_, _, err := underTest.SignIn(nil, "test", "test")
|
|
||||||
|
|
||||||
assert.Equal(t, types.ErrInternal, err)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSignUp(t *testing.T) {
|
func TestSignUp(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
t.Run("should check for correct email address", func(t *testing.T) {
|
t.Run("should check for correct email address", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user