fix: migrate sigin to testable code #181
This commit is contained in:
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"me-fit/db"
|
||||
m "me-fit/mocks"
|
||||
"me-fit/mocks"
|
||||
"me-fit/types"
|
||||
|
||||
"errors"
|
||||
@@ -18,7 +18,6 @@ func TestSignIn(t *testing.T) {
|
||||
t.Parallel()
|
||||
salt := []byte("salt")
|
||||
verifiedAt := time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
user := db.NewUser(
|
||||
uuid.New(),
|
||||
"test@test.de",
|
||||
@@ -30,10 +29,10 @@ func TestSignIn(t *testing.T) {
|
||||
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
)
|
||||
|
||||
mockDbAuth := m.NewMockDbAuth(t)
|
||||
mockDbAuth := mocks.NewMockDbAuth(t)
|
||||
mockDbAuth.EXPECT().GetUser("test@test.de").Return(user, nil)
|
||||
|
||||
underTest := NewServiceAuthImpl(mockDbAuth)
|
||||
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
|
||||
|
||||
actualUser, err := underTest.SignIn(user.Email, "password")
|
||||
if err != nil {
|
||||
@@ -54,6 +53,7 @@ func TestSignIn(t *testing.T) {
|
||||
t.Parallel()
|
||||
salt := []byte("salt")
|
||||
verifiedAt := time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
user := db.NewUser(
|
||||
uuid.New(),
|
||||
"test@test.de",
|
||||
@@ -65,10 +65,10 @@ func TestSignIn(t *testing.T) {
|
||||
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
)
|
||||
|
||||
mockDbAuth := m.NewMockDbAuth(t)
|
||||
mockDbAuth := mocks.NewMockDbAuth(t)
|
||||
mockDbAuth.EXPECT().GetUser(user.Email).Return(user, nil)
|
||||
|
||||
underTest := NewServiceAuthImpl(mockDbAuth)
|
||||
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
|
||||
|
||||
_, err := underTest.SignIn("test@test.de", "wrong password")
|
||||
if err != ErrInvaidCredentials {
|
||||
@@ -77,10 +77,11 @@ func TestSignIn(t *testing.T) {
|
||||
})
|
||||
t.Run("should return ErrInvalidCretentials if user has not been found", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
mockDbAuth := m.NewMockDbAuth(t)
|
||||
|
||||
mockDbAuth := mocks.NewMockDbAuth(t)
|
||||
mockDbAuth.EXPECT().GetUser("test").Return(nil, db.ErrUserNotFound)
|
||||
|
||||
underTest := NewServiceAuthImpl(mockDbAuth)
|
||||
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
|
||||
|
||||
_, err := underTest.SignIn("test", "test")
|
||||
if err != ErrInvaidCredentials {
|
||||
@@ -89,10 +90,11 @@ func TestSignIn(t *testing.T) {
|
||||
})
|
||||
t.Run("should forward ErrInternal on any other error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
mockDbAuth := m.NewMockDbAuth(t)
|
||||
|
||||
mockDbAuth := mocks.NewMockDbAuth(t)
|
||||
mockDbAuth.EXPECT().GetUser("test").Return(nil, errors.New("Some error"))
|
||||
|
||||
underTest := NewServiceAuthImpl(mockDbAuth)
|
||||
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
|
||||
|
||||
_, err := underTest.SignIn("test", "test")
|
||||
if err != types.ErrInternal {
|
||||
|
||||
Reference in New Issue
Block a user