rayhan-erp/Livrables/docs/Guide-Tests-Postman.md

6.6 KiB
Raw Blame History

Guide de Tests API — Postman

PFE Ali Guennari — ERP SUARL Rayhan

Configuration de Base

URL de base : https://rayhan-erp.bolbol.tn

1. Configurer une Variable d'Environnement Postman

Dans Postman, créer un environnement "Rayhan ERP" avec :

  • baseUrl = https://rayhan-erp.bolbol.tn
  • token = (sera rempli automatiquement)

Scénario 1 : Authentification

Se connecter (POST /api/auth/signin)

POST {{baseUrl}}/api/auth/signin
Content-Type: application/json

{
  "username": "admin",
  "password": "Rayhan2024!"
}

Réponse attendue (200 OK) :

{
  "token": "eyJhbGciOiJIUzI1NiJ9...",
  "type": "Bearer",
  "id": 1,
  "username": "admin",
  "email": "admin@rayhan.tn",
  "roles": ["ROLE_PDG"]
}

Script Postman (Tests tab) pour sauvegarder le token :

var json = pm.response.json();
pm.environment.set("token", json.token);

Utilisation dans toutes les requêtes suivantes :

Authorization: Bearer {{token}}

Scénario 2 : Référentiels

Créer un Article (Matière Première HDPE)

POST {{baseUrl}}/api/articles
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "reference": "MP-HDPE-001",
  "designation": "HDPE Granulés (Polyéthylène Haute Densité)",
  "type": "MP",
  "uniteMesure": "kg",
  "prixUnitaire": 2.850,
  "stockMinimum": 500
}

Créer un Article (Produit Fini — Sac Bertel)

POST {{baseUrl}}/api/articles
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "reference": "PF-SAC-BERTEL-001",
  "designation": "Sac Bertel 40x60 cm",
  "type": "PF",
  "uniteMesure": "unité",
  "prixUnitaire": 0.085,
  "stockMinimum": 1000
}

Créer un Client

POST {{baseUrl}}/api/clients
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "raisonSociale": "Supermarché Maghreb Distribution",
  "matriculeFiscal": "123456A/A/M/000",
  "adresse": "Avenue Habib Bourguiba, Tataouine",
  "telephone": "75123456",
  "email": "achats@maghreb-distrib.tn",
  "ville": "Tataouine",
  "typeClient": "Grossiste",
  "delaiPaiement": 60
}

Créer un Fournisseur (HDPE)

POST {{baseUrl}}/api/fournisseurs
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "raisonSociale": "PLASTUNION Tunisie",
  "matriculeFiscal": "654321B/A/M/000",
  "adresse": "Zone Industrielle Sfax",
  "telephone": "74987654",
  "email": "ventes@plastunion.tn",
  "ville": "Sfax",
  "pays": "Tunisie",
  "categorieProduit": "Matières plastiques",
  "delaiLivraison": 10
}

Scénario 3 : Cycle d'Achat Complet

Étape 3.1 — Créer une Commande Fournisseur

POST {{baseUrl}}/api/purchase-orders
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "fournisseur": {"id": 1},
  "dateLivraisonPrevue": "2024-05-15",
  "notes": "Commande mensuelle HDPE",
  "lignes": [
    {
      "article": {"id": 1},
      "quantiteCommandee": 1000,
      "prixUnitaireHT": 2.850,
      "tauxTVA": 19.00
    }
  ]
}

Réponse attendue : commande avec reference: "BC-2024-001", statut: "CONFIRMEE", totalTTC: 3391.50

Étape 3.2 — Réceptionner la Commande (Bon de Réception)

POST {{baseUrl}}/api/purchase-orders/1/receive
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "dateReception": "2024-05-14",
  "notes": "Réception conforme",
  "lignes": [
    {
      "purchaseOrderLine": {"id": 1},
      "article": {"id": 1},
      "quantiteRecue": 1000,
      "observations": "Qualité OK, sacs conformes"
    }
  ]
}

Vérification : GET {{baseUrl}}/api/articles/1stockActuel doit être 1000


Scénario 4 : Production (BOM + OF)

Étape 4.1 — Définir la Nomenclature (BOM)

POST {{baseUrl}}/api/production/bom
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "produitFini": {"id": 2},
  "composant": {"id": 1},
  "quantiteParUnite": 0.015,
  "uniteMesure": "kg"
}

Signification : pour produire 1 Sac Bertel, il faut 0.015 kg de HDPE

Étape 4.2 — Planifier un Ordre de Fabrication

POST {{baseUrl}}/api/production/orders/plan
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "produitFiniId": 2,
  "quantite": 10000,
  "datePlanifiee": "2024-05-16"
}

Vérification préalable : stock HDPE (1000 kg) ≥ 10000 × 0.015 = 150 kg → OK

Étape 4.3 — Lancer l'OF

POST {{baseUrl}}/api/production/orders/1/launch
Authorization: Bearer {{token}}

Vérification : stock HDPE passe de 1000 à 850 kg (consommation 150 kg)

Étape 4.4 — Terminer l'OF

POST {{baseUrl}}/api/production/orders/1/complete
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "quantiteRealisee": 9800
}

Vérification : stock Sac Bertel passe à 9800 unités


Scénario 5 : Cycle de Vente

Étape 5.1 — Créer une Commande Client

POST {{baseUrl}}/api/sales-orders
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "client": {"id": 1},
  "dateLivraisonSouhaitee": "2024-05-20",
  "notes": "Urgent",
  "lignes": [
    {
      "article": {"id": 2},
      "quantiteCommandee": 5000,
      "prixUnitaireHT": 0.085,
      "tauxTVA": 19.00
    }
  ]
}

Étape 5.2 — Créer un Bon de Livraison

POST {{baseUrl}}/api/sales-orders/1/deliver
Authorization: Bearer {{token}}
Content-Type: application/json

{
  "dateLivraison": "2024-05-20",
  "adresseLivraison": "Avenue Habib Bourguiba, Tataouine",
  "notes": "Livraison par camion",
  "lignes": [
    {
      "salesOrderLine": {"id": 1},
      "article": {"id": 2},
      "quantiteLivree": 5000
    }
  ]
}

Vérification : stock Sac Bertel passe de 9800 à 4800


Scénario 6 : Tableau de Bord (PDG uniquement)

GET {{baseUrl}}/api/dashboard
Authorization: Bearer {{token}}

Réponse attendue :

{
  "ventes": {
    "chiffreAffairesMois": 505.75,
    "nbCommandesMois": 1,
    "commandesEnCours": 0
  },
  "achats": {
    "commandesEnAttente": 0
  },
  "production": {
    "ofPlanifies": 0,
    "ofEnCours": 0
  },
  "stock": {
    "articlesEnAlerte": 0,
    "articlesEnAlerteDetails": []
  }
}

Codes d'Erreur Importants

Code Signification Action
401 Non authentifié Vérifier le token JWT
403 Accès interdit Le rôle ne permet pas cette action
400 Données invalides Vérifier le body de la requête
500 Erreur serveur Voir les logs du container

Commandes Docker Utiles

# Voir les logs de l'API
docker logs rayhan-backend -f

# Accéder à MySQL directement
docker exec -it rayhan-mysql mysql -u root -prayhan_erp_2024 rayhan_erp_db

# Redémarrer l'API
docker restart rayhan-backend