fix: migrate sigin to testable code #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 50s
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 50s
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user