Skip to content

Latest commit

 

History

History
517 lines (408 loc) · 11.1 KB

File metadata and controls

517 lines (408 loc) · 11.1 KB

Guide de Test de l'API Cousinade v2.0

Ce guide vous permet de tester toutes les fonctionnalités de l'API en utilisant curl.

🚀 Démarrage

cd server
npm install
npm start

Le serveur démarre sur http://localhost:5000

🔐 Authentification

1. Inscription d'un Propriétaire

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "proprietaire@example.com",
    "password": "password123",
    "first_name": "Jean",
    "last_name": "Dupont",
    "phone": "+33612345678",
    "role": "owner"
  }'

Réponse:

{
  "message": "Inscription réussie",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "email": "proprietaire@example.com",
    "first_name": "Jean",
    "last_name": "Dupont",
    "phone": "+33612345678",
    "role": "owner"
  }
}

💡 Sauvegardez le token retourné !

2. Inscription d'un Organisateur

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "organisateur@example.com",
    "password": "password123",
    "first_name": "Marie",
    "last_name": "Martin",
    "phone": "+33623456789",
    "role": "organizer"
  }'

3. Connexion

curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "proprietaire@example.com",
    "password": "password123"
  }'

4. Récupérer son Profil

TOKEN="votre_token_ici"

curl -X GET http://localhost:5000/api/auth/profile \
  -H "Authorization: Bearer $TOKEN"

🏠 Gestion des Lieux (Espace Propriétaire)

1. Créer un Lieu

OWNER_TOKEN="token_du_proprietaire"

curl -X POST http://localhost:5000/api/venues \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OWNER_TOKEN" \
  -d '{
    "name": "Château de la Vallée",
    "description": "Magnifique château du 18ème siècle, idéal pour vos cousinades",
    "type": "Château",
    "address": "15 Route du Château",
    "city": "Amboise",
    "region": "Centre-Val de Loire",
    "postal_code": "37400",
    "capacity": 30,
    "bedrooms": 12,
    "bathrooms": 8,
    "price_per_night": 800,
    "price_per_weekend": 2200,
    "price_per_week": 5000,
    "amenities": ["Piscine", "Parc", "Salle de réception", "WiFi", "Parking"],
    "images": ["https://example.com/chateau1.jpg", "https://example.com/chateau2.jpg"]
  }'

2. Lister Mes Lieux

curl -X GET http://localhost:5000/api/venues/owner/my-venues \
  -H "Authorization: Bearer $OWNER_TOKEN"

3. Modifier un Lieu

curl -X PUT http://localhost:5000/api/venues/1 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OWNER_TOKEN" \
  -d '{
    "name": "Château de la Vallée - Mis à jour",
    "description": "Magnifique château entièrement rénové",
    "price_per_night": 850,
    "available": true
  }'

4. Supprimer un Lieu

curl -X DELETE http://localhost:5000/api/venues/1 \
  -H "Authorization: Bearer $OWNER_TOKEN"

🔍 Recherche de Lieux (Public & Organisateur)

1. Lister Tous les Lieux

curl -X GET http://localhost:5000/api/venues

2. Recherche avec Filtres

Par ville:

curl -X GET "http://localhost:5000/api/venues?city=Paris"

Par capacité et prix:

curl -X GET "http://localhost:5000/api/venues?capacity_min=20&capacity_max=50&price_max=600"

Par région et type:

curl -X GET "http://localhost:5000/api/venues?region=Provence&type=Gîte%20rural"

Combinaison de filtres:

curl -X GET "http://localhost:5000/api/venues?city=Lyon&capacity_min=15&price_max=500&available=true"

3. Détails d'un Lieu

curl -X GET http://localhost:5000/api/venues/1

📅 Gestion des Réservations

1. Créer une Réservation (Organisateur)

ORGANIZER_TOKEN="token_de_l_organisateur"

curl -X POST http://localhost:5000/api/bookings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "venue_id": 1,
    "start_date": "2024-08-15",
    "end_date": "2024-08-22",
    "guests_count": 25,
    "message": "Nous organisons une cousinade pour célébrer les 90 ans de notre grand-mère"
  }'

2. Mes Réservations (Organisateur)

curl -X GET http://localhost:5000/api/bookings/my-bookings \
  -H "Authorization: Bearer $ORGANIZER_TOKEN"

3. Réservations Reçues (Propriétaire)

curl -X GET http://localhost:5000/api/bookings/owner/received \
  -H "Authorization: Bearer $OWNER_TOKEN"

4. Détails d'une Réservation

curl -X GET http://localhost:5000/api/bookings/1 \
  -H "Authorization: Bearer $ORGANIZER_TOKEN"

5. Confirmer une Réservation (Propriétaire)

curl -X PUT http://localhost:5000/api/bookings/1/status \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OWNER_TOKEN" \
  -d '{
    "status": "confirmed"
  }'

6. Rejeter une Réservation (Propriétaire)

curl -X PUT http://localhost:5000/api/bookings/1/status \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OWNER_TOKEN" \
  -d '{
    "status": "rejected"
  }'

7. Annuler une Réservation (Organisateur)

curl -X PUT http://localhost:5000/api/bookings/1/status \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "status": "cancelled"
  }'

8. Supprimer une Réservation

curl -X DELETE http://localhost:5000/api/bookings/1 \
  -H "Authorization: Bearer $ORGANIZER_TOKEN"

