You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-06-23 00:37:48 +02:00
fix where, auth use request arg
This commit is contained in:
@ -102,9 +102,13 @@ func TestAccountCRUDAdmin(t *testing.T) {
|
||||
"address1": tr.Account.Address1,
|
||||
"city": tr.Account.City,
|
||||
"status": map[string]interface{}{
|
||||
"value": "active",
|
||||
"title": "Active",
|
||||
"options": []map[string]interface{}{{"selected": false, "title": "[Active Pending Disabled]", "value": "[active pending disabled]"}},
|
||||
"value": "active",
|
||||
"title": "Active",
|
||||
"options": []map[string]interface{}{
|
||||
{"selected": true, "title": "Active", "value": "active"},
|
||||
{"selected": false, "title": "Pending", "value": "pending"},
|
||||
{"selected": false, "title": "Disabled", "value": "disabled"},
|
||||
},
|
||||
},
|
||||
"signup_user_id": &tr.Account.SignupUserID.String,
|
||||
}
|
||||
@ -322,9 +326,13 @@ func TestAccountCRUDUser(t *testing.T) {
|
||||
"address1": tr.Account.Address1,
|
||||
"city": tr.Account.City,
|
||||
"status": map[string]interface{}{
|
||||
"value": "active",
|
||||
"title": "Active",
|
||||
"options": []map[string]interface{}{{"selected": false, "title": "[Active Pending Disabled]", "value": "[active pending disabled]"}},
|
||||
"value": "active",
|
||||
"title": "Active",
|
||||
"options": []map[string]interface{}{
|
||||
{"selected": true, "title": "Active", "value": "active"},
|
||||
{"selected": false, "title": "Pending", "value": "pending"},
|
||||
{"selected": false, "title": "Disabled", "value": "disabled"},
|
||||
},
|
||||
},
|
||||
"signup_user_id": &tr.Account.SignupUserID.String,
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func TestProjectCRUDAdmin(t *testing.T) {
|
||||
"updated_at": web.NewTimeResponse(ctx, actual.UpdatedAt.Value),
|
||||
"id": actual.ID,
|
||||
"account_id": req.AccountID,
|
||||
"status": web.NewEnumResponse(ctx, "active", project.ProjectStatus_Values),
|
||||
"status": web.NewEnumResponse(ctx, "active", project.ProjectStatus_ValuesInterface()...),
|
||||
"created_at": web.NewTimeResponse(ctx, actual.CreatedAt.Value),
|
||||
"name": req.Name,
|
||||
}
|
||||
|
@ -56,7 +56,10 @@ func newMockSignup() mockSignup {
|
||||
}
|
||||
|
||||
expires := time.Now().UTC().Sub(s.User.CreatedAt) + time.Hour
|
||||
tkn, err := user_auth.Authenticate(tests.Context(), test.MasterDB, authenticator, req.User.Email, req.User.Password, expires, now)
|
||||
tkn, err := user_auth.Authenticate(tests.Context(), test.MasterDB, authenticator, user_auth.AuthenticateRequest{
|
||||
Email: req.User.Email,
|
||||
Password: req.User.Password,
|
||||
}, expires, now)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -139,9 +142,13 @@ func TestSignup(t *testing.T) {
|
||||
"address1": req.Account.Address1,
|
||||
"city": req.Account.City,
|
||||
"status": map[string]interface{}{
|
||||
"value": "active",
|
||||
"title": "Active",
|
||||
"options": []map[string]interface{}{{"selected": false, "title": "[Active Pending Disabled]", "value": "[active pending disabled]"}},
|
||||
"value": "active",
|
||||
"title": "Active",
|
||||
"options": []map[string]interface{}{
|
||||
{"selected": true, "title": "Active", "value": "active"},
|
||||
{"selected": false, "title": "Pending", "value": "pending"},
|
||||
{"selected": false, "title": "Disabled", "value": "disabled"},
|
||||
},
|
||||
},
|
||||
"signup_user_id": &actual.Account.SignupUserID,
|
||||
},
|
||||
|
@ -95,7 +95,10 @@ func testMain(m *testing.M) int {
|
||||
}
|
||||
|
||||
expires := time.Now().UTC().Sub(signup1.User.CreatedAt) + time.Hour
|
||||
adminTkn, err := user_auth.Authenticate(tests.Context(), test.MasterDB, authenticator, signupReq1.User.Email, signupReq1.User.Password, expires, now)
|
||||
adminTkn, err := user_auth.Authenticate(tests.Context(), test.MasterDB, authenticator, user_auth.AuthenticateRequest{
|
||||
Email: signupReq1.User.Email,
|
||||
Password: signupReq1.User.Password,
|
||||
}, expires, now)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -146,7 +149,10 @@ func testMain(m *testing.M) int {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
userTkn, err := user_auth.Authenticate(tests.Context(), test.MasterDB, authenticator, usr.Email, userReq.Password, expires, now)
|
||||
userTkn, err := user_auth.Authenticate(tests.Context(), test.MasterDB, authenticator, user_auth.AuthenticateRequest{
|
||||
Email: usr.Email,
|
||||
Password: userReq.Password,
|
||||
}, expires, now)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -89,13 +89,18 @@ func TestUserAccountCRUDAdmin(t *testing.T) {
|
||||
}
|
||||
created = actual
|
||||
|
||||
var roles []interface{}
|
||||
for _, r := range req.Roles {
|
||||
roles = append(roles, r)
|
||||
}
|
||||
|
||||
expectedMap := map[string]interface{}{
|
||||
"updated_at": web.NewTimeResponse(ctx, actual.UpdatedAt.Value),
|
||||
//"id": actual.ID,
|
||||
"account_id": req.AccountID,
|
||||
"user_id": req.UserID,
|
||||
"status": web.NewEnumResponse(ctx, "active", user_account.UserAccountStatus_Values),
|
||||
"roles": req.Roles,
|
||||
"status": web.NewEnumResponse(ctx, "active", user_account.UserAccountStatus_ValuesInterface()...),
|
||||
"roles": web.NewEnumMultiResponse(ctx, roles, user_account.UserAccountRole_ValuesInterface()...),
|
||||
"created_at": web.NewTimeResponse(ctx, actual.CreatedAt.Value),
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1419,7 @@ func TestUserToken(t *testing.T) {
|
||||
|
||||
// Test user token with invalid email.
|
||||
{
|
||||
expectedStatus := http.StatusUnauthorized
|
||||
expectedStatus := http.StatusBadRequest
|
||||
|
||||
rt := requestTest{
|
||||
fmt.Sprintf("Token %d using invalid email", expectedStatus),
|
||||
@ -1434,7 +1434,9 @@ func TestUserToken(t *testing.T) {
|
||||
t.Logf("\tTest: %s - %s %s", rt.name, rt.method, rt.url)
|
||||
|
||||
r := httptest.NewRequest(rt.method, rt.url, nil)
|
||||
r.SetBasicAuth("invalid email.com", "some random password")
|
||||
|
||||
invalidEmail := "invalid email.com"
|
||||
r.SetBasicAuth(invalidEmail, "some random password")
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
r.Header.Set("Content-Type", web.MIMEApplicationJSONCharsetUTF8)
|
||||
@ -1456,8 +1458,17 @@ func TestUserToken(t *testing.T) {
|
||||
|
||||
expected := weberror.ErrorResponse{
|
||||
StatusCode: expectedStatus,
|
||||
Error: http.StatusText(expectedStatus),
|
||||
Details: user_auth.ErrAuthenticationFailure.Error(),
|
||||
Error: "Field validation error",
|
||||
Fields: []weberror.FieldError{
|
||||
{
|
||||
Field: "email",
|
||||
Value: invalidEmail,
|
||||
Tag: "email",
|
||||
Error: "email must be a valid email address",
|
||||
Display: "email must be a valid email address",
|
||||
},
|
||||
},
|
||||
Details: actual.Details,
|
||||
StackTrace: actual.StackTrace,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user