From 7a7d7cf20454b16b82954f39db460ff103ed4cb6 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Mon, 23 Dec 2024 22:36:55 +0100 Subject: [PATCH] chore(auth): #331 remove duplicated/outdated tests --- service/auth_test.go | 99 -------------------------------------------- 1 file changed, 99 deletions(-) diff --git a/service/auth_test.go b/service/auth_test.go index f12789d..ab8db76 100644 --- a/service/auth_test.go +++ b/service/auth_test.go @@ -5,7 +5,6 @@ import ( "me-fit/mocks" "me-fit/types" - "errors" "strings" "testing" "time" @@ -15,104 +14,6 @@ import ( "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) { t.Parallel() t.Run("should check for correct email address", func(t *testing.T) {