feat: introduce hanko profile element and related api changes (#495)

* feat: introduce hanko profile element and related api changes
This commit is contained in:
bjoern-m
2023-01-25 10:55:23 +01:00
committed by GitHub
parent 93ad9c4056
commit ca62cf421f
254 changed files with 13765 additions and 3955 deletions

View File

@ -11,7 +11,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
)
@ -21,7 +20,6 @@ func TestUserHandlerAdmin_Delete(t *testing.T) {
users := []models.User{
{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
@ -35,7 +33,7 @@ func TestUserHandlerAdmin_Delete(t *testing.T) {
c.SetParamNames("id")
c.SetParamValues(userId.String())
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
if assert.NoError(t, handler.Delete(c)) {
@ -52,7 +50,7 @@ func TestUserHandlerAdmin_Delete_InvalidUserId(t *testing.T) {
c.SetParamNames("id")
c.SetParamValues("invalidId")
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.Delete(c)
@ -72,7 +70,7 @@ func TestUserHandlerAdmin_Delete_UnknownUserId(t *testing.T) {
c.SetParamNames("id")
c.SetParamValues(userId.String())
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.Delete(c)
@ -82,174 +80,12 @@ func TestUserHandlerAdmin_Delete_UnknownUserId(t *testing.T) {
}
}
func TestUserHandlerAdmin_Patch(t *testing.T) {
userId, _ := uuid.NewV4()
users := []models.User{
{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
}
e := echo.New()
e.Validator = dto.NewCustomValidator()
req := httptest.NewRequest(http.MethodPatch, "/", strings.NewReader(`{"email": "jane.doe@example.com", "verified": true}`))
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/users/:id")
c.SetParamNames("id")
c.SetParamValues(userId.String())
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
if assert.NoError(t, handler.Patch(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
}
}
func TestUserHandlerAdmin_Patch_InvalidUserIdAndEmail(t *testing.T) {
e := echo.New()
e.Validator = dto.NewCustomValidator()
req := httptest.NewRequest(http.MethodPatch, "/", strings.NewReader(`{"email": "invalidEmail"}`))
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/users/:id")
c.SetParamNames("id")
c.SetParamValues("invalidUserId")
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.Patch(c)
if assert.Error(t, err) {
httpError := dto.ToHttpError(err)
assert.Equal(t, http.StatusBadRequest, httpError.Code)
}
}
func TestUserHandlerAdmin_Patch_EmailNotAvailable(t *testing.T) {
users := []models.User{
func() models.User {
userId, _ := uuid.NewV4()
return models.User{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
}(),
func() models.User {
userId, _ := uuid.NewV4()
return models.User{
ID: userId,
Email: "jane.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
}(),
}
e := echo.New()
e.Validator = dto.NewCustomValidator()
req := httptest.NewRequest(http.MethodPatch, "/", strings.NewReader(`{"email": "jane.doe@example.com"}`))
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/users/:id")
c.SetParamNames("id")
c.SetParamValues(users[0].ID.String())
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.Patch(c)
if assert.Error(t, err) {
httpError := dto.ToHttpError(err)
assert.Equal(t, http.StatusBadRequest, httpError.Code)
}
}
func TestUserHandlerAdmin_Patch_UnknownUserId(t *testing.T) {
userId, _ := uuid.NewV4()
users := []models.User{
{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
}
e := echo.New()
e.Validator = dto.NewCustomValidator()
req := httptest.NewRequest(http.MethodPatch, "/", strings.NewReader(`{"email": "jane.doe@example.com", "verified": true}`))
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/users/:id")
c.SetParamNames("id")
unknownUserId, _ := uuid.NewV4()
c.SetParamValues(unknownUserId.String())
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.Patch(c)
if assert.Error(t, err) {
httpError := dto.ToHttpError(err)
assert.Equal(t, http.StatusNotFound, httpError.Code)
}
}
func TestUserHandlerAdmin_Patch_InvalidJson(t *testing.T) {
userId, _ := uuid.NewV4()
users := []models.User{
{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
},
}
e := echo.New()
e.Validator = dto.NewCustomValidator()
req := httptest.NewRequest(http.MethodPatch, "/", strings.NewReader(`"email: "jane.doe@example.com"}`))
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
c.SetPath("/users/:id")
c.SetParamNames("id")
unknownUserId, _ := uuid.NewV4()
c.SetParamValues(unknownUserId.String())
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.Patch(c)
if assert.Error(t, err) {
httpError := dto.ToHttpError(err)
assert.Equal(t, http.StatusBadRequest, httpError.Code)
}
}
func TestUserHandlerAdmin_List(t *testing.T) {
users := []models.User{
func() models.User {
userId, _ := uuid.NewV4()
return models.User{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
@ -258,7 +94,6 @@ func TestUserHandlerAdmin_List(t *testing.T) {
userId, _ := uuid.NewV4()
return models.User{
ID: userId,
Email: "jane.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
@ -271,7 +106,7 @@ func TestUserHandlerAdmin_List(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
if assert.NoError(t, handler.List(c)) {
@ -291,7 +126,6 @@ func TestUserHandlerAdmin_List_Pagination(t *testing.T) {
userId, _ := uuid.NewV4()
return models.User{
ID: userId,
Email: "john.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
@ -300,7 +134,6 @@ func TestUserHandlerAdmin_List_Pagination(t *testing.T) {
userId, _ := uuid.NewV4()
return models.User{
ID: userId,
Email: "jane.doe@example.com",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
@ -316,7 +149,7 @@ func TestUserHandlerAdmin_List_Pagination(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(users, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
if assert.NoError(t, handler.List(c)) {
@ -340,7 +173,7 @@ func TestUserHandlerAdmin_List_NoUsers(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
if assert.NoError(t, handler.List(c)) {
@ -363,7 +196,7 @@ func TestUserHandlerAdmin_List_InvalidPaginationParam(t *testing.T) {
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil)
p := test.NewPersister(nil, nil, nil, nil, nil, nil, nil, nil, nil)
handler := NewUserHandlerAdmin(p)
err := handler.List(c)