mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-20 06:43:11 -05:00
Improve error handling for duplicate recipe names
- Enhanced backend error message to be more descriptive and actionable - Added prominent error dialog in frontend to alert user about save failures - Keep user's edits in the editor so they can fix the issue and retry - Updated test to verify improved error messaging Co-authored-by: hay-kot <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
@@ -1327,7 +1327,7 @@ def test_create_recipe_slug_length_validation(api_client: TestClient, unique_use
|
||||
|
||||
|
||||
def test_recipe_update_duplicate_name_error(api_client: TestClient, unique_user: TestUser):
|
||||
"""Test that updating a recipe with a duplicate name returns a 400 error."""
|
||||
"""Test that updating a recipe with a duplicate name returns a 400 error with a helpful message."""
|
||||
# Create two recipes with different names
|
||||
recipe1_name = random_string(10)
|
||||
recipe2_name = random_string(10)
|
||||
@@ -1353,12 +1353,15 @@ def test_recipe_update_duplicate_name_error(api_client: TestClient, unique_user:
|
||||
headers=unique_user.token
|
||||
)
|
||||
|
||||
# Should return 400 error with appropriate message
|
||||
# Should return 400 error with helpful message
|
||||
assert update_response.status_code == 400
|
||||
response_data = json.loads(update_response.text)
|
||||
assert "already exists" in response_data["detail"]["message"].lower()
|
||||
error_message = response_data["detail"]["message"]
|
||||
assert "already exists" in error_message.lower()
|
||||
assert "choose a different name" in error_message.lower()
|
||||
assert "try saving again" in error_message.lower()
|
||||
|
||||
# Verify original recipe2 is unchanged
|
||||
# Verify original recipe2 is unchanged in the database
|
||||
get_response = api_client.get(api_routes.recipes_slug(recipe2_slug), headers=unique_user.token)
|
||||
assert get_response.status_code == 200
|
||||
unchanged_recipe = json.loads(get_response.text)
|
||||
|
||||
Reference in New Issue
Block a user