fix: use testify for assertions #181

This commit is contained in:
2024-10-05 12:58:34 +02:00
parent 5b4160b09f
commit d36f880a01

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestSignIn(t *testing.T) {
@@ -35,18 +36,15 @@ func TestSignIn(t *testing.T) {
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
actualUser, err := underTest.SignIn(user.Email, "password")
if err != nil {
t.Errorf("Expected nil, got %v", err)
}
assert.Nil(t, err)
expectedUser := User{
Id: user.Id,
Email: user.Email,
EmailVerified: user.EmailVerified,
}
if *actualUser != expectedUser {
t.Errorf("Expected %v, got %v", expectedUser, actualUser)
}
assert.Equal(t, expectedUser, *actualUser)
})
t.Run("should return ErrInvalidCretentials if password is not correct", func(t *testing.T) {
@@ -71,9 +69,8 @@ func TestSignIn(t *testing.T) {
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
_, err := underTest.SignIn("test@test.de", "wrong password")
if err != ErrInvaidCredentials {
t.Errorf("Expected %v, got %v", ErrInvaidCredentials, err)
}
assert.Equal(t, ErrInvaidCredentials, err)
})
t.Run("should return ErrInvalidCretentials if user has not been found", func(t *testing.T) {
t.Parallel()
@@ -84,21 +81,18 @@ func TestSignIn(t *testing.T) {
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
_, err := underTest.SignIn("test", "test")
if err != ErrInvaidCredentials {
t.Errorf("Expected %v, got %v", ErrInvaidCredentials, err)
}
assert.Equal(t, ErrInvaidCredentials, err)
})
t.Run("should forward ErrInternal on any other error", func(t *testing.T) {
t.Parallel()
mockDbAuth := mocks.NewMockDbAuth(t)
mockDbAuth.EXPECT().GetUser("test").Return(nil, errors.New("Some error"))
mockDbAuth.EXPECT().GetUser("test").Return(nil, errors.New("Some undefined error"))
underTest := NewServiceAuthImpl(mockDbAuth, &types.ServerSettings{})
_, err := underTest.SignIn("test", "test")
if err != types.ErrInternal {
t.Errorf("Expected %v, got %v", types.ErrInternal, err)
}
assert.Equal(t, types.ErrInternal, err)
})
}