Add integration tests for use handlers

This commit is contained in:
2024-11-29 23:57:17 +01:00
parent d47b601447
commit af9ab42969
2 changed files with 212 additions and 35 deletions

View File

@@ -23,24 +23,6 @@ type DeleteAccountRequest struct {
Password string `json:"password"`
}
// GetUser returns the current user's profile
func (h *Handler) GetUser() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, ok := context.GetRequestContext(w, r)
if !ok {
return
}
user, err := h.DB.GetUserByID(ctx.UserID)
if err != nil {
http.Error(w, "Failed to get user", http.StatusInternalServerError)
return
}
respondJSON(w, user)
}
}
// UpdateProfile updates the current user's profile
func (h *Handler) UpdateProfile() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -62,18 +44,6 @@ func (h *Handler) UpdateProfile() http.HandlerFunc {
return
}
// Start transaction for atomic updates
tx, err := h.DB.Begin()
if err != nil {
http.Error(w, "Failed to start transaction", http.StatusInternalServerError)
return
}
defer func() {
if err := tx.Rollback(); err != nil && err != sql.ErrTxDone {
http.Error(w, "Failed to rollback transaction", http.StatusInternalServerError)
}
}()
// Handle password update if requested
if req.NewPassword != "" {
// Current password must be provided to change password
@@ -139,11 +109,6 @@ func (h *Handler) UpdateProfile() http.HandlerFunc {
return
}
if err := tx.Commit(); err != nil {
http.Error(w, "Failed to commit changes", http.StatusInternalServerError)
return
}
// Return updated user data
respondJSON(w, user)
}