This commit is contained in:
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"me-fit/types"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -29,17 +30,7 @@ func setupDb(t *testing.T) *sql.DB {
|
||||
func TestUser(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("should return UserNotFound", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := setupDb(t)
|
||||
|
||||
underTest := AuthSqlite{db: db}
|
||||
|
||||
_, err := underTest.GetUserByEmail("someNonExistentEmail")
|
||||
assert.Equal(t, ErrNotFound, err)
|
||||
})
|
||||
|
||||
t.Run("should insert and get user", func(t *testing.T) {
|
||||
t.Run("should insert and get the same", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := setupDb(t)
|
||||
|
||||
@@ -52,13 +43,24 @@ func TestUser(t *testing.T) {
|
||||
err := underTest.InsertUser(expected)
|
||||
assert.Nil(t, err)
|
||||
|
||||
actual, err := underTest.GetUserByEmail(expected.Email)
|
||||
actual, err := underTest.GetUser(expected.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
actual, err = underTest.GetUserByEmail(expected.Email)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expected, actual)
|
||||
})
|
||||
t.Run("should return UserNotFound", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := setupDb(t)
|
||||
|
||||
t.Run("should throw error if user already exists", func(t *testing.T) {
|
||||
underTest := AuthSqlite{db: db}
|
||||
|
||||
_, err := underTest.GetUserByEmail("nonExistentEmail")
|
||||
assert.Equal(t, ErrNotFound, err)
|
||||
})
|
||||
t.Run("should return ErrUserExist", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := setupDb(t)
|
||||
|
||||
@@ -74,6 +76,18 @@ func TestUser(t *testing.T) {
|
||||
err = underTest.InsertUser(user)
|
||||
assert.Equal(t, ErrUserExists, err)
|
||||
})
|
||||
t.Run("should return ErrInternal on missing NOT NULL fields", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
db := setupDb(t)
|
||||
|
||||
underTest := AuthSqlite{db: db}
|
||||
|
||||
createAt := time.Date(2020, 1, 5, 12, 0, 0, 0, time.UTC)
|
||||
user := NewUser(uuid.New(), "some@email.de", false, nil, false, []byte("somePass"), nil, createAt)
|
||||
|
||||
err := underTest.InsertUser(user)
|
||||
assert.Equal(t, types.ErrInternal, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestEmailVerification(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user