From 05dd2400996187f3041fe6a4f4ebcb18926df93d Mon Sep 17 00:00:00 2001
From: MikeSoft007 <mekpenyong2@gmail.com>
Date: Fri, 23 Aug 2024 22:47:41 +0200
Subject: [PATCH 1/2] feat: updated email notification for waitlist signu

---
 tests/v1/auth/test_magic_link.py | 79 --------------------------------
 1 file changed, 79 deletions(-)

diff --git a/tests/v1/auth/test_magic_link.py b/tests/v1/auth/test_magic_link.py
index aedc43fe7..ffbfde3dc 100644
--- a/tests/v1/auth/test_magic_link.py
+++ b/tests/v1/auth/test_magic_link.py
@@ -60,82 +60,3 @@ def test_request_magic_link(mock_user_service, mock_db_session):
         response = client.post(MAGIC_ENDPOINT, json={"email": "notauser@gmail.com"})
         assert response.status_code == status.HTTP_404_NOT_FOUND
         assert response.json().get("message") == "User not found"
-
-
-
-# import pytest
-# from fastapi.testclient import TestClient
-# from unittest.mock import patch, MagicMock
-# from main import app
-# from api.v1.models.user import User
-# from api.v1.services.user import user_service
-# from uuid_extensions import uuid7
-# from api.db.database import get_db
-# from fastapi import status
-# from datetime import datetime, timezone
-
-
-# client = TestClient(app)
-# MAGIC_ENDPOINT = '/api/v1/auth/magic-link'
-
-
-# @pytest.fixture
-# def mock_db_session():
-#     """Fixture to create a mock database session."""
-
-#     with patch("api.v1.services.user.get_db", autospec=True) as mock_get_db:
-#         mock_db = MagicMock()
-#         # mock_get_db.return_value.__enter__.return_value = mock_db
-#         app.dependency_overrides[get_db] = lambda: mock_db
-#         yield mock_db
-#     app.dependency_overrides = {}
-
-
-# @pytest.fixture
-# def mock_user_service():
-#     """Fixture to create a mock user service."""
-
-#     with patch("api.v1.services.user.user_service", autospec=True) as mock_service:
-#         yield mock_service
-
-# @pytest.mark.usefixtures("mock_db_session", "mock_user_service")
-# def test_request_magic_link(mock_user_service, mock_db_session):
-#     """Test for requesting magic link"""
-
-#     # Create a mock user
-#     mock_user = User(
-#         id=str(uuid7()),
-#         email="testuser1@gmail.com",
-#         password=user_service.hash_password("Testpassword@123"),
-#         first_name='Test',
-#         last_name='User',
-#         is_active=False,
-#         is_superadmin=False,
-#         created_at=datetime.now(timezone.utc),
-#         updated_at=datetime.now(timezone.utc)
-#     )
-#     mock_db_session.query.return_value.filter.return_value.first.return_value = mock_user
-
-#     with patch("api.utils.send_mail.smtplib.SMTP_SSL") as mock_smtp:
-#         # Configure the mock SMTP server
-#         mock_smtp_instance = MagicMock()
-#         mock_smtp.return_value = mock_smtp_instance
-
-
-#         # Test for requesting magic link for an existing user
-#         magic_login = client.post(MAGIC_ENDPOINT, json={
-#             "email": mock_user.email
-#         })
-#         assert magic_login.status_code == status.HTTP_200_OK
-#         response = magic_login.json()
-#         #assert response.get("status_code") == status.HTTP_200_OK  # check for the right response before proceeding
-#         assert response.get("message") == f"Magic link sent to {mock_user.email}"
-
-#         # Test for requesting magic link for a non-existing user
-#         mock_db_session.query.return_value.filter.return_value.first.return_value = None
-#         magic_login = client.post(MAGIC_ENDPOINT, json={
-#             "email": "notauser@gmail.com"
-#         })
-#         response = magic_login.json()
-#         assert response.get("status_code") == status.HTTP_404_NOT_FOUND  # check for the right response before proceeding
-#         assert response.get("message") == "User not found"

