You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-12-19 23:52:43 +02:00
Complated web-api crud endpoints and unittests. unittest for find
endpoints still need to be implemented.
This commit is contained in:
@@ -53,7 +53,7 @@ func (m *UserAccount) Response(ctx context.Context) *UserAccountResponse {
|
||||
UserID: m.UserID,
|
||||
AccountID: m.AccountID,
|
||||
Roles: m.Roles,
|
||||
Status: web.NewEnumResponse(ctx, m.Status, UserAccountRole_Values),
|
||||
Status: web.NewEnumResponse(ctx, m.Status, UserAccountStatus_Values),
|
||||
CreatedAt: web.NewTimeResponse(ctx, m.CreatedAt),
|
||||
UpdatedAt: web.NewTimeResponse(ctx, m.UpdatedAt),
|
||||
}
|
||||
@@ -82,7 +82,7 @@ type UserAccountCreateRequest struct {
|
||||
type UserAccountUpdateRequest struct {
|
||||
UserID string `json:"user_id" validate:"required,uuid" example:"d69bdef7-173f-4d29-b52c-3edc60baf6a2"`
|
||||
AccountID string `json:"account_id" validate:"required,uuid" example:"c4653bf9-5978-48b7-89c5-95704aebb7e2"`
|
||||
Roles *UserAccountRoles `json:"roles,omitempty" validate:"required,dive,oneof=admin user" enums:"admin,user" swaggertype:"array,string" example:"user"`
|
||||
Roles *UserAccountRoles `json:"roles,omitempty" validate:"omitempty,dive,oneof=admin user" enums:"admin,user" swaggertype:"array,string" example:"user"`
|
||||
Status *UserAccountStatus `json:"status,omitempty" validate:"omitempty,oneof=active invited disabled" enums:"active,invited,disabled" swaggertype:"string" example:"disabled"`
|
||||
unArchive bool `json:"-"` // Internal use only.
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ func Read(ctx context.Context, claims auth.Claims, dbConn *sqlx.DB, id string, i
|
||||
|
||||
res, err := find(ctx, claims, dbConn, query, []interface{}{}, includedArchived)
|
||||
if res == nil || len(res) == 0 {
|
||||
err = errors.WithMessagef(ErrNotFound, "account %s not found", id)
|
||||
err = errors.WithMessagef(ErrNotFound, "user account %s not found", id)
|
||||
return nil, err
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -152,9 +152,9 @@ func TestCreateValidation(t *testing.T) {
|
||||
func(req UserAccountCreateRequest, res *UserAccount) *UserAccount {
|
||||
return nil
|
||||
},
|
||||
errors.New("Key: 'UserAccountCreateRequest.UserID' Error:Field validation for 'UserID' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountCreateRequest.AccountID' Error:Field validation for 'AccountID' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountCreateRequest.Roles' Error:Field validation for 'Roles' failed on the 'required' tag"),
|
||||
errors.New("Key: 'UserAccountCreateRequest.user_id' Error:Field validation for 'user_id' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountCreateRequest.account_id' Error:Field validation for 'account_id' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountCreateRequest.roles' Error:Field validation for 'roles' failed on the 'required' tag"),
|
||||
},
|
||||
{"Valid Role",
|
||||
UserAccountCreateRequest{
|
||||
@@ -165,7 +165,7 @@ func TestCreateValidation(t *testing.T) {
|
||||
func(req UserAccountCreateRequest, res *UserAccount) *UserAccount {
|
||||
return nil
|
||||
},
|
||||
errors.New("Key: 'UserAccountCreateRequest.Roles[0]' Error:Field validation for 'Roles[0]' failed on the 'oneof' tag"),
|
||||
errors.New("Key: 'UserAccountCreateRequest.roles[0]' Error:Field validation for 'roles[0]' failed on the 'oneof' tag"),
|
||||
},
|
||||
{"Valid Status",
|
||||
UserAccountCreateRequest{
|
||||
@@ -177,7 +177,7 @@ func TestCreateValidation(t *testing.T) {
|
||||
func(req UserAccountCreateRequest, res *UserAccount) *UserAccount {
|
||||
return nil
|
||||
},
|
||||
errors.New("Key: 'UserAccountCreateRequest.Status' Error:Field validation for 'Status' failed on the 'oneof' tag"),
|
||||
errors.New("Key: 'UserAccountCreateRequest.status' Error:Field validation for 'status' failed on the 'oneof' tag"),
|
||||
},
|
||||
{"Default Status",
|
||||
UserAccountCreateRequest{
|
||||
@@ -373,9 +373,8 @@ func TestUpdateValidation(t *testing.T) {
|
||||
}{
|
||||
{"Required Fields",
|
||||
UserAccountUpdateRequest{},
|
||||
errors.New("Key: 'UserAccountUpdateRequest.UserID' Error:Field validation for 'UserID' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountUpdateRequest.AccountID' Error:Field validation for 'AccountID' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountUpdateRequest.Roles' Error:Field validation for 'Roles' failed on the 'required' tag"),
|
||||
errors.New("Key: 'UserAccountUpdateRequest.user_id' Error:Field validation for 'user_id' failed on the 'required' tag\n" +
|
||||
"Key: 'UserAccountUpdateRequest.account_id' Error:Field validation for 'account_id' failed on the 'required' tag"),
|
||||
},
|
||||
{"Valid Role",
|
||||
UserAccountUpdateRequest{
|
||||
@@ -383,7 +382,7 @@ func TestUpdateValidation(t *testing.T) {
|
||||
AccountID: uuid.NewRandom().String(),
|
||||
Roles: &UserAccountRoles{invalidRole},
|
||||
},
|
||||
errors.New("Key: 'UserAccountUpdateRequest.Roles[0]' Error:Field validation for 'Roles[0]' failed on the 'oneof' tag"),
|
||||
errors.New("Key: 'UserAccountUpdateRequest.roles[0]' Error:Field validation for 'roles[0]' failed on the 'oneof' tag"),
|
||||
},
|
||||
|
||||
{"Valid Status",
|
||||
@@ -393,7 +392,7 @@ func TestUpdateValidation(t *testing.T) {
|
||||
Roles: &UserAccountRoles{UserAccountRole_User},
|
||||
Status: &invalidStatus,
|
||||
},
|
||||
errors.New("Key: 'UserAccountUpdateRequest.Status' Error:Field validation for 'Status' failed on the 'oneof' tag"),
|
||||
errors.New("Key: 'UserAccountUpdateRequest.status' Error:Field validation for 'status' failed on the 'oneof' tag"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user