wip
This commit is contained in:
@@ -89,9 +89,7 @@ func (cr *CarController) GetAll(c *gin.Context) {
|
||||
|
||||
func (cr *CarController) Delete(c *gin.Context) {
|
||||
type input struct {
|
||||
Car struct {
|
||||
ID uint `json:"id" binding:"required,numeric"`
|
||||
} `json:"car"`
|
||||
ID uint `json:"id" binding:"required,numeric"`
|
||||
}
|
||||
var deleteData input
|
||||
requestUser, err := cr.UserService.FromContext(c)
|
||||
@@ -109,7 +107,7 @@ func (cr *CarController) Delete(c *gin.Context) {
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
}
|
||||
err = cr.S.Delete(&deleteData.Car.ID)
|
||||
err = cr.S.Delete(&deleteData.ID)
|
||||
if err != nil {
|
||||
utils.RespondWithError(c, err, "Error deleting car", http.StatusInternalServerError, errors.Responses.Fields.Car, errors.Responses.Keys.InternalServerError)
|
||||
return
|
||||
|
||||
@@ -100,7 +100,7 @@ func TestMain(t *testing.T) {
|
||||
bankAccountService := &services.BankAccountService{Repo: bankAccountRepo}
|
||||
|
||||
var membershipRepo repositories.MembershipRepositoryInterface = &repositories.MembershipRepository{}
|
||||
var subscriptionRepo repositories.SubscriptionModelsRepositoryInterface = &repositories.SubscriptionModelsRepository{}
|
||||
var subscriptionRepo repositories.SubscriptionsRepositoryInterface = &repositories.SubscriptionsRepository{}
|
||||
membershipService := &services.MembershipService{Repo: membershipRepo, SubscriptionRepo: subscriptionRepo}
|
||||
|
||||
var licenceRepo repositories.LicenceInterface = &repositories.LicenceRepository{}
|
||||
@@ -119,6 +119,7 @@ func TestMain(t *testing.T) {
|
||||
if err := initLicenceCategories(); err != nil {
|
||||
log.Fatalf("Failed to init Categories: %v", err)
|
||||
}
|
||||
password := "securepassword"
|
||||
admin := models.User{
|
||||
FirstName: "Ad",
|
||||
LastName: "min",
|
||||
@@ -130,7 +131,7 @@ func TestMain(t *testing.T) {
|
||||
ZipCode: "12345",
|
||||
City: "SampleCity",
|
||||
Status: constants.ActiveStatus,
|
||||
Password: "",
|
||||
Password: password,
|
||||
Notes: "",
|
||||
RoleID: constants.Roles.Admin,
|
||||
Consents: nil,
|
||||
@@ -140,7 +141,6 @@ func TestMain(t *testing.T) {
|
||||
Licence: &models.Licence{
|
||||
Status: constants.UnverifiedStatus,
|
||||
}}
|
||||
admin.SetPassword("securepassword")
|
||||
admin.Create(db)
|
||||
validation.SetupValidators(db)
|
||||
t.Run("userController", func(t *testing.T) {
|
||||
@@ -203,7 +203,7 @@ func initLicenceCategories() error {
|
||||
}
|
||||
|
||||
func initSubscriptionPlans() error {
|
||||
subscriptions := []models.SubscriptionModel{
|
||||
subscriptions := []models.Subscription{
|
||||
{
|
||||
Name: "Basic",
|
||||
Details: "Test Plan",
|
||||
@@ -284,7 +284,7 @@ func getBaseUser() models.User {
|
||||
City: "Hasloh",
|
||||
Phone: "01738484993",
|
||||
BankAccount: &models.BankAccount{IBAN: "DE89370400440532013000"},
|
||||
Membership: &models.Membership{SubscriptionModel: models.SubscriptionModel{Name: "Basic"}},
|
||||
Membership: &models.Membership{Subscription: models.Subscription{Name: "Basic"}},
|
||||
Licence: nil,
|
||||
Password: "passw@#$#%$!-ord123",
|
||||
Company: "",
|
||||
@@ -303,7 +303,7 @@ func getBaseSupporter() models.User {
|
||||
City: "Hasloh",
|
||||
Phone: "01738484993",
|
||||
BankAccount: &models.BankAccount{IBAN: "DE89370400440532013000"},
|
||||
Membership: &models.Membership{SubscriptionModel: models.SubscriptionModel{Name: "Basic"}},
|
||||
Membership: &models.Membership{Subscription: models.Subscription{Name: "Basic"}},
|
||||
Licence: nil,
|
||||
Password: "passw@#$#%$!-ord123",
|
||||
Company: "",
|
||||
|
||||
@@ -33,7 +33,7 @@ func (mc *MembershipController) RegisterSubscription(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var subscription models.SubscriptionModel
|
||||
var subscription models.Subscription
|
||||
if err := c.ShouldBindJSON(&subscription); err != nil {
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
@@ -43,9 +43,9 @@ func (mc *MembershipController) RegisterSubscription(c *gin.Context) {
|
||||
id, err := mc.Service.RegisterSubscription(&subscription)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
|
||||
utils.RespondWithError(c, err, "Subscription already exists", http.StatusConflict, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.Duplicate)
|
||||
utils.RespondWithError(c, err, "Subscription already exists", http.StatusConflict, errors.Responses.Fields.Subscription, errors.Responses.Keys.Duplicate)
|
||||
} else {
|
||||
utils.RespondWithError(c, err, "Couldn't register Membershipmodel", http.StatusInternalServerError, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.InternalServerError)
|
||||
utils.RespondWithError(c, err, "Couldn't register Membershipmodel", http.StatusInternalServerError, errors.Responses.Fields.Subscription, errors.Responses.Keys.InternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func (mc *MembershipController) UpdateHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var subscription models.SubscriptionModel
|
||||
var subscription models.Subscription
|
||||
if err := c.ShouldBindJSON(&subscription); err != nil {
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
@@ -122,7 +122,7 @@ func (mc *MembershipController) DeleteSubscription(c *gin.Context) {
|
||||
func (mc *MembershipController) GetSubscriptions(c *gin.Context) {
|
||||
subscriptions, err := mc.Service.GetSubscriptions(nil)
|
||||
if err != nil {
|
||||
utils.RespondWithError(c, err, "Error retrieving subscriptions", http.StatusInternalServerError, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.InternalServerError)
|
||||
utils.RespondWithError(c, err, "Error retrieving subscriptions", http.StatusInternalServerError, errors.Responses.Fields.Subscription, errors.Responses.Keys.InternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,8 @@ func (dt *DeleteSubscriptionTest) ValidateResult() error {
|
||||
return validateSubscription(dt.Assert, dt.WantDBData)
|
||||
}
|
||||
|
||||
func getBaseSubscription() models.SubscriptionModel {
|
||||
return models.SubscriptionModel{
|
||||
func getBaseSubscription() models.Subscription {
|
||||
return models.Subscription{
|
||||
Name: "Premium",
|
||||
Details: "A subscription detail",
|
||||
MonthlyFee: 12.0,
|
||||
@@ -157,7 +157,7 @@ func getBaseSubscription() models.SubscriptionModel {
|
||||
}
|
||||
}
|
||||
|
||||
func customizeSubscription(customize func(models.SubscriptionModel) models.SubscriptionModel) models.SubscriptionModel {
|
||||
func customizeSubscription(customize func(models.Subscription) models.Subscription) models.Subscription {
|
||||
subscription := getBaseSubscription()
|
||||
return customize(subscription)
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func getSubscriptionRegistrationData() []RegisterSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Just a Subscription"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Details = ""
|
||||
return subscription
|
||||
})),
|
||||
@@ -187,7 +187,7 @@ func getSubscriptionRegistrationData() []RegisterSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": ""},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = ""
|
||||
return subscription
|
||||
})),
|
||||
@@ -200,7 +200,7 @@ func getSubscriptionRegistrationData() []RegisterSubscriptionTest {
|
||||
WantResponse: http.StatusBadRequest,
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(customizeSubscription(func(sub models.SubscriptionModel) models.SubscriptionModel {
|
||||
Input: GenerateInputJSON(customizeSubscription(func(sub models.Subscription) models.Subscription {
|
||||
sub.MonthlyFee = -10.0
|
||||
return sub
|
||||
})),
|
||||
@@ -213,7 +213,7 @@ func getSubscriptionRegistrationData() []RegisterSubscriptionTest {
|
||||
WantResponse: http.StatusBadRequest,
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(customizeSubscription(func(sub models.SubscriptionModel) models.SubscriptionModel {
|
||||
Input: GenerateInputJSON(customizeSubscription(func(sub models.Subscription) models.Subscription {
|
||||
sub.HourlyRate = -1.0
|
||||
return sub
|
||||
})),
|
||||
@@ -227,7 +227,7 @@ func getSubscriptionRegistrationData() []RegisterSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Conditions = "Some Condition"
|
||||
subscription.IncludedPerYear = 0
|
||||
subscription.IncludedPerMonth = 1
|
||||
@@ -243,7 +243,7 @@ func getSubscriptionRegistrationData() []RegisterSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Conditions = "Some Condition"
|
||||
subscription.IncludedPerYear = 0
|
||||
subscription.IncludedPerMonth = 1
|
||||
@@ -274,7 +274,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium", "monthly_fee": "12"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.MonthlyFee = 123.0
|
||||
return subscription
|
||||
})),
|
||||
@@ -288,7 +288,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.ID = 0
|
||||
return subscription
|
||||
})),
|
||||
@@ -302,7 +302,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium", "hourly_rate": "14"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.HourlyRate = 3254.0
|
||||
return subscription
|
||||
})),
|
||||
@@ -316,7 +316,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium", "included_per_year": "0"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.IncludedPerYear = 9873.0
|
||||
return subscription
|
||||
})),
|
||||
@@ -330,7 +330,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium", "included_per_month": "1"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.IncludedPerMonth = 23415.0
|
||||
return subscription
|
||||
})),
|
||||
@@ -344,7 +344,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "NonExistentSubscription"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = "NonExistentSubscription"
|
||||
return subscription
|
||||
})),
|
||||
@@ -358,7 +358,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium", "details": "Altered Details"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Details = "Altered Details"
|
||||
subscription.Conditions = "Some Condition"
|
||||
subscription.IncludedPerYear = 0
|
||||
@@ -375,7 +375,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium", "details": "Altered Details"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Details = "Altered Details"
|
||||
subscription.Conditions = "Some Condition"
|
||||
subscription.IncludedPerYear = 0
|
||||
@@ -388,7 +388,7 @@ func getSubscriptionUpdateData() []UpdateSubscriptionTest {
|
||||
|
||||
func getSubscriptionDeleteData() []DeleteSubscriptionTest {
|
||||
|
||||
var premiumSub, basicSub models.SubscriptionModel
|
||||
var premiumSub, basicSub models.Subscription
|
||||
database.DB.Where("name = ?", "Premium").First(&premiumSub)
|
||||
database.DB.Where("name = ?", "Basic").First(&basicSub)
|
||||
|
||||
@@ -402,7 +402,7 @@ func getSubscriptionDeleteData() []DeleteSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "NonExistentSubscription"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = "NonExistentSubscription"
|
||||
subscription.ID = basicSub.ID
|
||||
logger.Error.Printf("subscription to delete: %#v", subscription)
|
||||
@@ -418,7 +418,7 @@ func getSubscriptionDeleteData() []DeleteSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": ""},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = ""
|
||||
subscription.ID = basicSub.ID
|
||||
return subscription
|
||||
@@ -433,7 +433,7 @@ func getSubscriptionDeleteData() []DeleteSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Basic"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = "Basic"
|
||||
subscription.ID = basicSub.ID
|
||||
return subscription
|
||||
@@ -448,7 +448,7 @@ func getSubscriptionDeleteData() []DeleteSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: true,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = "Premium"
|
||||
subscription.ID = premiumSub.ID
|
||||
return subscription
|
||||
@@ -463,7 +463,7 @@ func getSubscriptionDeleteData() []DeleteSubscriptionTest {
|
||||
WantDBData: map[string]interface{}{"name": "Premium"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(
|
||||
customizeSubscription(func(subscription models.SubscriptionModel) models.SubscriptionModel {
|
||||
customizeSubscription(func(subscription models.Subscription) models.Subscription {
|
||||
subscription.Name = "Premium"
|
||||
subscription.ID = premiumSub.ID
|
||||
return subscription
|
||||
|
||||
@@ -132,9 +132,9 @@ func (uc *UserController) ChangePassword(c *gin.Context) {
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !user.Verify(input.Token, constants.VerificationTypes.Password) {
|
||||
utils.RespondWithError(c, errors.ErrAlreadyVerified, "Couldn't verify user", http.StatusInternalServerError, errors.Responses.Fields.General, errors.Responses.Keys.InternalServerError)
|
||||
err = user.Verify(input.Token, constants.VerificationTypes.Password)
|
||||
if err != nil {
|
||||
utils.RespondWithError(c, err, "Couldn't verify user", http.StatusInternalServerError, errors.Responses.Fields.General, errors.Responses.Keys.InternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ func setupTestContext() (*TestContext, error) {
|
||||
logger.Error.Printf("error fetching user: %#v", err)
|
||||
return nil, err
|
||||
}
|
||||
logger.Error.Printf("found user: %#v", user)
|
||||
return &TestContext{
|
||||
router: gin.Default(),
|
||||
response: httptest.NewRecorder(),
|
||||
@@ -104,7 +103,6 @@ func testChangePassword(t *testing.T, tc *TestContext) {
|
||||
var verification models.Verification
|
||||
result := database.DB.Where("user_id = ? AND type = ?", tc.user.ID, constants.VerificationTypes.Password).First(&verification)
|
||||
assert.NoError(t, result.Error)
|
||||
logger.Error.Printf("token from db: %#v", verification.VerificationToken)
|
||||
requestBody := map[string]interface{}{
|
||||
"password": "new-pas9247A@!sword",
|
||||
"token": verification.VerificationToken,
|
||||
|
||||
@@ -89,6 +89,10 @@ func (uc *UserController) UpdateHandler(c *gin.Context) {
|
||||
|
||||
var updateData RegistrationData
|
||||
if err := c.ShouldBindJSON(&updateData); err != nil {
|
||||
if updateData.User.Password != "" {
|
||||
|
||||
logger.Error.Printf("u.password: %#v", updateData.User.Password)
|
||||
}
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
}
|
||||
@@ -240,12 +244,12 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
|
||||
}
|
||||
|
||||
logger.Info.Printf("Registering user %v", regData.User.Email)
|
||||
selectedModel, err := uc.MembershipService.GetSubscriptionByName(®Data.User.Membership.SubscriptionModel.Name)
|
||||
selectedModel, err := uc.MembershipService.GetSubscriptionByName(®Data.User.Membership.Subscription.Name)
|
||||
if err != nil {
|
||||
utils.RespondWithError(c, err, "Error in Registeruser, couldn't get selected model", http.StatusNotFound, errors.Responses.Fields.SubscriptionModel, errors.Responses.Keys.InvalidSubscriptionModel)
|
||||
utils.RespondWithError(c, err, "Error in Registeruser, couldn't get selected model", http.StatusNotFound, errors.Responses.Fields.Subscription, errors.Responses.Keys.InvalidSubscription)
|
||||
return
|
||||
}
|
||||
regData.User.Membership.SubscriptionModel = *selectedModel
|
||||
regData.User.Membership.Subscription = *selectedModel
|
||||
// Get Gin's binding validator engine with all registered validators
|
||||
validate := binding.Validator.Engine().(*validator.Validate)
|
||||
|
||||
@@ -254,7 +258,7 @@ func (uc *UserController) RegisterUser(c *gin.Context) {
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
}
|
||||
if regData.User.Membership.SubscriptionModel.Name == constants.SupporterSubscriptionModelName {
|
||||
if regData.User.Membership.Subscription.Name == constants.SupporterSubscriptionName {
|
||||
regData.User.RoleID = constants.Roles.Supporter
|
||||
} else {
|
||||
regData.User.RoleID = constants.Roles.Member
|
||||
@@ -347,7 +351,8 @@ func (uc *UserController) VerifyMailHandler(c *gin.Context) {
|
||||
c.HTML(http.StatusBadRequest, "verification_error.html", gin.H{"ErrorMessage": "Couldn't find user"})
|
||||
return
|
||||
}
|
||||
if !user.Verify(token, constants.VerificationTypes.Email) {
|
||||
err = user.Verify(token, constants.VerificationTypes.Email)
|
||||
if err != nil {
|
||||
logger.Error.Printf("Couldn't find user verification in verifyMailHandler: %v", err)
|
||||
c.HTML(http.StatusBadRequest, "verification_error.html", gin.H{"ErrorMessage": "Couldn't find user verification request"})
|
||||
return
|
||||
|
||||
@@ -351,8 +351,8 @@ func testCurrentUserHandler(t *testing.T, loginEmail string) http.Cookie {
|
||||
|
||||
if tt.expectedStatus == http.StatusOK {
|
||||
var response struct {
|
||||
User models.User `json:"user"`
|
||||
Subscriptions []models.SubscriptionModel `json:"subscriptions"`
|
||||
User models.User `json:"user"`
|
||||
Subscriptions []models.Subscription `json:"subscriptions"`
|
||||
}
|
||||
err := json.Unmarshal(w.Body.Bytes(), &response)
|
||||
assert.NoError(t, err)
|
||||
@@ -407,12 +407,15 @@ func validateUser(assert bool, wantDBData map[string]interface{}) error {
|
||||
if assert {
|
||||
user := (*users)[0]
|
||||
// Check for mandate reference
|
||||
if user.BankAccount.MandateReference == "" {
|
||||
|
||||
if user.BankAccount.IBAN != "" && user.BankAccount.MandateReference == "" {
|
||||
return fmt.Errorf("Mandate reference not generated for user: %s", user.Email)
|
||||
} else if user.BankAccount.IBAN == "" && user.BankAccount.MandateReference != "" {
|
||||
return fmt.Errorf("Mandate reference generated without IBAN for user: %s", user.Email)
|
||||
}
|
||||
|
||||
// Validate mandate reference format
|
||||
expected := user.GenerateMandateReference()
|
||||
expected := user.BankAccount.GenerateMandateReference(user.ID)
|
||||
if !strings.HasPrefix(user.BankAccount.MandateReference, expected) {
|
||||
return fmt.Errorf("Mandate reference is invalid. Expected: %s, Got: %s", expected, user.BankAccount.MandateReference)
|
||||
}
|
||||
@@ -686,6 +689,20 @@ func testUpdateUser(t *testing.T) {
|
||||
},
|
||||
expectedStatus: http.StatusAccepted,
|
||||
},
|
||||
{
|
||||
name: "Admin Password Update low entropy should fail",
|
||||
setupCookie: func(req *http.Request) {
|
||||
req.AddCookie(AdminCookie)
|
||||
},
|
||||
updateFunc: func(u *models.User) {
|
||||
u.Password = "newpassword"
|
||||
|
||||
},
|
||||
expectedErrors: []map[string]string{
|
||||
{"field": "server.validation.special server.validation.uppercase server.validation.numbers server.validation.longer", "key": "server.validation.insecure"},
|
||||
},
|
||||
expectedStatus: http.StatusBadRequest,
|
||||
},
|
||||
{
|
||||
name: "Admin Password Update",
|
||||
setupCookie: func(req *http.Request) {
|
||||
@@ -792,7 +809,11 @@ func testUpdateUser(t *testing.T) {
|
||||
if updatedUser.Password == "" {
|
||||
assert.Equal(t, user.Password, (*updatedUserFromDB).Password)
|
||||
} else {
|
||||
assert.NotEqual(t, user.Password, (*updatedUserFromDB).Password)
|
||||
matches, err := updatedUserFromDB.PasswordMatches(updatedUser.Password)
|
||||
if err != nil {
|
||||
t.Fatalf("Error matching password: %v", err)
|
||||
}
|
||||
assert.True(t, matches, "Password mismatch")
|
||||
}
|
||||
|
||||
updatedUserFromDB.Password = ""
|
||||
@@ -820,7 +841,7 @@ func testUpdateUser(t *testing.T) {
|
||||
assert.Equal(t, updatedUser.Membership.StartDate, updatedUserFromDB.Membership.StartDate, "Membership.StartDate mismatch")
|
||||
assert.Equal(t, updatedUser.Membership.EndDate, updatedUserFromDB.Membership.EndDate, "Membership.EndDate mismatch")
|
||||
assert.Equal(t, updatedUser.Membership.Status, updatedUserFromDB.Membership.Status, "Membership.Status mismatch")
|
||||
assert.Equal(t, updatedUser.Membership.SubscriptionModelID, updatedUserFromDB.Membership.SubscriptionModelID, "Membership.SubscriptionModelID mismatch")
|
||||
assert.Equal(t, updatedUser.Membership.SubscriptionID, updatedUserFromDB.Membership.SubscriptionID, "Membership.SubscriptionID mismatch")
|
||||
assert.Equal(t, updatedUser.Membership.ParentMembershipID, updatedUserFromDB.Membership.ParentMembershipID, "Membership.ParentMembershipID mismatch")
|
||||
|
||||
if updatedUser.Licence == nil {
|
||||
@@ -871,11 +892,11 @@ func checkWelcomeMail(message *utils.Email, user *models.User) error {
|
||||
if !strings.Contains(message.Body, user.FirstName) {
|
||||
return fmt.Errorf("User first name(%v) has not been rendered in registration mail.", user.FirstName)
|
||||
}
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/Monat</strong>: %v", user.Membership.SubscriptionModel.MonthlyFee)) {
|
||||
return fmt.Errorf("Users monthly subscription fee(%v) has not been rendered in registration mail.", user.Membership.SubscriptionModel.MonthlyFee)
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/Monat</strong>: %v", user.Membership.Subscription.MonthlyFee)) {
|
||||
return fmt.Errorf("Users monthly subscription fee(%v) has not been rendered in registration mail.", user.Membership.Subscription.MonthlyFee)
|
||||
}
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/h</strong>: %v", user.Membership.SubscriptionModel.HourlyRate)) {
|
||||
return fmt.Errorf("Users hourly subscription fee(%v) has not been rendered in registration mail.", user.Membership.SubscriptionModel.HourlyRate)
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/h</strong>: %v", user.Membership.Subscription.HourlyRate)) {
|
||||
return fmt.Errorf("Users hourly subscription fee(%v) has not been rendered in registration mail.", user.Membership.Subscription.HourlyRate)
|
||||
}
|
||||
if user.Company != "" && !strings.Contains(message.Body, user.Company) {
|
||||
return fmt.Errorf("Users Company(%v) has not been rendered in registration mail.", user.Company)
|
||||
@@ -907,11 +928,11 @@ func checkRegistrationMail(message *utils.Email, user *models.User) error {
|
||||
if !strings.Contains(message.Body, user.FirstName+" "+user.LastName) {
|
||||
return fmt.Errorf("User first and last name(%v) has not been rendered in registration mail.", user.FirstName+" "+user.LastName)
|
||||
}
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/Monat</strong>: %v", user.Membership.SubscriptionModel.MonthlyFee)) {
|
||||
return fmt.Errorf("Users monthly subscription fee(%v) has not been rendered in registration mail.", user.Membership.SubscriptionModel.MonthlyFee)
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/Monat</strong>: %v", user.Membership.Subscription.MonthlyFee)) {
|
||||
return fmt.Errorf("Users monthly subscription fee(%v) has not been rendered in registration mail.", user.Membership.Subscription.MonthlyFee)
|
||||
}
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/h</strong>: %v", user.Membership.SubscriptionModel.HourlyRate)) {
|
||||
return fmt.Errorf("Users hourly subscription fee(%v) has not been rendered in registration mail.", user.Membership.SubscriptionModel.HourlyRate)
|
||||
if !strings.Contains(message.Body, fmt.Sprintf("Preis/h</strong>: %v", user.Membership.Subscription.HourlyRate)) {
|
||||
return fmt.Errorf("Users hourly subscription fee(%v) has not been rendered in registration mail.", user.Membership.Subscription.HourlyRate)
|
||||
}
|
||||
if user.Company != "" && !strings.Contains(message.Body, user.Company) {
|
||||
return fmt.Errorf("Users Company(%v) has not been rendered in registration mail.", user.Company)
|
||||
@@ -951,7 +972,7 @@ func checkVerificationMail(message *utils.Email, user *models.User) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error parsing verification URL: %#v", err.Error())
|
||||
}
|
||||
v, err := user.GetVerification(constants.VerificationTypes.Email)
|
||||
v, err := user.FindVerification(constants.VerificationTypes.Email)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error getting verification token: %v", err.Error())
|
||||
}
|
||||
@@ -1132,7 +1153,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
user.BankAccount.IBAN = "DE1234234123134"
|
||||
user.RoleID = constants.Roles.Supporter
|
||||
user.Email = "john.supporter@example.com"
|
||||
user.Membership.SubscriptionModel.Name = constants.SupporterSubscriptionModelName
|
||||
user.Membership.Subscription.Name = constants.SupporterSubscriptionName
|
||||
return user
|
||||
})),
|
||||
},
|
||||
@@ -1145,7 +1166,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
user.BankAccount.IBAN = ""
|
||||
user.RoleID = constants.Roles.Supporter
|
||||
user.Email = "john.supporter@example.com"
|
||||
user.Membership.SubscriptionModel.Name = constants.SupporterSubscriptionModelName
|
||||
user.Membership.Subscription.Name = constants.SupporterSubscriptionName
|
||||
return user
|
||||
})),
|
||||
},
|
||||
@@ -1155,7 +1176,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
WantDBData: map[string]interface{}{"email": "john.doe@example.com"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(customizeInput(func(user models.User) models.User {
|
||||
user.Membership.SubscriptionModel.Name = ""
|
||||
user.Membership.Subscription.Name = ""
|
||||
return user
|
||||
})),
|
||||
},
|
||||
@@ -1165,7 +1186,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
WantDBData: map[string]interface{}{"email": "john.doe@example.com"},
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(customizeInput(func(user models.User) models.User {
|
||||
user.Membership.SubscriptionModel.Name = "NOTEXISTENTPLAN"
|
||||
user.Membership.Subscription.Name = "NOTEXISTENTPLAN"
|
||||
return user
|
||||
})),
|
||||
},
|
||||
@@ -1204,7 +1225,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
Assert: false,
|
||||
Input: GenerateInputJSON(customizeInput(func(user models.User) models.User {
|
||||
user.Email = "john.junior.doe@example.com"
|
||||
user.Membership.SubscriptionModel.Name = "additional"
|
||||
user.Membership.Subscription.Name = "additional"
|
||||
return user
|
||||
})),
|
||||
},
|
||||
@@ -1216,7 +1237,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
Input: GenerateInputJSON(customizeInput(func(user models.User) models.User {
|
||||
user.Email = "john.junior.doe@example.com"
|
||||
user.Membership.ParentMembershipID = 200
|
||||
user.Membership.SubscriptionModel.Name = "additional"
|
||||
user.Membership.Subscription.Name = "additional"
|
||||
return user
|
||||
})),
|
||||
},
|
||||
@@ -1228,7 +1249,7 @@ func getTestUsers() []RegisterUserTest {
|
||||
Input: GenerateInputJSON(customizeInput(func(user models.User) models.User {
|
||||
user.Email = "john.junior.doe@example.com"
|
||||
user.Membership.ParentMembershipID = 1
|
||||
user.Membership.SubscriptionModel.Name = "additional"
|
||||
user.Membership.Subscription.Name = "additional"
|
||||
return user
|
||||
})),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user