fix: lint errors
This commit was merged in pull request #130.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package service
|
||||
package service_test
|
||||
|
||||
import (
|
||||
"spend-sparrow/db"
|
||||
"spend-sparrow/mocks"
|
||||
"spend-sparrow/service"
|
||||
"spend-sparrow/types"
|
||||
|
||||
"strings"
|
||||
@@ -12,6 +13,17 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
settings = types.Settings{
|
||||
Port: "",
|
||||
PrometheusEnabled: false,
|
||||
BaseUrl: "",
|
||||
Environment: "test",
|
||||
Smtp: nil,
|
||||
}
|
||||
)
|
||||
|
||||
func TestSignUp(t *testing.T) {
|
||||
@@ -24,11 +36,11 @@ func TestSignUp(t *testing.T) {
|
||||
mockClock := mocks.NewMockClock(t)
|
||||
mockMail := mocks.NewMockMail(t)
|
||||
|
||||
underTest := NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
||||
underTest := service.NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &settings)
|
||||
|
||||
_, err := underTest.SignUp("invalid email address", "SomeStrongPassword123!")
|
||||
|
||||
assert.Equal(t, ErrInvalidEmail, err)
|
||||
assert.Equal(t, service.ErrInvalidEmail, err)
|
||||
})
|
||||
t.Run("should check for password complexity", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -38,7 +50,7 @@ func TestSignUp(t *testing.T) {
|
||||
mockClock := mocks.NewMockClock(t)
|
||||
mockMail := mocks.NewMockMail(t)
|
||||
|
||||
underTest := NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
||||
underTest := service.NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &settings)
|
||||
|
||||
weakPasswords := []string{
|
||||
"123!ab", // too short
|
||||
@@ -49,7 +61,7 @@ func TestSignUp(t *testing.T) {
|
||||
|
||||
for _, password := range weakPasswords {
|
||||
_, err := underTest.SignUp("some@valid.email", password)
|
||||
assert.Equal(t, ErrInvalidPassword, err)
|
||||
assert.Equal(t, service.ErrInvalidPassword, err)
|
||||
}
|
||||
})
|
||||
t.Run("should signup correctly", func(t *testing.T) {
|
||||
@@ -66,17 +78,17 @@ func TestSignUp(t *testing.T) {
|
||||
salt := []byte("salt")
|
||||
createTime := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
expected := types.NewUser(userId, email, false, nil, false, GetHashPassword(password, salt), salt, createTime)
|
||||
expected := types.NewUser(userId, email, false, nil, false, service.GetHashPassword(password, salt), salt, createTime)
|
||||
|
||||
mockRandom.EXPECT().UUID().Return(userId, nil)
|
||||
mockRandom.EXPECT().Bytes(16).Return(salt, nil)
|
||||
mockClock.EXPECT().Now().Return(createTime)
|
||||
mockAuthDb.EXPECT().InsertUser(expected).Return(nil)
|
||||
|
||||
underTest := NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
||||
underTest := service.NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &settings)
|
||||
actual, err := underTest.SignUp(email, password)
|
||||
|
||||
assert.Nil(t, err)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, expected, actual)
|
||||
})
|
||||
@@ -93,7 +105,7 @@ func TestSignUp(t *testing.T) {
|
||||
createTime := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
password := "SomeStrongPassword123!"
|
||||
salt := []byte("salt")
|
||||
user := types.NewUser(userId, email, false, nil, false, GetHashPassword(password, salt), salt, createTime)
|
||||
user := types.NewUser(userId, email, false, nil, false, service.GetHashPassword(password, salt), salt, createTime)
|
||||
|
||||
mockRandom.EXPECT().UUID().Return(user.Id, nil)
|
||||
mockRandom.EXPECT().Bytes(16).Return(salt, nil)
|
||||
@@ -101,20 +113,25 @@ func TestSignUp(t *testing.T) {
|
||||
|
||||
mockAuthDb.EXPECT().InsertUser(user).Return(db.ErrAlreadyExists)
|
||||
|
||||
underTest := NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
||||
underTest := service.NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &settings)
|
||||
|
||||
_, err := underTest.SignUp(user.Email, password)
|
||||
assert.Equal(t, ErrAccountExists, err)
|
||||
assert.Equal(t, service.ErrAccountExists, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSendVerificationMail(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
t.Run("should use stored token and send mail", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
token := types.NewToken(uuid.New(), "sessionId", "someRandomTokenToUse", types.TokenTypeEmailVerify, time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC))
|
||||
token := types.NewToken(
|
||||
uuid.New(),
|
||||
"sessionId",
|
||||
"someRandomTokenToUse",
|
||||
types.TokenTypeEmailVerify,
|
||||
time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
time.Date(2020, 1, 2, 0, 0, 0, 0, time.UTC))
|
||||
tokens := []*types.Token{token}
|
||||
|
||||
email := "some@email.de"
|
||||
@@ -131,7 +148,7 @@ func TestSendVerificationMail(t *testing.T) {
|
||||
return strings.Contains(message, token.Token)
|
||||
})).Return()
|
||||
|
||||
underTest := NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &types.Settings{})
|
||||
underTest := service.NewAuth(mockAuthDb, mockRandom, mockClock, mockMail, &settings)
|
||||
|
||||
underTest.SendVerificationMail(userId, email)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user