⭐ Gestion des Avis

1. Avis d'un Lieu

curl -X GET http://localhost:5000/api/reviews/venue/1

2. Créer un Avis (après un séjour)

curl -X POST http://localhost:5000/api/reviews \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "venue_id": 1,
    "booking_id": 1,
    "rating": 5,
    "comment": "Excellent lieu pour notre cousinade ! Très spacieux et bien équipé."
  }'

3. Supprimer un Avis

curl -X DELETE http://localhost:5000/api/reviews/1 \
  -H "Authorization: Bearer $ORGANIZER_TOKEN"

🎉 Gestion des Événements (avec authentification)

1. Mes Événements

curl -X GET http://localhost:5000/api/events \
  -H "Authorization: Bearer $ORGANIZER_TOKEN"

2. Créer un Événement

curl -X POST http://localhost:5000/api/events \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "title": "Cousinade Été 2024",
    "description": "Réunion de la famille Martin",
    "location": "Château de la Vallée, Amboise",
    "start_date": "2024-08-15",
    "end_date": "2024-08-22",
    "booking_id": 1,
    "image_url": "https://example.com/event.jpg"
  }'

🧪 Scénario de Test Complet

Étape 1: Créer les Utilisateurs

# Propriétaire
curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "owner@test.com",
    "password": "test123",
    "first_name": "Paul",
    "last_name": "Bernard",
    "role": "owner"
  }'

# Sauvegarder le token retourné
OWNER_TOKEN="<token_retourné>"

# Organisateur
curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "organizer@test.com",
    "password": "test123",
    "first_name": "Sophie",
    "last_name": "Dubois",
    "role": "organizer"
  }'

# Sauvegarder le token
ORGANIZER_TOKEN="<token_retourné>"

Étape 2: Créer un Lieu (Propriétaire)

curl -X POST http://localhost:5000/api/venues \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OWNER_TOKEN" \
  -d '{
    "name": "Gîte des Lavandes",
    "description": "Gîte familial en Provence",
    "type": "Gîte rural",
    "address": "5 Chemin des Lavandes",
    "city": "Roussillon",
    "region": "Provence-Alpes-Côte d'\''Azur",
    "postal_code": "84220",
    "capacity": 20,
    "bedrooms": 7,
    "bathrooms": 3,
    "price_per_night": 400,
    "price_per_week": 2500,
    "amenities": ["Piscine", "Jardin", "BBQ"],
    "images": ["https://example.com/gite.jpg"]
  }'

Étape 3: Rechercher et Réserver (Organisateur)

# Rechercher
curl -X GET "http://localhost:5000/api/venues?city=Roussillon"

# Voir les détails
curl -X GET http://localhost:5000/api/venues/1

# Réserver
curl -X POST http://localhost:5000/api/bookings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "venue_id": 1,
    "start_date": "2024-07-20",
    "end_date": "2024-07-27",
    "guests_count": 18,
    "message": "Pour une réunion de famille"
  }'

Étape 4: Gérer la Réservation (Propriétaire)

# Voir les réservations reçues
curl -X GET http://localhost:5000/api/bookings/owner/received \
  -H "Authorization: Bearer $OWNER_TOKEN"

# Confirmer la réservation
curl -X PUT http://localhost:5000/api/bookings/1/status \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OWNER_TOKEN" \
  -d '{"status": "confirmed"}'

Étape 5: Créer un Événement (Organisateur)

curl -X POST http://localhost:5000/api/events \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "title": "Cousinade Famille Dubois 2024",
    "description": "Retrouvailles familiales",
    "location": "Gîte des Lavandes, Roussillon",
    "start_date": "2024-07-20",
    "end_date": "2024-07-27",
    "booking_id": 1
  }'

Étape 6: Laisser un Avis (Organisateur, après le séjour)

curl -X POST http://localhost:5000/api/reviews \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $ORGANIZER_TOKEN" \
  -d '{
    "venue_id": 1,
    "booking_id": 1,
    "rating": 5,
    "comment": "Parfait pour notre cousinade !"
  }'

📊 Vérifications

Statistiques d'un Lieu

# Le lieu avec sa note moyenne et nombre d'avis
curl -X GET http://localhost:5000/api/venues/1

Profil Utilisateur

curl -X GET http://localhost:5000/api/auth/profile \
  -H "Authorization: Bearer $ORGANIZER_TOKEN"

⚠️ Gestion des Erreurs

Erreurs Communes

401 Unauthorized

{
  "error": "Accès refusé. Token manquant."
}

→ Ajoutez le header Authorization: Bearer <token>

403 Forbidden

{
  "error": "Accès réservé aux propriétaires."
}

→ Votre rôle ne permet pas cette action

400 Bad Request

{
  "error": "Tous les champs sont requis"
}

→ Vérifiez les données envoyées

404 Not Found

{
  "error": "Lieu non trouvé"
}

→ L'ID n'existe pas


🎯 Tips

  1. Sauvegardez vos tokens dans des variables d'environnement
  2. Utilisez jq pour formater les réponses: | jq .
  3. Testez d'abord en tant que propriétaire, puis organisateur
  4. Vérifiez les statuts des réservations avant de les modifier
  5. Les dates doivent être au format YYYY-MM-DD

Documentation complète de l'API: Voir CHANGELOG.md