fix: migrate sigin to testable code #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 50s

This commit is contained in:
2024-10-04 23:25:57 +02:00
parent cbf5b39294
commit 2ff6f92235
6 changed files with 256 additions and 127 deletions

View File

@@ -19,6 +19,15 @@ type DbAuthStub struct {
func (d DbAuthStub) GetUser(email string) (*db.User, error) {
return d.user, d.err
}
func (d DbAuthStub) InsertUser(user *db.User) error {
return nil
}
func (d DbAuthStub) GetEmailVerificationToken(userId uuid.UUID) (string, error) {
return "", nil
}
func (d DbAuthStub) InsertEmailVerificationToken(userId uuid.UUID, token string) error {
return nil
}
func TestSignIn(t *testing.T) {
t.Parallel()
@@ -39,7 +48,7 @@ func TestSignIn(t *testing.T) {
),
err: nil,
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(nil, stub, &types.ServerSettings{})
actualUser, err := underTest.SignIn("test@test.de", "password")
if err != nil {
@@ -73,7 +82,7 @@ func TestSignIn(t *testing.T) {
),
err: nil,
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(nil, stub, &types.ServerSettings{})
_, err := underTest.SignIn("test@test.de", "wrong password")
if err != ErrInvaidCredentials {
@@ -86,7 +95,7 @@ func TestSignIn(t *testing.T) {
user: nil,
err: db.ErrUserNotFound,
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(nil, stub, &types.ServerSettings{})
_, err := underTest.SignIn("test", "test")
if err != ErrInvaidCredentials {
@@ -99,7 +108,7 @@ func TestSignIn(t *testing.T) {
user: nil,
err: errors.New("Some error"),
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(nil, stub, &types.ServerSettings{})
_, err := underTest.SignIn("test", "test")
if err != types.ErrInternal {