Sistem web pentru rezervarea de birouri și săli de ședință cu flux de aprobare administrativă. Stack: FastAPI + Vue.js 3 + SQLite + TypeScript Features implementate: - Autentificare JWT + Self-registration cu email verification - CRUD Spații, Utilizatori, Settings (Admin) - Calendar interactiv (FullCalendar) cu drag-and-drop - Creare rezervări cu validare (durată, program, overlap, max/zi) - Rezervări recurente (săptămânal) - Admin: aprobare/respingere/anulare cereri - Admin: creare directă rezervări (bypass approval) - Admin: editare orice rezervare - User: editare/anulare rezervări proprii - Notificări in-app (bell icon + dropdown) - Notificări email (async SMTP cu BackgroundTasks) - Jurnal acțiuni administrative (audit log) - Rapoarte avansate (utilizare, top users, approval rate) - Șabloane rezervări (booking templates) - Atașamente fișiere (upload/download) - Conflict warnings (verificare disponibilitate real-time) - Integrare Google Calendar (OAuth2) - Suport timezone (UTC storage + user preference) - 225+ teste backend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
"""Tests for notification service."""
|
|
import pytest
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models.booking import Booking
|
|
from app.models.notification import Notification
|
|
from app.models.user import User
|
|
from app.services.notification_service import create_notification
|
|
|
|
|
|
def test_create_notification(db: Session, test_user: User, test_booking: Booking):
|
|
"""Test creating a notification."""
|
|
notification = create_notification(
|
|
db=db,
|
|
user_id=test_user.id,
|
|
type="booking_approved",
|
|
title="Booking Approved",
|
|
message="Your booking has been approved",
|
|
booking_id=test_booking.id,
|
|
)
|
|
|
|
assert notification.id is not None
|
|
assert notification.user_id == test_user.id
|
|
assert notification.type == "booking_approved"
|
|
assert notification.title == "Booking Approved"
|
|
assert notification.message == "Your booking has been approved"
|
|
assert notification.is_read is False
|
|
assert notification.booking_id == test_booking.id
|
|
assert notification.created_at is not None
|
|
|
|
|
|
def test_create_notification_without_booking(db: Session, test_user: User):
|
|
"""Test creating a notification without a booking reference."""
|
|
notification = create_notification(
|
|
db=db,
|
|
user_id=test_user.id,
|
|
type="system_message",
|
|
title="System Update",
|
|
message="The system will undergo maintenance tonight",
|
|
)
|
|
|
|
assert notification.id is not None
|
|
assert notification.user_id == test_user.id
|
|
assert notification.type == "system_message"
|
|
assert notification.booking_id is None
|
|
assert notification.is_read is False
|
|
|
|
|
|
def test_notification_relationships(db: Session, test_user: User, test_booking: Booking):
|
|
"""Test notification relationships with user and booking."""
|
|
notification = create_notification(
|
|
db=db,
|
|
user_id=test_user.id,
|
|
type="booking_created",
|
|
title="Booking Created",
|
|
message="Your booking has been created",
|
|
booking_id=test_booking.id,
|
|
)
|
|
|
|
# Test user relationship
|
|
assert notification.user is not None
|
|
assert notification.user.id == test_user.id
|
|
assert notification.user.email == test_user.email
|
|
|
|
# Test booking relationship
|
|
assert notification.booking is not None
|
|
assert notification.booking.id == test_booking.id
|
|
assert notification.booking.title == test_booking.title
|
|
|
|
|
|
def test_multiple_notifications_for_user(db: Session, test_user: User):
|
|
"""Test creating multiple notifications for the same user."""
|
|
notification1 = create_notification(
|
|
db=db,
|
|
user_id=test_user.id,
|
|
type="booking_created",
|
|
title="First Booking",
|
|
message="Your first booking has been created",
|
|
)
|
|
|
|
notification2 = create_notification(
|
|
db=db,
|
|
user_id=test_user.id,
|
|
type="booking_approved",
|
|
title="Second Booking",
|
|
message="Your second booking has been approved",
|
|
)
|
|
|
|
assert notification1.id != notification2.id
|
|
assert notification1.user_id == notification2.user_id == test_user.id
|
|
|
|
# Check user has access to all notifications
|
|
db.refresh(test_user)
|
|
user_notifications = test_user.notifications
|
|
assert len(user_notifications) == 2
|
|
assert notification1 in user_notifications
|
|
assert notification2 in user_notifications
|