mirror of
http://88.130.71.182:3000/BlitTech/badoHair_be.git
synced 2026-06-12 23:23:22 +00:00
Initial Commit
This commit is contained in:
55
tests/test_services_contact.py
Normal file
55
tests/test_services_contact.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Services list and contact form endpoint tests."""
|
||||
from unittest.mock import AsyncMock
|
||||
from tests.conftest import SAMPLE_SERVICE
|
||||
|
||||
|
||||
async def test_list_services(anon_client, mock_db):
|
||||
mock_db.fetch = AsyncMock(return_value=[SAMPLE_SERVICE])
|
||||
|
||||
r = await anon_client.get("/api/v1/services")
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["success"] is True
|
||||
assert isinstance(body["data"], list)
|
||||
assert body["data"][0]["name"] == "Pose complète"
|
||||
assert "duration_minutes" in body["data"][0]
|
||||
assert "price" in body["data"][0]
|
||||
|
||||
|
||||
async def test_list_services_empty(anon_client, mock_db):
|
||||
mock_db.fetch = AsyncMock(return_value=[])
|
||||
r = await anon_client.get("/api/v1/services")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["data"] == []
|
||||
|
||||
|
||||
async def test_contact_form_success(anon_client, mock_db):
|
||||
mock_db.execute = AsyncMock(return_value="INSERT 1")
|
||||
|
||||
r = await anon_client.post("/api/v1/contact", json={
|
||||
"name": "Marie Dupont",
|
||||
"email": "marie@test.com",
|
||||
"message": "Je voudrais prendre rendez-vous.",
|
||||
})
|
||||
assert r.status_code == 200
|
||||
assert r.json()["success"] is True
|
||||
mock_db.execute.assert_called_once()
|
||||
|
||||
|
||||
async def test_contact_form_invalid_email(anon_client):
|
||||
r = await anon_client.post("/api/v1/contact", json={
|
||||
"name": "Marie",
|
||||
"email": "not-an-email",
|
||||
"message": "Hello",
|
||||
})
|
||||
assert r.status_code == 422
|
||||
assert r.json()["error"]["code"] == "VALIDATION_ERROR"
|
||||
|
||||
|
||||
async def test_contact_form_missing_field(anon_client):
|
||||
r = await anon_client.post("/api/v1/contact", json={
|
||||
"name": "Marie",
|
||||
"email": "marie@test.com",
|
||||
# message missing
|
||||
})
|
||||
assert r.status_code == 422
|
||||
Reference in New Issue
Block a user