From 9023e9414f2f54295ed16d1a53d360dc2841fded Mon Sep 17 00:00:00 2001
From: MikeSoft007 <mekpenyong2@gmail.com>
Date: Fri, 23 Aug 2024 22:59:13 +0200
Subject: [PATCH 2/2] feat: updated email notification for waitlist signu

---
 .../{waitlist.html => waitlists.html}         |  0
 api/v1/routes/waitlist.py                     | 59 +++++++++++++++----
 2 files changed, 48 insertions(+), 11 deletions(-)
 rename api/core/dependencies/email/templates/{waitlist.html => waitlists.html} (100%)

diff --git a/api/core/dependencies/email/templates/waitlist.html b/api/core/dependencies/email/templates/waitlists.html
similarity index 100%
rename from api/core/dependencies/email/templates/waitlist.html
rename to api/core/dependencies/email/templates/waitlists.html
diff --git a/api/v1/routes/waitlist.py b/api/v1/routes/waitlist.py
index 5f8453805..6c9355e2a 100644
--- a/api/v1/routes/waitlist.py
+++ b/api/v1/routes/waitlist.py
@@ -22,6 +22,19 @@
 waitlist = APIRouter(prefix="/waitlist", tags=["Waitlist"])
 
 def process_waitlist_signup(user: WaitlistAddUserSchema, db: Session):
+    """
+    Process a waitlist signup request.
+
+    Args:
+    - user (WaitlistAddUserSchema): The user details to be added to the waitlist.
+    - db (Session): The database session.
+
+    Returns:
+    - db_user: The added user object.
+
+    Raises:
+    - HTTPException: If the full name is not provided or if the email is already registered.
+    """
     if not user.full_name:
         logger.error("Full name is required")
         raise HTTPException(
@@ -55,6 +68,24 @@ async def waitlist_signup(
     user: WaitlistAddUserSchema,
     db: Session = Depends(get_db)
 ):
+    """
+    Add a user to the waitlist.
+
+    Args:
+    - user (WaitlistAddUserSchema): The user details to be added to the waitlist.
+
+    Returns:
+    - success_response: A success response with a message and status code.
+
+    Example:
+    ```
+    curl -X POST \
+      http://localhost:8000/waitlist/ \
+      -H 'Content-Type: application/json' \
+      -d '{"email": "user@example.com", "full_name": "John Doe"}'
+    ```
+    """
+     
     db_user = process_waitlist_signup(user, db)
     if db_user:
         cta_link = 'https://anchor-python.teams.hng.tech/about-us'
@@ -62,7 +93,7 @@ async def waitlist_signup(
         background_tasks.add_task(
             send_email, 
             recipient=user.email,
-            template_name='waitlist.html',
+            template_name='waitlists.html',
             subject='Welcome to HNG Waitlist',
             context={
                 'name': user.full_name,
@@ -82,19 +113,25 @@ def admin_add_user_to_waitlist(
     db: Session = Depends(get_db),
 ):
     """
-    Manually adds a user to the waitlist.
-    This endpoint allows an admin to add a user to the waitlist.
+    Manually add a user to the waitlist as an admin.
 
-    Parameters:
-    - item: WaitlistAddUserSchema
-        The details of the user to be added to the waitlist.
-    - admin: User (Depends on get_super_admin)
-        The current admin making the request. This is a dependency that provides the current admin context.
+    Args:
+    - item (WaitlistAddUserSchema): The user details to be added to the waitlist.
+    - admin (User): The current admin making the request.
 
     Returns:
-    - 201: User added successfully
-    - 400: Validation error
-    - 403: Forbidden
+    - success_response: A success response with a message and status code.
+
+    Raises:
+    - HTTPException: If the full name is not provided or if the email is already registered.
+
+    Example:
+    ```
+    curl -X POST \
+      http://localhost:8000/waitlist/admin \
+      -H 'Content-Type: application/json' \
+      -d '{"email": "user@example.com", "full_name": "John Doe"}'
+    ```
     """
 
     try: