Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Pipeline
# Trigger this workflow on Push to specific branches OR on Pull Requests to main
on:
push:
branches: ["dev"]
branches: ["**"]
pull_request:
branches: ["main"]

Expand Down
31 changes: 18 additions & 13 deletions server/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ class MockDocRef:
mock_db_client = mocker.Mock()
# Ensure nested calls like db.collection().add() return valid mocks
mock_db_client.collection.return_value.add.return_value = (None, MockDocRef())
mock_db_client.collection.return_value.document.return_value = mocker.Mock()

# Bypass the FileNotFoundError in main.py
mocker.patch("main.os.path.exists", return_value=True)

# Patch the External Firebase Calls (so they don't hit the network)
mocker.patch("firebase_admin.credentials.Certificate")
mocker.patch("firebase_admin.initialize_app")
mock_fs_client = mocker.patch("firebase_admin.firestore.client")
mock_fs_client.return_value = mock_db_client
mocker.patch("firebase_admin.firestore.client", return_value=mock_db_client)

# PATCH THE GLOBAL DB VARIABLE
# Patch the global db variable
import main

# We overwrite the 'db' variable inside the 'main' module
# Overwrite the 'db' variable inside the 'main' module
main.db = mock_db_client

yield
Expand All @@ -37,9 +38,14 @@ class MockDocRef:
main.db = None


# It is safer to use a fixture for the client to ensure fresh state,
# but global is okay for simple tests if the app is stateless.
client = TestClient(app)
@pytest.fixture
def client():
"""
Creates a fresh client for each test and triggers the lifespan
"""

with TestClient(app) as c:
yield c


# Fixture for sample job data
Expand All @@ -55,7 +61,7 @@ def sample_job_data():
}


def test_client_is_working():
def test_client_is_working(client):
"""
A simple "sanity check" test to make sure the client is working.
We don't have a "/" route, so we expect a 404 "Not Found" error.
Expand All @@ -64,16 +70,15 @@ def test_client_is_working():
assert response.status_code == 404


def test_chat_endpoint(mocker):
def test_chat_endpoint(client, mocker):
"""
Tests the /chat endpoint.
It uses 'mocker' to fake the Gemini AI call.
Firebase/Firestore is already mocked by the mock_firebase fixture.
"""

# --- ARRANGE (Mocks) ---

# Mock the Gemini Client API call
# Mock Gemini
class MockGeminiResponse:
text = "This is a fake AI response."

Expand All @@ -98,7 +103,7 @@ class MockGeminiResponse:
mock_gemini_client.return_value.models.generate_content.assert_called_once()


def test_resume_tailor_endpoint(sample_job_data, mocker):
def test_resume_tailor_endpoint(client, sample_job_data, mocker):
"""
Tests the /resumes endpoint.

Expand Down