func TestUpdateUser(t *testing.T) { initUserHandlerTest() userController.Create("*****@*****.**", "password") user, _ := userRepo.FindByEmail("*****@*****.**") id := strconv.Itoa(user.ID) ctx, _ := CreateReqContext("POST", "/user/update", map[string][]string{ "id": []string{id}, "email": []string{"*****@*****.**"}, "password": []string{"testpassword"}, "password-again": []string{"testpassword"}, }) userHandler.Update(ctx) if ctx.HasValidationErrors() { t.Log(ctx.ValidationErrors) t.Fatal("Did not expect any errors") } if !ctx.IsRedirected() { t.Fatal("Expected redirection") } user, _ = userRepo.FindByEmail("*****@*****.**") if !user.PasswordEquals("testpassword") { t.Fatal("Expected a updated password") } }
func TestCreateUser(t *testing.T) { initUserHandlerTest() ctx, _ := CreateReqContext("POST", "/user/create", map[string][]string{ "email": []string{"*****@*****.**"}, "password": []string{"testpassword"}, "password-again": []string{"testpassword"}, }) userHandler.Create(ctx) if ctx.HasValidationErrors() { t.Log(ctx.ValidationErrors) t.Fatal("Did not expect any errors") } if !ctx.IsRedirected() { t.Fatal("Expected redirection") } result, _ := userRepo.All() if len(result) != 1 { t.Fatal("Expected user created") } }