diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..fd988bbc --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Run Uvicorn Server", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/venv/bin/uvicorn", // Adjust path for Windows if needed + "args": [ + "main:app", + "--reload", + "--port", "8000" + ], + "console": "integratedTerminal", + "env": { + "PYTHONPATH": "${workspaceFolder}" + }, + "cwd": "${workspaceFolder}", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/services/supabase/users_manager.py b/services/supabase/users_manager.py index cd603b84..272e5a8e 100644 --- a/services/supabase/users_manager.py +++ b/services/supabase/users_manager.py @@ -25,7 +25,7 @@ def __init__(self, client: Client) -> None: def check_email_is_valid(self, email: str) -> bool: """Check if email is valid""" if email is None: - return True + return False if not isinstance(email, str): return False if "@" not in email or "." not in email: @@ -249,8 +249,7 @@ def user_exists(self, user_id: int) -> bool: @handle_exceptions(default_return_value=None, raise_on_error=True) def handle_user_email_update(self, user_id: int, email: str) -> None: """Update user email in the users table if email is valid and not None""" - email = email if self.check_email_is_valid(email=email) else None - if email is not None: + if self.check_email_is_valid(email=email): self.client.table("users").update( json={"email": email} ).eq("user_id", user_id).execute() diff --git a/tests/services/supabase/test_users_manager.py b/tests/services/supabase/test_users_manager.py index 3e73c0ce..25b00cd5 100644 --- a/tests/services/supabase/test_users_manager.py +++ b/tests/services/supabase/test_users_manager.py @@ -440,6 +440,19 @@ def test_handle_user_email_update() -> None: ) assert users_data[1][0]["email"] == EMAIL + # Update the user's email + none_email = None + supabase_manager.handle_user_email_update(user_id=USER_ID, email=none_email) + + # Verify the email was updated + users_data, _ = ( + supabase_manager.client.table(table_name="users") + .select("email") + .eq(column="user_id", value=USER_ID) + .execute() + ) + assert users_data[1][0]["email"] == EMAIL + # Update the user's email new_email = "new_email@example.com" supabase_manager.handle_user_email_update(user_id=USER_ID, email=new_email)